]> source.dussan.org Git - jgit.git/commitdiff
Add public isStaleFileHandle() API, improve detection. 89/54489/1
authorMartin Fick <mfick@codeaurora.org>
Tue, 25 Aug 2015 13:48:50 +0000 (07:48 -0600)
committerMartin Fick <mfick@codeaurora.org>
Tue, 25 Aug 2015 14:19:54 +0000 (08:19 -0600)
Add a public API to the FileUtils to determine if an IOException is a
stale NFS file handle exception.  This will make it easier to detect
such errors, and interpret them consistently throughout the codebase.
This new API is a bit more lenient in its detection than the previous
detection, and should be able to detect some errors which previously
were not identified as stale file handle exceptions because they had the
word NFS in the error message.  Adjust the packfile handling code to use
this new API for detection.

Change-Id: I21f80014546ba1afec7335890e5ae79e7f521412
Signed-off-by: Martin Fick<mfick@codeaurora.org>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java

index 796109aee20f49209d55213d2a15f96f7fa7d807..a430d1a6f1fecce7f15051262c41baf47cc09963 100644 (file)
@@ -114,8 +114,6 @@ public class ObjectDirectory extends FileObjectDatabase {
        /** Maximum number of candidates offered as resolutions of abbreviation. */
        private static final int RESOLVE_ABBREV_LIMIT = 256;
 
-       private static final String STALE_FILE_HANDLE_MSG = "stale file handle"; //$NON-NLS-1$
-
        private final Config config;
 
        private final File objects;
@@ -565,8 +563,7 @@ public class ObjectDirectory extends FileObjectDatabase {
                } else if (e instanceof FileNotFoundException) {
                        warnTmpl = JGitText.get().packWasDeleted;
                        removePack(p);
-               } else if (e.getMessage() != null
-                               && e.getMessage().toLowerCase().contains(STALE_FILE_HANDLE_MSG)) {
+               } else if (FileUtils.isStaleFileHandle(e)) {
                        warnTmpl = JGitText.get().packHandleIsStale;
                        removePack(p);
                }
index 56eecc48d3aa00e3b2fb9f9ea1e7a83c9b150c8b..126384b7aec1121da133aea6d84504688c884646 100644 (file)
@@ -514,4 +514,15 @@ public class FileUtils {
                }
                return builder.toString();
        }
+
+       /**
+        * Determine if an IOException is a Stale NFS File Handle
+        *
+        * @param ioe
+        * @return a boolean true if the IOException is a Stale NFS FIle Handle
+        */
+       public static boolean isStaleFileHandle(IOException ioe) {
+               String msg = ioe.getMessage();
+               return msg != null && msg.toLowerCase().matches("stale .*file .*handle");
+       }
 }