Add cyclic dependence detection.

If a depends on b which depends on a, redo would just freeze.  Now it
aborts with a somewhat helpful error message.

[Updated by apenwarr for coding style and to add a test.]
This commit is contained in:
Robert L. Bocchino Jr 2016-11-27 23:35:28 -08:00 committed by Avery Pennarun
commit 7dd63efb37
8 changed files with 32 additions and 1 deletions

View file

@ -11,6 +11,9 @@ STAMP_DIR='dir' # the stamp of a directory; mtime is unhelpful
STAMP_MISSING='0' # the stamp of a nonexistent file
class CyclicDependencyError(Exception): pass
def _connect(dbfile):
_db = sqlite3.connect(dbfile, timeout=TIMEOUT)
_db.execute("pragma synchronous = off")
@ -347,6 +350,9 @@ class Lock:
def waitlock(self):
assert(not self.owned)
if str(self.fid) in vars.get_locks():
# Lock already held by parent: cyclic dependence
raise CyclicDependencyError
fcntl.lockf(self.lockfile, fcntl.LOCK_EX, 0, 0)
self.owned = True