/// <exception cref="System.IO.IOException"></exception> protected internal override RefUpdate.Result DoUpdate(RefUpdate.Result status) { WriteConfig wc = database.GetRepository().GetConfig().Get(WriteConfig.KEY); Lock.SetFSync(wc.GetFSyncRefFiles()); Lock.SetNeedStatInformation(true); Lock.Write(GetNewObjectId()); string msg = GetRefLogMessage(); if (msg != null) { if (IsRefLogIncludingResult()) { string strResult = ToResultString(status); if (strResult != null) { if (msg.Length > 0) { msg = msg + ": " + strResult; } else { msg = strResult; } } } database.Log(this, msg, true); } if (!Lock.Commit()) { return(RefUpdate.Result.LOCK_FAILURE); } database.Stored(this, Lock.GetCommitSnapshot()); return(status); }
/// <summary>Save the configuration as a Git text style configuration file.</summary> /// <remarks> /// Save the configuration as a Git text style configuration file. /// <p> /// <b>Warning:</b> Although this method uses the traditional Git file /// locking approach to protect against concurrent writes of the /// configuration file, it does not ensure that the file has not been /// modified since the last read, which means updates performed by other /// objects accessing the same backing file may be lost. /// </remarks> /// <exception cref="System.IO.IOException">the file could not be written.</exception> public override void Save() { byte[] @out = Constants.Encode(ToText()); LockFile lf = new LockFile(GetFile(), fs); if (!lf.Lock()) { throw new IOException(MessageFormat.Format(JGitText.Get().cannotLockFile, GetFile ())); } try { lf.SetNeedStatInformation(true); lf.Write(@out); if (!lf.Commit()) { throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile ())); } } finally { lf.Unlock(); } lastModified = lf.GetCommitLastModified(); // notify the listeners FireConfigChangedEvent(); }