Browse Source

Merge branch 'stable-4.11'

* stable-4.11:
  Retry stale file handles on .git/config file

Change-Id: I4fe6152c3c40dde9cb88913cc9706852de0fd712
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-5.0
Matthias Sohn 7 years ago
parent
commit
81fa158e7c
  1. 1
      org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
  2. 1
      org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
  3. 30
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java

1
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties

@ -136,6 +136,7 @@ compressingObjects=Compressing objects
configSubsectionContainsNewline=config subsection name contains newline
configSubsectionContainsNullByte=config subsection name contains byte 0x00
configValueContainsNullByte=config value contains byte 0x00
configHandleIsStale=config file handle is stale, {0}. retry
connectionFailed=connection failed
connectionTimeOut=Connection time out: {0}
contextMustBeNonNegative=context must be >= 0

1
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java

@ -197,6 +197,7 @@ public class JGitText extends TranslationBundle {
/***/ public String configSubsectionContainsNewline;
/***/ public String configSubsectionContainsNullByte;
/***/ public String configValueContainsNullByte;
/***/ public String configHandleIsStale;
/***/ public String connectionFailed;
/***/ public String connectionTimeOut;
/***/ public String contextMustBeNonNegative;

30
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java

@ -68,13 +68,19 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The configuration file that is stored in the file of the file system.
*/
public class FileBasedConfig extends StoredConfig {
private final static Logger LOG = LoggerFactory
.getLogger(FileBasedConfig.class);
private final File configFile;
private final FS fs;
@ -143,16 +149,20 @@ public class FileBasedConfig extends StoredConfig {
*/
@Override
public void load() throws IOException, ConfigInvalidException {
final int maxStaleRetries = 5;
int retries = 0;
while (true) {
final FileSnapshot oldSnapshot = snapshot;
final FileSnapshot newSnapshot = FileSnapshot.save(getFile());
try {
final byte[] in = IO.readFully(getFile());
final ObjectId newHash = hash(in);
if (hash.equals(newHash)) {
if (oldSnapshot.equals(newSnapshot))
if (oldSnapshot.equals(newSnapshot)) {
oldSnapshot.setClean(newSnapshot);
else
} else {
snapshot = newSnapshot;
}
} else {
final String decoded;
if (isUtf8(in)) {
@ -166,17 +176,31 @@ public class FileBasedConfig extends StoredConfig {
snapshot = newSnapshot;
hash = newHash;
}
return;
} catch (FileNotFoundException noFile) {
if (configFile.exists()) {
throw noFile;
}
clear();
snapshot = newSnapshot;
return;
} catch (IOException e) {
if (FileUtils.isStaleFileHandle(e)
&& retries < maxStaleRetries) {
if (LOG.isDebugEnabled()) {
LOG.debug(MessageFormat.format(
JGitText.get().configHandleIsStale,
Integer.valueOf(retries)), e);
}
retries++;
continue;
}
throw new IOException(MessageFormat
.format(JGitText.get().cannotReadFile, getFile()), e);
} catch (ConfigInvalidException e) {
throw new ConfigInvalidException(MessageFormat.format(JGitText.get().cannotReadFile, getFile()), e);
throw new ConfigInvalidException(MessageFormat
.format(JGitText.get().cannotReadFile, getFile()), e);
}
}
}

Loading…
Cancel
Save