Example #1
0
def makestableidentifier(orig, length=16):
    stableidentifierfile = os.path.join(os.environ["TESTTMP"],
                                        "stableidentifier")
    with extutil.flock(stableidentifierfile, "stableidentifier"):
        try:
            coid = int(open(stableidentifierfile).read().strip())
        except Exception:
            coid = 0
        with open(stableidentifierfile, "w") as f:
            f.write("%s\n" % (coid + 1))
    return "%0*d" % (length, coid)
Example #2
0
    def testflock(self):
        testtmp = os.environ["TESTTMP"]
        opener = vfs.vfs(testtmp)
        name = "testlock"

        with extutil.flock(opener.join(name), "testing a lock", timeout=0):
            otherlock = self.otherprocesslock(opener, name)
            self.assertEqual(otherlock, locktimeout,
                             "other process should not have taken the lock")

        otherlock = self.otherprocesslock(opener, name)
        self.assertEqual(otherlock, locksuccess,
                         "other process should have taken the lock")
Example #3
0
 def otherprocesslock(self, opener, name):
     pid = os.fork()
     if pid == 0:
         try:
             with extutil.flock(opener.join(name), "other process lock", timeout=0):
                 os._exit(locksuccess)
         except error.LockHeld:
             os._exit(locktimeout)
     else:
         time.sleep(0.1) # Avoids a crash on OSX
         p, st = os.waitpid(pid, 0)
         st = _exitstatus(st)  # Convert back to an int
         return st
Example #4
0
def savepinnednodes(repo, newpin, newunpin, fullargs):
    # take a narrowed lock so it does not affect repo lock
    with extutil.flock(repo.svfs.join("obsinhibit.lock"), "save pinned nodes"):
        orignodes = loadpinnednodes(repo)
        nodes = set(orignodes)
        nodes |= set(newpin)
        nodes -= set(newunpin)
        with util.atomictempfile(repo.svfs.join("obsinhibit")) as f:
            f.write("".join(nodes))

        desc = lambda s: [short(n) for n in s]
        repo.ui.log(
            "pinnednodes",
            "pinnednodes: %r newpin=%r newunpin=%r "
            "before=%r after=%r\n",
            fullargs,
            desc(newpin),
            desc(newunpin),
            desc(orignodes),
            desc(nodes),
        )
Example #5
0
def debugwaitonrepack(repo):
    with extutil.flock(repacklockvfs(repo).join("repacklock"), ""):
        return