From 94ce99ac9c0b4c5653fe46339feb525571d734a5 Mon Sep 17 00:00:00 2001 From: kimim Date: Mon, 1 Apr 2019 12:38:46 +0800 Subject: [PATCH] use portable locker to support cygwin in Windows --- offlineimap/accounts.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index 4aca7c4..644d03d 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -34,7 +34,7 @@ SYNC_MUTEXES = {} SYNC_MUTEXES_LOCK = Lock() try: - import fcntl + import portalocker except: pass # Ok if this fails, we can do without. @@ -232,7 +232,7 @@ class SyncableAccount(Account): self._lockfd = open(self._lockfilepath, 'w') try: - fcntl.lockf(self._lockfd, fcntl.LOCK_EX|fcntl.LOCK_NB) + portalocker.lock(self._lockfd, portalocker.LOCK_EX) except NameError: #fcntl not available (Windows), disable file locking... :( pass @@ -250,6 +250,7 @@ class SyncableAccount(Account): #If we own the lock file, delete it if self._lockfd and not self._lockfd.closed: + portalocker.unlock(self._lockfd) self._lockfd.close() try: os.unlink(self._lockfilepath)