use portable locker to support cygwin in Windows

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
kimim 2019-04-01 12:38:46 +08:00 committed by Nicolas Sebrecht
parent 8a7946e338
commit 2806f40071

View File

@ -34,7 +34,7 @@ SYNC_MUTEXES = {}
SYNC_MUTEXES_LOCK = Lock() SYNC_MUTEXES_LOCK = Lock()
try: try:
import fcntl import portalocker
except: except:
pass # Ok if this fails, we can do without. pass # Ok if this fails, we can do without.
@ -232,7 +232,7 @@ class SyncableAccount(Account):
self._lockfd = open(self._lockfilepath, 'w') self._lockfd = open(self._lockfilepath, 'w')
try: try:
fcntl.lockf(self._lockfd, fcntl.LOCK_EX|fcntl.LOCK_NB) portalocker.lock(self._lockfd, portalocker.LOCK_EX)
except NameError: except NameError:
#fcntl not available (Windows), disable file locking... :( #fcntl not available (Windows), disable file locking... :(
pass pass
@ -250,6 +250,7 @@ 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:
portalocker.unlock(self._lockfd)
self._lockfd.close() self._lockfd.close()
try: try:
os.unlink(self._lockfilepath) os.unlink(self._lockfilepath)