diff options
author | Jens Baumgart <jens.baumgart@sap.com> | 2010-07-26 10:18:47 +0200 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-07-27 10:00:47 -0700 |
commit | db82b8d7eb646a2d31f1b4e52ab4a623743192e9 (patch) | |
tree | d484fb29139ae3673dfad6930aaefb467ec41977 /org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java | |
parent | a00377a7e23dbde315598ee20f61c45d031e159a (diff) | |
download | jgit-db82b8d7eb646a2d31f1b4e52ab4a623743192e9.tar.gz jgit-db82b8d7eb646a2d31f1b4e52ab4a623743192e9.zip |
Fix concurrent read / write issue in LockFile on Windows
LockFile.commit fails if another thread concurrently reads
the base file. The problem is fixed by retrying the rename
operation if it fails.
Change-Id: I6bb76ea7f2e6e90e3ddc45f9dd4d69bd1b6fa1eb
Bug: 308506
Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java index cc10fad2b4..60238c3d8b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java @@ -67,6 +67,7 @@ import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.storage.file.LockFile; +import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.MutableInteger; import org.eclipse.jgit.util.NB; @@ -129,7 +130,7 @@ public class DirCache { * memory). */ public static DirCache newInCore() { - return new DirCache(null); + return new DirCache(null, null); } /** @@ -141,6 +142,9 @@ public class DirCache { * * @param indexLocation * location of the index file on disk. + * @param fs + * the file system abstraction which will be necessary to perform + * certain file system operations. * @return a cache representing the contents of the specified index file (if * it exists) or an empty cache if the file does not exist. * @throws IOException @@ -149,9 +153,9 @@ public class DirCache { * the index file is using a format or extension that this * library does not support. */ - public static DirCache read(final File indexLocation) + public static DirCache read(final File indexLocation, final FS fs) throws CorruptObjectException, IOException { - final DirCache c = new DirCache(indexLocation); + final DirCache c = new DirCache(indexLocation, fs); c.read(); return c; } @@ -161,11 +165,14 @@ public class DirCache { * <p> * 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 method from returning a partially populated index. On read failure, * the lock is released. * * @param indexLocation * location of the index file on disk. + * @param fs + * the file system abstraction which will be necessary to perform + * certain file system operations. * @return a cache representing the contents of the specified index file (if * it exists) or an empty cache if the file does not exist. * @throws IOException @@ -175,9 +182,9 @@ public class DirCache { * the index file is using a format or extension that this * library does not support. */ - public static DirCache lock(final File indexLocation) + public static DirCache lock(final File indexLocation, final FS fs) throws CorruptObjectException, IOException { - final DirCache c = new DirCache(indexLocation); + final DirCache c = new DirCache(indexLocation, fs); if (!c.lock()) throw new IOException(MessageFormat.format(JGitText.get().cannotLock, indexLocation)); @@ -215,6 +222,9 @@ public class DirCache { /** Our active lock (if we hold it); null if we don't have it locked. */ private LockFile myLock; + /** file system abstraction **/ + private final FS fs; + /** * Create a new in-core index representation. * <p> @@ -223,9 +233,13 @@ public class DirCache { * * @param indexLocation * location of the index file on disk. + * @param fs + * the file system abstraction which will be necessary to perform + * certain file system operations. */ - public DirCache(final File indexLocation) { + public DirCache(final File indexLocation, final FS fs) { liveFile = indexLocation; + this.fs = fs; clear(); } @@ -429,7 +443,7 @@ public class DirCache { public boolean lock() throws IOException { if (liveFile == null) throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile); - final LockFile tmp = new LockFile(liveFile); + final LockFile tmp = new LockFile(liveFile, fs); if (tmp.lock()) { tmp.setNeedStatInformation(true); myLock = tmp; |