Browse Source

Merge "Fix concurrent read / write issue in GitIndex on Windows"

tags/v0.9.1
Shawn Pearce 14 years ago
parent
commit
0ec0e21fdf

+ 26
- 4
org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java View File

@@ -297,10 +297,32 @@ public class GitIndex {
fc.write(buf);
fc.close();
fileOutputStream.close();
if (cacheFile.exists())
if (!cacheFile.delete())
throw new IOException(
JGitText.get().couldNotRenameDeleteOldIndex);
if (cacheFile.exists()) {
if (db.getFS().retryFailedLockFileCommit()) {
// file deletion fails on windows if another
// thread is reading the file concurrently
// So let's try 10 times...
boolean deleted = false;
for (int i = 0; i < 10; i++) {
if (cacheFile.delete()) {
deleted = true;
break;
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// ignore
}
}
if (!deleted)
throw new IOException(
JGitText.get().couldNotRenameDeleteOldIndex);
} else {
if (!cacheFile.delete())
throw new IOException(
JGitText.get().couldNotRenameDeleteOldIndex);
}
}
if (!tmpIndex.renameTo(cacheFile))
throw new IOException(
JGitText.get().couldNotRenameTemporaryIndexFileToIndex);

+ 7
- 0
org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java View File

@@ -148,6 +148,13 @@ public abstract class FS {
return userHome;
}

/**
* Does this file system have problems with atomic renames?
*
* @return true if the caller should retry a failed rename of a lock file.
*/
public abstract boolean retryFailedLockFileCommit();

/**
* Determine the user's home directory (location where preferences are).
*

+ 5
- 0
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java5.java View File

@@ -57,4 +57,9 @@ class FS_POSIX_Java5 extends FS {
public boolean setExecute(final File f, final boolean canExec) {
return false;
}

@Override
public boolean retryFailedLockFileCommit() {
return false;
}
}

+ 5
- 0
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX_Java6.java View File

@@ -104,4 +104,9 @@ class FS_POSIX_Java6 extends FS {
throw new Error(e);
}
}

@Override
public boolean retryFailedLockFileCommit() {
return false;
}
}

+ 5
- 0
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java View File

@@ -71,4 +71,9 @@ class FS_Win32 extends FS {
public boolean setExecute(final File f, final boolean canExec) {
return false;
}

@Override
public boolean retryFailedLockFileCommit() {
return true;
}
}

Loading…
Cancel
Save