GitSharp.Core.DirectoryCache.DirCache.Lock C# (CSharp) Method

Lock() public static method

Create a new in-core index representation, lock it, and read from disk. The new index will be locked and then read before it is returned to the caller. Read failures are reported as exceptions and therefore prevent the method from returning a partially populated index. On read failure, the lock is released.
/// The index file is present but could not be read, or the lock /// could not be obtained. /// /// the index file is using a format or extension that this /// library does not support. ///
public static Lock ( FileInfo indexLocation ) : DirCache
indexLocation System.IO.FileInfo /// location of the index file on disk. ///
return DirCache
		public static DirCache Lock(FileInfo indexLocation)
		{
			var c = new DirCache(indexLocation);
			if (!c.Lock())
			{
				throw new IOException("Cannot lock " + indexLocation);
			}

			try
			{
				c.read();
			}
			catch (Exception)
			{
				c.unlock();
				throw;
			}

			return c;
		}

Same methods

DirCache::Lock ( Repository db ) : DirCache
DirCache::Lock ( ) : bool

Usage Example

Example #1
0
        ///	<summary>
        /// Create a new in-core index representation, lock it, and read from disk.
        /// <para />
        /// The new index will be locked and then read before it is returned to the
        /// caller. Read failures are reported as exceptions and therefore prevent
        /// the method from returning a partially populated index.  On read failure,
        /// the lock is released.
        /// </summary>
        /// <param name="indexLocation">
        /// location of the index file on disk.
        /// </param>
        /// <returns>
        /// A cache representing the contents of the specified index file (if
        /// it exists) or an empty cache if the file does not exist.
        /// </returns>
        /// <exception cref="IOException">
        /// The index file is present but could not be read, or the lock
        /// could not be obtained.
        /// </exception>
        /// <exception cref="CorruptObjectException">
        /// the index file is using a format or extension that this
        /// library does not support.
        /// </exception>
        public static DirCache Lock(FileInfo indexLocation)
        {
            var c = new DirCache(indexLocation);

            if (!c.Lock())
            {
                throw new IOException("Cannot lock " + indexLocation);
            }

            try
            {
                c.read();
            }
            catch (Exception)
            {
                c.unlock();
                throw;
            }

            return(c);
        }
All Usage Examples Of GitSharp.Core.DirectoryCache.DirCache::Lock