summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2015-11-20 14:40:41 +0100
committerJonathan Nieder <jrn@google.com>2015-11-24 15:54:20 -0500
commitd2faec27a7af7c9ea7db6b4ac31f75533ca45b80 (patch)
treede6457295b3001431ca8c142be617092cf2bf9e6 /org.eclipse.jgit
parent15e60b646e1af9c6b7bf01d3822dc50162dbf3dc (diff)
downloadjgit-d2faec27a7af7c9ea7db6b4ac31f75533ca45b80.tar.gz
jgit-d2faec27a7af7c9ea7db6b4ac31f75533ca45b80.zip
Raise error if FileNotFoundException is caught for an existing file
File, FileInputStream and friends may throw FileNotFoundException even if the file is existing e.g. when file permissions don't allow to access the file content. In most cases this is a severe error we should not suppress hence rethrow the FileNotFoundException in this case. This may also fix bug 451508. Bug: 451508 Change-Id: If4a94217fb5b7cfd4c04d881902f3e86193c7008 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java37
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReaderImpl.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java3
10 files changed, 53 insertions, 19 deletions
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
index cdb2be151d..6e3b3047fb 100644
--- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
+++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
@@ -451,6 +451,7 @@ packfileIsTruncated=Packfile {0} is truncated.
packfileIsTruncatedNoParam=Packfile is truncated.
packHandleIsStale=Pack file {0} handle is stale, removing it from pack list
packHasUnresolvedDeltas=pack has unresolved deltas
+packInaccessible=Pack file {0} now inaccessible; removing it from pack list
packingCancelledDuringObjectsWriting=Packing cancelled during objects writing
packObjectCountMismatch=Pack object count mismatch: pack {0} index {1}: {2}
packRefs=Pack refs
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
index ff29008420..753bc85bc6 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
@@ -980,6 +980,9 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
try {
raw = IO.readFully(authorScriptFile);
} catch (FileNotFoundException notFound) {
+ if (authorScriptFile.exists()) {
+ throw notFound;
+ }
return null;
}
return parseAuthor(raw);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
index be29feabd0..b03038b062 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
@@ -510,6 +510,7 @@ public class JGitText extends TranslationBundle {
/***/ public String packfileIsTruncatedNoParam;
/***/ public String packHandleIsStale;
/***/ public String packHasUnresolvedDeltas;
+ /***/ public String packInaccessible;
/***/ public String packingCancelledDuringObjectsWriting;
/***/ public String packObjectCountMismatch;
/***/ public String packRefs;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java
index 50297a97a0..e23ca741b8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java
@@ -227,6 +227,10 @@ public class LockFile {
fis.close();
}
} catch (FileNotFoundException fnfe) {
+ if (ref.exists()) {
+ unlock();
+ throw fnfe;
+ }
// Don't worry about a file that doesn't exist yet, it
// conceptually has no current content to copy.
//
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
index e7ef127dd7..bd1d488d94 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
@@ -433,16 +433,14 @@ public class ObjectDirectory extends FileObjectDatabase {
ObjectLoader openLooseObject(WindowCursor curs, AnyObjectId id)
throws IOException {
- try {
- File path = fileFor(id);
- FileInputStream in = new FileInputStream(path);
- try {
- unpackedObjectCache.add(id);
- return UnpackedObject.open(in, path, id, curs);
- } finally {
- in.close();
- }
+ File path = fileFor(id);
+ try (FileInputStream in = new FileInputStream(path)) {
+ unpackedObjectCache.add(id);
+ return UnpackedObject.open(in, path, id, curs);
} catch (FileNotFoundException noFile) {
+ if (path.exists()) {
+ throw noFile;
+ }
unpackedObjectCache.remove(id);
return null;
}
@@ -513,15 +511,14 @@ public class ObjectDirectory extends FileObjectDatabase {
private long getLooseObjectSize(WindowCursor curs, AnyObjectId id)
throws IOException {
- try {
- FileInputStream in = new FileInputStream(fileFor(id));
- try {
- unpackedObjectCache.add(id);
- return UnpackedObject.getSize(in, id, curs);
- } finally {
- in.close();
- }
+ File f = fileFor(id);
+ try (FileInputStream in = new FileInputStream(f)) {
+ unpackedObjectCache.add(id);
+ return UnpackedObject.getSize(in, id, curs);
} catch (FileNotFoundException noFile) {
+ if (f.exists()) {
+ throw noFile;
+ }
unpackedObjectCache.remove(id);
return -1;
}
@@ -561,7 +558,11 @@ public class ObjectDirectory extends FileObjectDatabase {
// Assume the pack is corrupted, and remove it from the list.
removePack(p);
} else if (e instanceof FileNotFoundException) {
- warnTmpl = JGitText.get().packWasDeleted;
+ if (p.getPackFile().exists()) {
+ warnTmpl = JGitText.get().packInaccessible;
+ } else {
+ warnTmpl = JGitText.get().packWasDeleted;
+ }
removePack(p);
} else if (FileUtils.isStaleFileHandle(e)) {
warnTmpl = JGitText.get().packHandleIsStale;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
index c8c12f5b6c..69f7e97071 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
@@ -788,6 +788,9 @@ public class RefDirectory extends RefDatabase {
new DigestInputStream(new FileInputStream(packedRefsFile),
digest), CHARSET));
} catch (FileNotFoundException noPackedRefs) {
+ if (packedRefsFile.exists()) {
+ throw noPackedRefs;
+ }
// Ignore it and leave the new list empty.
return PackedRefList.NO_PACKED_REFS;
}
@@ -944,7 +947,10 @@ public class RefDirectory extends RefDatabase {
try {
buf = IO.readSome(path, limit);
} catch (FileNotFoundException noFile) {
- return null; // doesn't exist; not a reference.
+ if (path.exists() && path.isFile()) {
+ throw noFile;
+ }
+ return null; // doesn't exist or no file; not a reference.
}
int n = buf.length;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReaderImpl.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReaderImpl.java
index dadc631194..2f583b275a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReaderImpl.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReaderImpl.java
@@ -96,6 +96,9 @@ class ReflogReaderImpl implements ReflogReader {
try {
log = IO.readFully(logName);
} catch (FileNotFoundException e) {
+ if (logName.exists()) {
+ throw e;
+ }
return null;
}
@@ -118,6 +121,9 @@ class ReflogReaderImpl implements ReflogReader {
try {
log = IO.readFully(logName);
} catch (FileNotFoundException e) {
+ if (logName.exists()) {
+ throw e;
+ }
return Collections.emptyList();
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java
index 2cc2563962..a02743720d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java
@@ -399,6 +399,9 @@ public class UnpackedObject {
try {
in = buffer(new FileInputStream(path));
} catch (FileNotFoundException gone) {
+ if (path.exists()) {
+ throw gone;
+ }
// If the loose file no longer exists, it may have been
// moved into a pack file in the mean time. Try again
// to locate the object.
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
index eda02dea4e..8d512ccb24 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -1590,6 +1590,9 @@ public abstract class Repository implements AutoCloseable {
try {
return RawParseUtils.decode(IO.readFully(mergeMsgFile));
} catch (FileNotFoundException e) {
+ if (mergeMsgFile.exists()) {
+ throw e;
+ }
// the file has disappeared in the meantime ignore it
return null;
}
@@ -1621,6 +1624,9 @@ public abstract class Repository implements AutoCloseable {
byte[] raw = IO.readFully(file);
return raw.length > 0 ? raw : null;
} catch (FileNotFoundException notFound) {
+ if (file.exists()) {
+ throw notFound;
+ }
return null;
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java
index 5509fc6a70..29c7f98411 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java
@@ -163,6 +163,9 @@ public class FileBasedConfig extends StoredConfig {
hash = newHash;
}
} catch (FileNotFoundException noFile) {
+ if (configFile.exists()) {
+ throw noFile;
+ }
clear();
snapshot = newSnapshot;
} catch (IOException e) {