diff options
author | drebs <drebs@leap.se> | 2014-01-07 11:05:39 -0200 |
---|---|---|
committer | drebs <drebs@leap.se> | 2014-01-07 11:05:39 -0200 |
commit | 82628d8284c5c11452da75a6604f2f68b8dd8520 (patch) | |
tree | 2e7280c065301306611fd60d614111c19e43acaa /server | |
parent | f98f66549d6762bbfc072ef6afe0057798a4da27 (diff) |
Use temp dir for server side locks (#4918).
Diffstat (limited to 'server')
-rw-r--r-- | server/changes/feature_4918_use-temporary-directory-for-server-side-locks | 1 | ||||
-rw-r--r-- | server/src/leap/soledad/server/__init__.py | 10 |
2 files changed, 9 insertions, 2 deletions
diff --git a/server/changes/feature_4918_use-temporary-directory-for-server-side-locks b/server/changes/feature_4918_use-temporary-directory-for-server-side-locks new file mode 100644 index 00000000..d8c5ba8e --- /dev/null +++ b/server/changes/feature_4918_use-temporary-directory-for-server-side-locks @@ -0,0 +1 @@ + o Use a temporary directory for server side locks (#4918). diff --git a/server/src/leap/soledad/server/__init__.py b/server/src/leap/soledad/server/__init__.py index 00d3c8c1..4380966c 100644 --- a/server/src/leap/soledad/server/__init__.py +++ b/server/src/leap/soledad/server/__init__.py @@ -90,6 +90,7 @@ import configparser import time import hashlib import os +import tempfile from u1db.remote import http_app @@ -122,6 +123,7 @@ from leap.soledad.common.errors import ( NotLockedError, AlreadyLockedError, LockTimedOutError, + CouldNotObtainLockError, ) @@ -201,7 +203,9 @@ class LockResource(object): self._shared_db = state.open_database(SoledadApp.SHARED_DB_NAME) self._lock_doc_id = '%s%s' % (SHARED_DB_LOCK_DOC_ID_PREFIX, uuid) self._lock = FilesystemLock( - hashlib.sha512(self._lock_doc_id).hexdigest()) + os.path.join( + tempfile.gettmpdir(), + hashlib.sha512(self._lock_doc_id).hexdigest())) self._state = state self._responder = responder @@ -328,8 +332,10 @@ class LockResource(object): while tries > 0: try: return self._lock.lock() - except Exception as e: + except OSError as e: tries -= 1 + if tries == 0: + raise CouldNotObtainLockError(e.message) time.sleep(self.FILESYSTEM_LOCK_SLEEP_SECONDS) return False |