]> source.dussan.org Git - jgit.git/commitdiff
Merge branch 'stable-4.11' 94/122394/3
authorMatthias Sohn <matthias.sohn@sap.com>
Thu, 10 May 2018 11:41:45 +0000 (13:41 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 10 May 2018 11:41:45 +0000 (13:41 +0200)
* stable-4.11:
  Retry stale file handles on .git/config file

Change-Id: I4fe6152c3c40dde9cb88913cc9706852de0fd712
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
1  2 
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java

index 93ffb944c806e6a8acfc8a1ad02d669d3daad779,3f064e3341e51838ba685cb41e167f98719b8849..fcac80ce3c7def52d2afe5729ed2b3d565416f97
@@@ -143,40 -147,58 +149,58 @@@ public class FileBasedConfig extends St
         */
        @Override
        public void load() throws IOException, ConfigInvalidException {
-               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))
-                                       oldSnapshot.setClean(newSnapshot);
-                               else
-                                       snapshot = newSnapshot;
-                       } else {
-                               final String decoded;
-                               if (isUtf8(in)) {
-                                       decoded = RawParseUtils.decode(CHARSET,
-                                                       in, 3, in.length);
-                                       utf8Bom = true;
+               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)) {
+                                               oldSnapshot.setClean(newSnapshot);
+                                       } else {
+                                               snapshot = newSnapshot;
+                                       }
                                } else {
-                                       decoded = RawParseUtils.decode(in);
+                                       final String decoded;
+                                       if (isUtf8(in)) {
 -                                              decoded = RawParseUtils.decode(
 -                                                              RawParseUtils.UTF8_CHARSET, in, 3, in.length);
++                                              decoded = RawParseUtils.decode(CHARSET,
++                                                              in, 3, in.length);
+                                               utf8Bom = true;
+                                       } else {
+                                               decoded = RawParseUtils.decode(in);
+                                       }
+                                       fromText(decoded);
+                                       snapshot = newSnapshot;
+                                       hash = newHash;
                                }
-                               fromText(decoded);
+                               return;
+                       } catch (FileNotFoundException noFile) {
+                               if (configFile.exists()) {
+                                       throw noFile;
+                               }
+                               clear();
                                snapshot = newSnapshot;
-                               hash = newHash;
-                       }
-               } catch (FileNotFoundException noFile) {
-                       if (configFile.exists()) {
-                               throw noFile;
+                               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);
                        }
-                       clear();
-                       snapshot = newSnapshot;
-               } catch (IOException e) {
-                       throw new IOException(MessageFormat
-                                       .format(JGitText.get().cannotReadFile, getFile()), e);
-               } catch (ConfigInvalidException e) {
-                       throw new ConfigInvalidException(MessageFormat.format(JGitText.get().cannotReadFile, getFile()), e);
                }
        }