Allow empty foldernames

Empty foldernames (as they could be created through nametrans) were
failing as the uidvalidity and status files names as determined by
folder/Base.py:getfolderbasename() lead to invalid file names ''.

Fix this by handling empty file names and translating them to '.' which
leads to the special file name 'dot'. (this special value existed before
and was not invented by this patch)

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth 2011-08-17 16:11:00 +02:00 committed by Nicolas Sebrecht
parent 4f1cd05fdc
commit 373e7cdbc1
4 changed files with 22 additions and 11 deletions

View File

@ -72,11 +72,15 @@ class BaseFolder(object):
return self.getname() return self.getname()
def getfolderbasename(self): def getfolderbasename(self):
foldername = self.getname() """Return base file name of file to store Status/UID info in"""
foldername = foldername.replace(self.repository.getsep(), '.') if not self.name:
foldername = re.sub('/\.$', '/dot', foldername) basename = '.'
foldername = re.sub('^\.$', 'dot', foldername) else: #avoid directory hierarchies and file names such as '/'
return foldername basename = self.name.replace('/', '.')
# replace with literal 'dot' if final path name is '.' as '.' is
# an invalid file name.
basename = re.sub('(^|\/)\.$','\\1dot', basename)
return basename
def isuidvalidityok(self): def isuidvalidityok(self):
"""Does the cached UID match the real UID """Does the cached UID match the real UID

View File

@ -28,7 +28,7 @@ class LocalStatusFolder(BaseFolder):
self.root = root self.root = root
self.sep = '.' self.sep = '.'
self.config = config self.config = config
self.filename = repository.getfolderfilename(name) self.filename = os.path.join(root, self.getfolderbasename())
self.messagelist = {} self.messagelist = {}
self.repository = repository self.repository = repository
self.savelock = threading.Lock() self.savelock = threading.Lock()

View File

@ -115,7 +115,7 @@ class LocalStatusSQLiteFolder(LocalStatusFolder):
plaintextfilename = os.path.join( plaintextfilename = os.path.join(
self.repository.account.getaccountmeta(), self.repository.account.getaccountmeta(),
'LocalStatus', 'LocalStatus',
re.sub('(^|\/)\.$','\\1dot', self.name)) self.getfolderbasename(self.name))
# MIGRATE from plaintext if needed # MIGRATE from plaintext if needed
if os.path.exists(plaintextfilename): if os.path.exists(plaintextfilename):
self.ui._msg('Migrating LocalStatus cache from plain text ' self.ui._msg('Migrating LocalStatus cache from plain text '

View File

@ -50,10 +50,17 @@ class LocalStatusRepository(BaseRepository):
return '.' return '.'
def getfolderfilename(self, foldername): def getfolderfilename(self, foldername):
"""Return the full path of the status file""" """Return the full path of the status file
# replace with 'dot' if final path name is '.'
foldername = re.sub('(^|\/)\.$','\\1dot', foldername) This mimics the path that Folder().getfolderbasename() would return"""
return os.path.join(self.directory, foldername) if not foldername:
basename = '.'
else: #avoid directory hierarchies and file names such as '/'
basename = foldername.replace('/', '.')
# replace with literal 'dot' if final path name is '.' as '.' is
# an invalid file name.
basename = re.sub('(^|\/)\.$','\\1dot', basename)
return os.path.join(self.directory, basename)
def makefolder(self, foldername): def makefolder(self, foldername):
"""Create a LocalStatus Folder """Create a LocalStatus Folder