/// <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 LockFailedException(GetFile());
            }
            try
            {
                lf.SetNeedSnapshot(true);
                lf.Write(@out);
                if (!lf.Commit())
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
                                                                   ()));
                }
            }
            finally
            {
                lf.Unlock();
            }
            snapshot = lf.GetCommitSnapshot();
            hash     = Hash(@out);
            // notify the listeners
            FireConfigChangedEvent();
        }
 protected internal override void WriteFile(string file, byte[] content)
 {
     FilePath p = new FilePath(_db.Directory, file);
     LockFile lck = new LockFile(p, FS.DETECTED);
     if (!lck.Lock())
         throw new ObjectWritingException("Can't write " + p);
     try {
         lck.Write(content);
     }
     catch (IOException) {
         throw new ObjectWritingException("Can't write " + p);
     }
     if (!lck.Commit())
         throw new ObjectWritingException("Can't write " + p);
 }
Пример #4
0
        /// <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;
            string text = ToText();

            if (utf8Bom)
            {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                bos.Write(unchecked ((int)(0xEF)));
                bos.Write(unchecked ((int)(0xBB)));
                bos.Write(unchecked ((int)(0xBF)));
                bos.Write(Sharpen.Runtime.GetBytesForString(text, RawParseUtils.UTF8_CHARSET.Name
                                                                ()));
                @out = bos.ToByteArray();
            }
            else
            {
                @out = Constants.Encode(text);
            }
            LockFile lf = new LockFile(GetFile(), fs);

            if (!lf.Lock())
            {
                throw new LockFailedException(GetFile());
            }
            try
            {
                lf.SetNeedSnapshot(true);
                lf.Write(@out);
                if (!lf.Commit())
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
                                                                   ()));
                }
            }
            finally
            {
                lf.Unlock();
            }
            snapshot = lf.GetCommitSnapshot();
            hash     = Hash(@out);
            // notify the listeners
            FireConfigChangedEvent();
        }
Пример #5
0
        /// <summary>Create the <code>pack-*.keep</code> file, with the given message.</summary>
        /// <remarks>Create the <code>pack-*.keep</code> file, with the given message.</remarks>
        /// <param name="msg">message to store in the file.</param>
        /// <returns>true if the keep file was successfully written; false otherwise.</returns>
        /// <exception cref="System.IO.IOException">the keep file could not be written.</exception>
        public virtual bool Lock(string msg)
        {
            if (msg == null)
            {
                return(false);
            }
            if (!msg.EndsWith("\n"))
            {
                msg += "\n";
            }
            LockFile lf = new LockFile(keepFile, fs);

            if (!lf.Lock())
            {
                return(false);
            }
            lf.Write(Constants.Encode(msg));
            return(lf.Commit());
        }
Пример #6
0
		/// <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;
			string text = ToText();
			if (utf8Bom)
			{
				ByteArrayOutputStream bos = new ByteArrayOutputStream();
				bos.Write(unchecked((int)(0xEF)));
				bos.Write(unchecked((int)(0xBB)));
				bos.Write(unchecked((int)(0xBF)));
				bos.Write(Sharpen.Runtime.GetBytesForString(text, RawParseUtils.UTF8_CHARSET.Name
					()));
				@out = bos.ToByteArray();
			}
			else
			{
				@out = Constants.Encode(text);
			}
			LockFile lf = new LockFile(GetFile(), fs);
			if (!lf.Lock())
			{
				throw new LockFailedException(GetFile());
			}
			try
			{
				lf.SetNeedSnapshot(true);
				lf.Write(@out);
				if (!lf.Commit())
				{
					throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
						()));
				}
			}
			finally
			{
				lf.Unlock();
			}
			snapshot = lf.GetCommitSnapshot();
			hash = Hash(@out);
			// notify the listeners
			FireConfigChangedEvent();
		}
Пример #7
0
 /// <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 LockFailedException(GetFile());
     }
     try
     {
         lf.SetNeedSnapshot(true);
         lf.Write(@out);
         if (!lf.Commit())
         {
             throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
                 ()));
         }
     }
     finally
     {
         lf.Unlock();
     }
     snapshot = lf.GetCommitSnapshot();
     hash = Hash(@out);
     // notify the listeners
     FireConfigChangedEvent();
 }
Пример #8
0
 /// <exception cref="System.IO.IOException"></exception>
 private void UpdateFETCH_HEAD(FetchResult result)
 {
     FilePath meta = transport.local.Directory;
     if (meta == null)
     {
         return;
     }
     LockFile Lock = new LockFile(new FilePath(meta, "FETCH_HEAD"), transport.local.FileSystem
         );
     try
     {
         if (Lock.Lock())
         {
             TextWriter w = new OutputStreamWriter(Lock.GetOutputStream());
             try
             {
                 foreach (FetchHeadRecord h in fetchHeadUpdates)
                 {
                     h.Write(w);
                     result.Add(h);
                 }
             }
             finally
             {
                 w.Close();
             }
             Lock.Commit();
         }
     }
     finally
     {
         Lock.Unlock();
     }
 }
Пример #9
0
		/// <summary>Create the <code>pack-*.keep</code> file, with the given message.</summary>
		/// <remarks>Create the <code>pack-*.keep</code> file, with the given message.</remarks>
		/// <param name="msg">message to store in the file.</param>
		/// <returns>true if the keep file was successfully written; false otherwise.</returns>
		/// <exception cref="System.IO.IOException">the keep file could not be written.</exception>
		public virtual bool Lock(string msg)
		{
			if (msg == null)
			{
				return false;
			}
			if (!msg.EndsWith("\n"))
			{
				msg += "\n";
			}
			LockFile lf = new LockFile(keepFile, fs);
			if (!lf.Lock())
			{
				return false;
			}
			lf.Write(Constants.Encode(msg));
			return lf.Commit();
		}