MCPcopy
hub / github.com/treeverse/dvc / _edit_rwlock

Function _edit_rwlock

dvc/rwlock.py:45–67  ·  view source on GitHub ↗
(lock_dir, fs, hardlink)

Source from the content-addressed store, hash-verified

43
44@contextmanager
45def _edit_rwlock(lock_dir, fs, hardlink):
46 path = fs.join(lock_dir, RWLOCK_FILE)
47
48 rwlock_guard = make_lock(
49 fs.join(lock_dir, RWLOCK_LOCK),
50 tmp_dir=lock_dir,
51 hardlink_lock=hardlink,
52 )
53 with rwlock_guard:
54 try:
55 with fs.open(path, encoding="utf-8") as fobj:
56 lock = SCHEMA(json.load(fobj))
57 except FileNotFoundError:
58 lock = SCHEMA({})
59 except json.JSONDecodeError as exc:
60 raise RWLockFileCorruptedError(path) from exc
61 except Invalid as exc:
62 raise RWLockFileFormatError(path) from exc
63 lock["read"] = defaultdict(list, lock["read"])
64 lock["write"] = defaultdict(dict, lock["write"])
65 yield lock
66 with fs.open(path, "w", encoding="utf-8") as fobj:
67 json.dump(lock, fobj)
68
69
70def _infos_to_str(infos):

Callers 4

test_rwlock_reentrantFunction · 0.90
test_broken_rwlockFunction · 0.90
rwlockFunction · 0.85

Calls 7

make_lockFunction · 0.85
joinMethod · 0.80
openMethod · 0.80
loadMethod · 0.45
dumpMethod · 0.45

Tested by 3

test_rwlock_reentrantFunction · 0.72
test_broken_rwlockFunction · 0.72