/// <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);
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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();
		}
Ejemplo n.º 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();
 }
Ejemplo n.º 8
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();
		}