make portalocker really optional

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Nicolas Sebrecht 2019-04-27 14:51:41 +02:00
parent 93bc8d11ac
commit 801893cc73
3 changed files with 15 additions and 6 deletions

View File

@ -105,7 +105,7 @@ Bugs, issues and contributions can be requested to both the mailing list or the
* six (required) * six (required)
* imaplib2 >= 2.57 (optional) * imaplib2 >= 2.57 (optional)
* gssapi (optional), for Kerberos authentication * 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 ## Documentation

View File

@ -36,6 +36,9 @@ SYNC_MUTEXES_LOCK = Lock()
try: try:
import portalocker import portalocker
except: except:
try:
import fcntl
except:
pass # Ok if this fails, we can do without. pass # Ok if this fails, we can do without.
# FIXME: spaghetti code alert! # FIXME: spaghetti code alert!
@ -234,8 +237,11 @@ class SyncableAccount(Account):
try: try:
portalocker.lock(self._lockfd, portalocker.LOCK_EX) portalocker.lock(self._lockfd, portalocker.LOCK_EX)
except NameError: except NameError:
#fcntl not available (Windows), disable file locking... :( # portalocker not available for Windows.
pass try:
fcntl.lockf(self._lockfd, fcntl.LOCK_EX|fcntl.LOCK_NB)
except NameError:
pass # fnctl not available, disable file locking... :(
except IOError: except IOError:
self._lockfd.close() self._lockfd.close()
six.reraise(OfflineImapError, six.reraise(OfflineImapError,
@ -250,7 +256,10 @@ class SyncableAccount(Account):
#If we own the lock file, delete it #If we own the lock file, delete it
if self._lockfd and not self._lockfd.closed: if self._lockfd and not self._lockfd.closed:
try:
portalocker.unlock(self._lockfd) portalocker.unlock(self._lockfd)
except NameError:
pass
self._lockfd.close() self._lockfd.close()
try: try:
os.unlink(self._lockfilepath) os.unlink(self._lockfilepath)

View File

@ -1,4 +1,4 @@
# Requirements # Requirements
six six
gssapi[kerberos] gssapi[kerberos]
portalocker portalocker[cygwin]