Move env.{add,get}_lock() into cycles.py, and rename.

They really aren't locks at all, they're a cycle detector.  Also rename
REDO_LOCKS to a more meaningful REDO_CYCLES.  And we'll move the
CyclicDependencyError exception in here as well, instead of state.py
where it doesn't really belong.
This commit is contained in:
Avery Pennarun 2018-12-05 00:18:07 -05:00
commit f1305b49eb
5 changed files with 32 additions and 25 deletions

View file

@ -1,5 +1,5 @@
import sys, os, errno, stat, fcntl, sqlite3
import env
import cycles, env
from helpers import unlink, close_on_exec, join
from logs import warn, debug2, debug3
@ -24,10 +24,6 @@ STAMP_MISSING = '0' # the stamp of a nonexistent file
LOG_LOCK_MAGIC = 0x10000000 # fid offset for "log locks"
class CyclicDependencyError(Exception):
pass
def _connect(dbfile):
_db = sqlite3.connect(dbfile, timeout=TIMEOUT)
_db.execute("pragma synchronous = off")
@ -466,9 +462,7 @@ class Lock(object):
def check(self):
assert not self.owned
if str(self.fid) in env.get_locks():
# Lock already held by parent: cyclic dependence
raise CyclicDependencyError()
cycles.check(self.fid)
def trylock(self):
self.check()