GitSharp.Core.LockFile.Lock C# (CSharp) Method

Lock() public method

* Try to establish the lock.
/// the temporary output file could not be created. The caller /// does not hold the lock. ///
public Lock ( ) : bool
return bool
        public bool Lock()
        {
            _lockFile.Directory.Mkdirs();
            if (_lockFile.Exists)
            {
                return false;
            }

            try
            {
                _haveLock = true;
                _os = _lockFile.Create();

                _fLck = FileLock.TryLock(_os, _lockFile);
                if (_fLck == null)
                {
                    // We cannot use unlock() here as this file is not
                    // held by us, but we thought we created it. We must
                    // not delete it, as it belongs to some other process.
                    _haveLock = false;
                    try
                    {
                        _os.Close();
                    }
                    catch (Exception)
                    {
                        // Fail by returning haveLck = false.
                    }
                    _os = null;
                }
            }
            catch (Exception)
            {
                Unlock();
                throw;
            }

            return _haveLock;
        }

Usage Example

Exemplo n.º 1
0
        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();
            }
        }
All Usage Examples Of GitSharp.Core.LockFile::Lock