Permalink
Browse files

Recache folder list after creating a new folder

If we create a new folder we would previously not update our folder
list, which led to us skipping the synchronization of those new folders
during the initial run (subsequent runs would pick it up).

Invalidate the folder cache when we create a folder during folder
structure sync. Regetting the whole list from an IMAP server might be
slightly suboptimal from a performance point, but it is easy and will
lead to consistent results. Hopefully we will not have to create new
folders on each new run.

Reported-by: Daniel Shahaf <d.s@daniel.shahaf.name>
Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
  • Loading branch information...
spaetz committed Sep 30, 2011
1 parent 3f77490 commit 4e89bbfe6e1a95742630191800dfd9cfd76150a0
View
@@ -26,3 +26,6 @@ Bug Fixes
* Syncing multiple accounts in single-threaded mode would fail as we try
to "register" a thread as belonging to two accounts which was
fatal. Make it non-fatal (it can be legitimate).
+
+* New folders on the remote would be skipped on the very sync run they
+ are created and only by synced in subsequent runs. Fixed.
View
@@ -265,7 +265,7 @@ def sync(self):
remoterepos = self.remoterepos
localrepos = self.localrepos
statusrepos = self.statusrepos
- # replicate the folderstructure from REMOTE to LOCAL
+ # replicate the folderstructure between REMOTE to LOCAL
if not localrepos.getconfboolean('readonly', False):
self.ui.syncfolders(remoterepos, localrepos)
remoterepos.syncfoldersto(localrepos, statusrepos)
@@ -144,7 +144,8 @@ def syncfoldersto(self, dst_repo, status_repo):
src_repo = self
src_folders = src_repo.getfolders()
dst_folders = dst_repo.getfolders()
-
+ # Do we need to refresh the folder list afterwards?
+ src_haschanged, dst_haschanged = False, False
# Create hashes with the names, but convert the source folders
# to the dest folder's sep.
src_hash = {}
@@ -160,6 +161,7 @@ def syncfoldersto(self, dst_repo, status_repo):
if src_folder.sync_this and not src_name in dst_hash:
try:
dst_repo.makefolder(src_name)
+ dst_haschanged = True # Need to refresh list
except OfflineImapError, e:
self.ui.error(e, exc_info()[2],
"Creating folder %s on repository %s" %\
@@ -203,6 +205,7 @@ def syncfoldersto(self, dst_repo, status_repo):
try:
src_repo.makefolder(newsrc_name)
+ src_haschanged = True # Need to refresh list
except OfflineImapError, e:
self.ui.error(e, exc_info()[2],
"Creating folder %s on repository %s" %\
@@ -211,7 +214,13 @@ def syncfoldersto(self, dst_repo, status_repo):
status_repo.makefolder(newsrc_name.replace(
src_repo.getsep(), status_repo.getsep()))
# Find deleted folders.
- # We don't delete folders right now.
+ # TODO: We don't delete folders right now.
+
+ #Forget old list of cached folders so we get new ones if needed
+ if src_haschanged:
+ self.forgetfolders()
+ if dst_haschanged:
+ dst_repo.forgetfolders()
def startkeepalive(self):
"""The default implementation will do nothing."""
@@ -311,6 +311,10 @@ def getfolders(self):
def makefolder(self, foldername):
"""Create a folder on the IMAP server
+ This will not update the list cached in :meth:`getfolders`. You
+ will need to invoke :meth:`forgetfolders` to force new caching
+ when you are done creating folders yourself.
+
:param foldername: Full path of the folder to be created."""
#TODO: IMHO this existing commented out code is correct and
#should be enabled, but this would change the behavior for
@@ -72,6 +72,10 @@ def getsep(self):
def makefolder(self, foldername):
"""Create new Maildir folder if necessary
+ This will not update the list cached in getfolders(). You will
+ need to invoke :meth:`forgetfolders` to force new caching when
+ you are done creating folders yourself.
+
:param foldername: A relative mailbox name. The maildir will be
created in self.root+'/'+foldername. All intermediate folder
levels will be created if they do not exist yet. 'cur',
@@ -108,8 +112,6 @@ def makefolder(self, foldername):
(foldername, subdir))
else:
raise
- # Invalidate the folder cache
- self.folders = None
def deletefolder(self, foldername):
self.ui.warn("NOT YET IMPLEMENTED: DELETE FOLDER %s" % foldername)

0 comments on commit 4e89bbf

Please sign in to comment.