mbnames: don't duplicate entries in autorefresh mode
mbnames is initialized and written once in the run from OfflineImap.__sync(). However, the in-memory instance is fed with data at sync time for each folder and the intermediate files are written as soon as all the folders are synced for the account. All of this is done inside the SyncableAccount.__sync() method while the syncrunner is looping on this. This means that we duplicate entries for mbnames in each loop (most likely when autorefresh is enabled). It is wrong to have duplicates in mbnames for each account. Ignore duplicates when adding data in the mbnames intermediate files. Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/467 Reported-and-tested-by: Shin Kojima <shin@kojima.org> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
ddf2df1d8d
commit
5d5ad62fa7
@ -309,6 +309,9 @@ class SyncableAccount(Account):
|
|||||||
remotefolder.getvisiblename().
|
remotefolder.getvisiblename().
|
||||||
replace(self.remoterepos.getsep(), self.localrepos.getsep()))
|
replace(self.remoterepos.getsep(), self.localrepos.getsep()))
|
||||||
|
|
||||||
|
|
||||||
|
# The syncrunner will loop on this method. This means it is called more than
|
||||||
|
# once during the run.
|
||||||
def __sync(self):
|
def __sync(self):
|
||||||
"""Synchronize the account once, then return.
|
"""Synchronize the account once, then return.
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ _mbLock = Lock()
|
|||||||
_mbnames = None
|
_mbnames = None
|
||||||
|
|
||||||
|
|
||||||
|
# Called at sync time for each folder.
|
||||||
def add(accountname, folder_root, foldername):
|
def add(accountname, folder_root, foldername):
|
||||||
global _mbnames
|
global _mbnames
|
||||||
if _mbnames.is_enabled() is not True:
|
if _mbnames.is_enabled() is not True:
|
||||||
@ -41,12 +42,14 @@ def add(accountname, folder_root, foldername):
|
|||||||
_mbnames.addAccountFolder(accountname, folder_root, foldername)
|
_mbnames.addAccountFolder(accountname, folder_root, foldername)
|
||||||
|
|
||||||
|
|
||||||
|
# Called once.
|
||||||
def init(conf, ui, dry_run):
|
def init(conf, ui, dry_run):
|
||||||
global _mbnames
|
global _mbnames
|
||||||
if _mbnames is None:
|
if _mbnames is None:
|
||||||
_mbnames = _Mbnames(conf, ui, dry_run)
|
_mbnames = _Mbnames(conf, ui, dry_run)
|
||||||
|
|
||||||
|
|
||||||
|
# Called once.
|
||||||
def prune(accounts):
|
def prune(accounts):
|
||||||
global _mbnames
|
global _mbnames
|
||||||
if _mbnames.is_enabled() is True:
|
if _mbnames.is_enabled() is True:
|
||||||
@ -55,6 +58,7 @@ def prune(accounts):
|
|||||||
_mbnames.pruneAll()
|
_mbnames.pruneAll()
|
||||||
|
|
||||||
|
|
||||||
|
# Called once.
|
||||||
def write():
|
def write():
|
||||||
"""Write the mbnames file."""
|
"""Write the mbnames file."""
|
||||||
|
|
||||||
@ -66,6 +70,7 @@ def write():
|
|||||||
_mbnames.write()
|
_mbnames.write()
|
||||||
|
|
||||||
|
|
||||||
|
# Called as soon as all the folders are synced for the account.
|
||||||
def writeIntermediateFile(accountname):
|
def writeIntermediateFile(accountname):
|
||||||
"""Write intermediate mbnames file."""
|
"""Write intermediate mbnames file."""
|
||||||
|
|
||||||
@ -93,6 +98,7 @@ class _IntermediateMbnames(object):
|
|||||||
self._dryrun = dry_run
|
self._dryrun = dry_run
|
||||||
|
|
||||||
def add(self, foldername):
|
def add(self, foldername):
|
||||||
|
if foldername not in self._foldernames:
|
||||||
self._foldernames.append(foldername)
|
self._foldernames.append(foldername)
|
||||||
|
|
||||||
def get_folder_root(self):
|
def get_folder_root(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user