private RefUpdateResult UpdateImpl(RevWalk.RevWalk walk, StoreBase store) { if (isNameConflicting()) { return(RefUpdateResult.LockFailure); } var @lock = new LockFile(_looseFile); if ([email protected]()) { return(RefUpdateResult.LockFailure); } try { OldObjectId = _db.IdOf(Name); if (_expValue != null) { ObjectId o = OldObjectId ?? ObjectId.ZeroId; if (!AnyObjectId.equals(_expValue, o)) { return(RefUpdateResult.LockFailure); } } if (OldObjectId == null) { return(store.Store(@lock, RefUpdateResult.New)); } RevObject newObj = SafeParse(walk, _newValue); RevObject oldObj = SafeParse(walk, OldObjectId); if (newObj == oldObj) { return(store.Store(@lock, RefUpdateResult.NoChange)); } RevCommit newCom = (newObj as RevCommit); RevCommit oldCom = (oldObj as RevCommit); if (newCom != null && oldCom != null) { if (walk.isMergedInto(oldCom, newCom)) { return(store.Store(@lock, RefUpdateResult.FastForward)); } } if (IsForceUpdate) { return(store.Store(@lock, RefUpdateResult.Forced)); } return(RefUpdateResult.Rejected); } finally { @lock.Unlock(); } }
public override RefUpdateResult Store(LockFile @lock, RefUpdateResult status) { var storage = RefUpdate._ref.StorageFormat; if (storage == Ref.Storage.New) { return(status); } if (storage.IsPacked) { RefUpdate._db.RemovePackedRef(RefUpdate._ref.Name); } int levels = Count(RefUpdate._ref.Name, '/') - 2; // Delete logs _before_ unlocking DirectoryInfo gitDir = RefUpdate._db.Repository.Directory; var logDir = new DirectoryInfo(gitDir + "/" + Constants.LOGS); DeleteFileAndEmptyDir(new FileInfo(logDir + "/" + RefUpdate._ref.Name), levels); // We have to unlock before (maybe) deleting the parent directories @lock.Unlock(); if (storage.IsLoose) { DeleteFileAndEmptyDir(RefUpdate._looseFile, levels); } return(status); }
protected override void writeFile(string name, byte[] content) { _lck.setNeedStatInformation(true); try { _lck.Write(content); } catch (IOException ioe) { throw new ObjectWritingException("Unable to write " + name, ioe); } try { _lck.waitForStatChange(); } catch (ThreadAbortException) { _lck.Unlock(); throw new ObjectWritingException("Interrupted writing " + name); } if (!_lck.Commit()) { throw new ObjectWritingException("Unable to write " + name); } _packedRefs.compareAndSet(_oldPackedList, new PackedRefList(_refs, content.Length, _lck.CommitLastModified)); }
public override void unlock() { if (_lock != null) { _lock.Unlock(); _lock = null; } }
public void delete(RefDirectoryUpdate update) { Ref dst = update.getRef().getLeaf(); string name = dst.getName(); // Write the packed-refs file using an atomic update. We might // wind up reading it twice, before and after the lock, to ensure // we don't miss an edit made externally. PackedRefList packed = getPackedRefs(); if (packed.contains(name)) { var lck = new LockFile(packedRefsFile); if (!lck.Lock()) { throw new IOException("Cannot lock " + packedRefsFile); } try { PackedRefList cur = readPackedRefs(0, 0); int idx = cur.find(name); if (0 <= idx) { commitPackedRefs(lck, cur.remove(idx), packed); } } finally { lck.Unlock(); } } RefList <LooseRef> curLoose, newLoose; do { curLoose = looseRefs.get(); int idx = curLoose.find(name); if (idx < 0) { break; } newLoose = curLoose.remove(idx); } while (!looseRefs.compareAndSet(curLoose, newLoose)); int levels = levelsIn(name) - 2; delete(logFor(name), levels); if (dst.getStorage().IsLoose) { update.unlock(); delete(fileFor(name), levels); } modCnt.incrementAndGet(); fireRefsChanged(); }
public override void Close() { try { _lockFile._os.Flush(); _lockFile._fLck.Release(); _lockFile._os.Close(); _lockFile._os = null; } catch (Exception) { _lockFile.Unlock(); throw; } }
public void save() { byte[] o = Constants.encode(toText()); LockFile lf = new LockFile(getFile()); if (!lf.Lock()) { throw new IOException("Cannot lock " + getFile()); } try { lf.Write(o); if (!lf.Commit()) { throw new IOException("Cannot commit write to " + getFile()); } } finally { lf.Unlock(); } }
public void tryRenameWhenLocked(string toLock, string fromName, string toName, string headPointsTo) { // setup db.WriteSymref(Constants.HEAD, headPointsTo); ObjectId oldfromId = db.Resolve(fromName); ObjectId oldHeadId = db.Resolve(Constants.HEAD); RefLogWriter.WriteReflog(db, oldfromId, oldfromId, "Just a message", fromName); IList<ReflogReader.Entry> oldFromLog = db .ReflogReader(fromName).getReverseEntries(); IList<ReflogReader.Entry> oldHeadLog = oldHeadId != null ? db .ReflogReader(Constants.HEAD).getReverseEntries() : null; Assert.IsTrue(new FileInfo(Path.Combine(db.Directory.FullName, "logs/" + fromName)).Exists, "internal check, we have a log"); // "someone" has branch X locked var lockFile = new LockFile(new FileInfo(Path.Combine(db.Directory.FullName, toLock))); try { Assert.IsTrue(lockFile.Lock()); // Now this is our test RefRename renameRef = db.RenameRef(fromName, toName); RefUpdate.RefUpdateResult result = renameRef.Rename(); Assert.AreEqual(RefUpdate.RefUpdateResult.LockFailure, result); // Check that the involved refs are the same despite the failure assertExists(false, toName); if (!toLock.Equals(toName)) assertExists(false, toName + ".lock"); assertExists(true, toLock + ".lock"); if (!toLock.Equals(fromName)) assertExists(false, "logs/" + fromName + ".lock"); assertExists(false, "logs/" + toName + ".lock"); Assert.AreEqual(oldHeadId, db.Resolve(Constants.HEAD)); Assert.AreEqual(oldfromId, db.Resolve(fromName)); Assert.IsNull(db.Resolve(toName)); Assert.AreEqual(oldFromLog.ToString(), db.ReflogReader(fromName) .getReverseEntries().ToString()); if (oldHeadId != null) Assert.AreEqual(oldHeadLog, db.ReflogReader(Constants.HEAD) .getReverseEntries()); } finally { lockFile.Unlock(); } }
public void testUpdateRefLockFailureLocked() { ObjectId opid = db.Resolve("refs/heads/master"); ObjectId pid = db.Resolve("refs/heads/master^"); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.NewObjectId = pid; var lockFile1 = new LockFile(new FileInfo(Path.Combine(db.Directory.FullName, "refs/heads/master"))); try { Assert.IsTrue(lockFile1.Lock()); // precondition to test RefUpdate.RefUpdateResult update = updateRef.Update(); Assert.AreEqual(RefUpdate.RefUpdateResult.LockFailure, update); Assert.AreEqual(opid, db.Resolve("refs/heads/master")); var lockFile2 = new LockFile(new FileInfo(Path.Combine(db.Directory.FullName, "refs/heads/master"))); Assert.IsFalse(lockFile2.Lock()); // was locked, still is } finally { lockFile1.Unlock(); } }
public void save() { byte[] o = Constants.encode(toText()); LockFile lf = new LockFile(getFile()); if (!lf.Lock()) throw new IOException("Cannot lock " + getFile()); try { lf.Write(o); if (!lf.Commit()) throw new IOException("Cannot commit write to " + getFile()); } finally { lf.Unlock(); } }
public override RefUpdateResult Store(LockFile @lock, RefUpdateResult status) { var storage = RefUpdate._ref.StorageFormat; if (storage == Ref.Storage.New) { return status; } if (storage.IsPacked) { RefUpdate._db.RemovePackedRef(RefUpdate._ref.Name); } int levels = Count(RefUpdate._ref.Name, '/') - 2; // Delete logs _before_ unlocking DirectoryInfo gitDir = RefUpdate._db.Repository.Directory; var logDir = new DirectoryInfo(gitDir + "/" + Constants.LOGS); DeleteFileAndEmptyDir(new FileInfo(logDir + "/" + RefUpdate._ref.Name), levels); // We have to unlock before (maybe) deleting the parent directories @lock.Unlock(); if (storage.IsLoose) { DeleteFileAndEmptyDir(RefUpdate._looseFile, levels); } return status; }
private RefUpdateResult UpdateImpl(RevWalk.RevWalk walk, StoreBase store) { if (isNameConflicting()) { return RefUpdateResult.LockFailure; } var @lock = new LockFile(_looseFile); if ([email protected]()) { return RefUpdateResult.LockFailure; } try { OldObjectId = _db.IdOf(Name); if (_expValue != null) { ObjectId o = OldObjectId ?? ObjectId.ZeroId; if (!AnyObjectId.equals(_expValue, o)) { return RefUpdateResult.LockFailure; } } if (OldObjectId == null) { return store.Store(@lock, RefUpdateResult.New); } RevObject newObj = SafeParse(walk, _newValue); RevObject oldObj = SafeParse(walk, OldObjectId); if (newObj == oldObj) { return store.Store(@lock, RefUpdateResult.NoChange); } RevCommit newCom = (newObj as RevCommit); RevCommit oldCom = (oldObj as RevCommit); if (newCom != null && oldCom != null) { if (walk.isMergedInto(oldCom, newCom)) { return store.Store(@lock, RefUpdateResult.FastForward); } } if (IsForceUpdate) { return store.Store(@lock, RefUpdateResult.Forced); } return RefUpdateResult.Rejected; } finally { @lock.Unlock(); } }