state: don't forget to lock before dumping db

Related to #1081

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-09-02 23:47:50 +03:00
parent f1f1a97fbf
commit 022eea8214
+9 -4
View File
@@ -86,7 +86,7 @@ class State(object):
exc)
return {}
def dump(self):
def _dump(self):
if not self.state_file:
return
@@ -94,6 +94,11 @@ class State(object):
with open(self.state_file, 'w+') as fd:
json.dump(self._db, fd)
def dump(self):
with self._lock:
with self._lock_file:
self._dump()
@staticmethod
def mtime(path):
mtime = os.path.getmtime(path)
@@ -131,7 +136,7 @@ class State(object):
self._db[inode] = d
if dump:
self.dump()
self._dump()
return (md5, info)
@@ -207,7 +212,7 @@ class LinkState(State):
self._db[os.path.relpath(path, self.root_dir)] = d
if dump:
with self._lock_file:
self.dump()
self._dump()
def _do_remove_unused(self, used):
items = self._db.copy().items()
@@ -233,4 +238,4 @@ class LinkState(State):
with self._lock:
with self._lock_file:
self._do_remove_unused(used)
self.dump()
self._dump()