summaryrefslogtreecommitdiff
path: root/server/src/leap
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2014-01-07 11:05:39 -0200
committerdrebs <drebs@leap.se>2014-01-07 11:05:39 -0200
commit82628d8284c5c11452da75a6604f2f68b8dd8520 (patch)
tree2e7280c065301306611fd60d614111c19e43acaa /server/src/leap
parentf98f66549d6762bbfc072ef6afe0057798a4da27 (diff)
Use temp dir for server side locks (#4918).
Diffstat (limited to 'server/src/leap')
-rw-r--r--server/src/leap/soledad/server/__init__.py10
1 files changed, 8 insertions, 2 deletions
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