From 801893cc732246bb9ef837ae81db35a7856abc3d Mon Sep 17 00:00:00 2001 From: Nicolas Sebrecht Date: Sat, 27 Apr 2019 14:51:41 +0200 Subject: [PATCH] make portalocker really optional Signed-off-by: Nicolas Sebrecht --- README.md | 2 +- offlineimap/accounts.py | 17 +++++++++++++---- requirements.txt | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 03ad084..cd5d2fc 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ Bugs, issues and contributions can be requested to both the mailing list or the * six (required) * imaplib2 >= 2.57 (optional) * gssapi (optional), for Kerberos authentication -* portalocker(optional), if you need to run offlineimap in Cygwin for Windows +* portalocker (optional), if you need to run offlineimap in Cygwin for Windows ## Documentation diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index 644d03d..9d49546 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -36,7 +36,10 @@ SYNC_MUTEXES_LOCK = Lock() try: import portalocker except: - pass # Ok if this fails, we can do without. + try: + import fcntl + except: + pass # Ok if this fails, we can do without. # FIXME: spaghetti code alert! def getaccountlist(customconfig): @@ -234,8 +237,11 @@ class SyncableAccount(Account): try: portalocker.lock(self._lockfd, portalocker.LOCK_EX) except NameError: - #fcntl not available (Windows), disable file locking... :( - pass + # portalocker not available for Windows. + try: + fcntl.lockf(self._lockfd, fcntl.LOCK_EX|fcntl.LOCK_NB) + except NameError: + pass # fnctl not available, disable file locking... :( except IOError: self._lockfd.close() six.reraise(OfflineImapError, @@ -250,7 +256,10 @@ class SyncableAccount(Account): #If we own the lock file, delete it if self._lockfd and not self._lockfd.closed: - portalocker.unlock(self._lockfd) + try: + portalocker.unlock(self._lockfd) + except NameError: + pass self._lockfd.close() try: os.unlink(self._lockfilepath) diff --git a/requirements.txt b/requirements.txt index f4527a3..3b1819e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ # Requirements six gssapi[kerberos] -portalocker +portalocker[cygwin]