From 29d64f7dbe4bb8297774c01ad823fcd6f523a380 Mon Sep 17 00:00:00 2001 From: jgoerzen Date: Thu, 8 Aug 2002 04:01:31 +0100 Subject: [PATCH] /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. --- .../head/offlineimap/repository/Maildir.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/offlineimap/head/offlineimap/repository/Maildir.py b/offlineimap/head/offlineimap/repository/Maildir.py index 4a5f684..aa7a16f 100644 --- a/offlineimap/head/offlineimap/repository/Maildir.py +++ b/offlineimap/head/offlineimap/repository/Maildir.py @@ -49,9 +49,23 @@ 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) - os.makedirs(foldername, 0700) + + # 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) # Invalidate the cache