mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
state: don't forget to lock before dumping db
Related to #1081 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+9
-4
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user