diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index 5a2a120..5138523 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -172,6 +172,7 @@ class SyncableAccount(Account): def lock(self): """Lock the account, throwing an exception if it is locked already""" + # Take a new-style per-account lock self._lockfd = open(self._lockfilepath, 'w') try: fcntl.lockf(self._lockfd, fcntl.LOCK_EX|fcntl.LOCK_NB) diff --git a/offlineimap/init.py b/offlineimap/init.py index 88baf9f..e5560a9 100644 --- a/offlineimap/init.py +++ b/offlineimap/init.py @@ -24,6 +24,10 @@ import signal import socket import logging from optparse import OptionParser +try: + import fcntl +except ImportError: + pass #it's OK import offlineimap from offlineimap import accounts, threadutil, syncmaster from offlineimap.error import OfflineImapError @@ -311,6 +315,18 @@ class OfflineImap: #various initializations that need to be performed: 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: #singlethreaded self.sync_singlethreaded(syncaccounts, config) @@ -330,7 +346,7 @@ class OfflineImap: return except (SystemExit): raise - except: + except Exception, e: ui.mainException() def sync_singlethreaded(self, accs, config):