/offlineimap/head: changeset 213

Fix to makefolder() such that it won't fail when hierarchical folders
are used and sub-folders are created before master folders.
This commit is contained in:
jgoerzen 2002-08-08 04:01:31 +01:00
parent 850db440ae
commit 29d64f7dbe

View File

@ -49,8 +49,22 @@ class MaildirRepository(BaseRepository):
assert foldername.find('./') == -1, "Folder names may not contain ../"
assert not foldername.startswith('/'), "Folder names may not begin with /"
oldcwd = os.getcwd()
os.chdir(self.root)
# If we're using hierarchical folders, it's possible that sub-folders
# may be created before higher-up ones. If this is the case,
# makedirs will fail because the higher-up dir already exists.
# So, check to see if this is indeed the case.
if os.path.isdir(foldername):
# Already exists. Sanity-check that it's not a Maildir.
for subdir in ['cur', 'new', 'tmp']:
assert not os.path.isdir(os.path.join(foldername, subdir)), \
"Tried to create folder %s but it already had dir %s" %\
(foldername, subdir)
else:
os.makedirs(foldername, 0700)
for subdir in ['cur', 'new', 'tmp']:
os.mkdir(os.path.join(foldername, subdir), 0700)