From 4217fccb821f35238bc63c3e672093911a6ddc1d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 22 Mar 2015 14:34:24 -0400 Subject: [PATCH] mbnames: add option to write the file once per account The basic problem is in the context of syncing multiple accounts where one is fast and the others are slower (due to the number of folders). When the fast account completes, the other accounts are partially written through the list and if the file is read during this time, the list can be useless. However, in the general case, the file is probably left around from a previous run of offlineimap and is more correct, so add an option to leave it alone until all syncing is done. Incremental is still the default since this running offlineimap using its own timer setup is likely the most common setup. Turning it off works best with one-shot mode triggered by cron or systemd timers. Signed-off-by: Ben Boeckel Signed-off-by: Nicolas Sebrecht --- offlineimap.conf | 8 ++++++++ offlineimap/accounts.py | 2 +- offlineimap/init.py | 4 ++++ offlineimap/mbnames.py | 12 +++++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/offlineimap.conf b/offlineimap.conf index 7fbbdf7..c447d7b 100644 --- a/offlineimap.conf +++ b/offlineimap.conf @@ -182,6 +182,13 @@ accounts = Test # The header, peritem, sep, and footer are all Python expressions passed # through eval, so you can (and must) use Python quoting. # +# The incremental setting controls whether the file is written after each +# account completes or once all synced accounts are complete. This is usefull if +# an account is sightly slower than the other. It allows keeping the previous +# file rather than having it partially written. +# This works best with "no" if in one-shot mode started by cron or systemd +# timers. Default: no. +# # The following hash key are available to the expansion for 'peritem': # - accountname: the name of the corresponding account; # - foldername: the name of the folder; @@ -197,6 +204,7 @@ accounts = Test #peritem = "+%(accountname)s/%(foldername)s" #sep = " " #footer = "\n" +#incremental = no # This option stands in the [mbnames] section. diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index 62ed5c3..cac4d88 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -359,7 +359,7 @@ class SyncableAccount(Account): thr.join() # Write out mailbox names if required and not in dry-run mode if not self.dryrun: - mbnames.write() + mbnames.write(False) localrepos.forgetfolders() remoterepos.forgetfolders() except: diff --git a/offlineimap/init.py b/offlineimap/init.py index a5277cb..a48c152 100644 --- a/offlineimap/init.py +++ b/offlineimap/init.py @@ -334,6 +334,10 @@ class OfflineImap: 'config': self.config}) t.start() threadutil.exitnotifymonitorloop(threadutil.threadexited) + + if not options.dryrun: + offlineimap.mbnames.write(True) + self.ui.terminate() except (SystemExit): raise diff --git a/offlineimap/mbnames.py b/offlineimap/mbnames.py index 936a110..8829ee5 100644 --- a/offlineimap/mbnames.py +++ b/offlineimap/mbnames.py @@ -38,7 +38,17 @@ def add(accountname, foldername, localfolders): if not foldername in boxes[accountname]: boxes[accountname].append(foldername) -def write(): +def write(allcomplete): + incremental = config.getdefaultboolean("mbnames", "incremental", False) + + # Skip writing if we don't want incremental writing and we're not done. + if not incremental and not allcomplete: + return + + # Skip writing if we want incremental writing and we're done. + if incremental and allcomplete: + return + # See if we're ready to write it out. for account in accounts: if account not in boxes: