Perform legacy global lock in addition to new per-account lock
We simply lock OfflineImap the same global way that we have always done in addition to the previously implemented per-account lock. We can keep both systems in parallel and then after a few stable releases, drop the old-style global lock. by reverting this patch Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
parent
89c705bb26
commit
0d95651417
@ -172,6 +172,7 @@ class SyncableAccount(Account):
|
|||||||
|
|
||||||
def lock(self):
|
def lock(self):
|
||||||
"""Lock the account, throwing an exception if it is locked already"""
|
"""Lock the account, throwing an exception if it is locked already"""
|
||||||
|
# Take a new-style per-account lock
|
||||||
self._lockfd = open(self._lockfilepath, 'w')
|
self._lockfd = open(self._lockfilepath, 'w')
|
||||||
try:
|
try:
|
||||||
fcntl.lockf(self._lockfd, fcntl.LOCK_EX|fcntl.LOCK_NB)
|
fcntl.lockf(self._lockfd, fcntl.LOCK_EX|fcntl.LOCK_NB)
|
||||||
|
@ -24,6 +24,10 @@ import signal
|
|||||||
import socket
|
import socket
|
||||||
import logging
|
import logging
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
try:
|
||||||
|
import fcntl
|
||||||
|
except ImportError:
|
||||||
|
pass #it's OK
|
||||||
import offlineimap
|
import offlineimap
|
||||||
from offlineimap import accounts, threadutil, syncmaster
|
from offlineimap import accounts, threadutil, syncmaster
|
||||||
from offlineimap.error import OfflineImapError
|
from offlineimap.error import OfflineImapError
|
||||||
@ -311,6 +315,18 @@ class OfflineImap:
|
|||||||
#various initializations that need to be performed:
|
#various initializations that need to be performed:
|
||||||
offlineimap.mbnames.init(config, syncaccounts)
|
offlineimap.mbnames.init(config, syncaccounts)
|
||||||
|
|
||||||
|
#TODO: keep legacy lock for a few versions, then remove.
|
||||||
|
self._legacy_lock = open(self.config.getmetadatadir() + "/lock",
|
||||||
|
'w')
|
||||||
|
try:
|
||||||
|
fcntl.lockf(self._legacy_lock, fcntl.LOCK_EX|fcntl.LOCK_NB)
|
||||||
|
except NameError:
|
||||||
|
#fcntl not available (Windows), disable file locking... :(
|
||||||
|
pass
|
||||||
|
except IOError:
|
||||||
|
raise OfflineImapError("Could not take global lock.",
|
||||||
|
OfflineImapError.ERROR.REPO)
|
||||||
|
|
||||||
if options.singlethreading:
|
if options.singlethreading:
|
||||||
#singlethreaded
|
#singlethreaded
|
||||||
self.sync_singlethreaded(syncaccounts, config)
|
self.sync_singlethreaded(syncaccounts, config)
|
||||||
@ -330,7 +346,7 @@ class OfflineImap:
|
|||||||
return
|
return
|
||||||
except (SystemExit):
|
except (SystemExit):
|
||||||
raise
|
raise
|
||||||
except:
|
except Exception, e:
|
||||||
ui.mainException()
|
ui.mainException()
|
||||||
|
|
||||||
def sync_singlethreaded(self, accs, config):
|
def sync_singlethreaded(self, accs, config):
|
||||||
|
Loading…
Reference in New Issue
Block a user