diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2010-12-10 21:58:05 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2011-01-28 01:11:12 +0100 |
commit | 38eec8f4a26935ba9e75bfbdde8a5682e05f338d (patch) | |
tree | e609e5e005fed86ef245b1646010312eaa0a3a61 /org.eclipse.jgit | |
parent | f5fe2dca3cb9f57891e1a4b18832fcc158d0c490 (diff) | |
download | jgit-38eec8f4a26935ba9e75bfbdde8a5682e05f338d.tar.gz jgit-38eec8f4a26935ba9e75bfbdde8a5682e05f338d.zip |
[findbugs] Do not ignore exceptional return value of mkdir
java.io.File.mkdir() and mkdirs() report failure as an exceptional
return value false. Fix the code which silently ignored this
exceptional return value.
Change-Id: I41244f4b9d66176e68e2c07e2329cf08492f8619
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
8 files changed, 30 insertions, 17 deletions
diff --git a/org.eclipse.jgit/findBugs/FindBugsExcludeFilter.xml b/org.eclipse.jgit/findBugs/FindBugsExcludeFilter.xml index 948308e778..073f3da9d5 100644 --- a/org.eclipse.jgit/findBugs/FindBugsExcludeFilter.xml +++ b/org.eclipse.jgit/findBugs/FindBugsExcludeFilter.xml @@ -9,6 +9,13 @@ <Bug pattern="DM_GC" /> </Match> + <!-- Silence ignoring return value of mkdirs --> + <Match> + <Class name="org.eclipse.jgit.dircache.DirCacheCheckout" /> + <Method name="checkout" /> + <Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" /> + </Match> + <!-- Silence the construction of our magic String instance. --> <Match> 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 36c06702a9..e5e6045920 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -509,7 +509,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> { Collections.reverse(cherryPickList); // create the folder for the meta information - rebaseDir.mkdir(); + FileUtils.mkdir(rebaseDir); createFile(repo.getDirectory(), Constants.ORIG_HEAD, headId.name()); createFile(rebaseDir, REBASE_HEAD, headId.name()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java index 25acf16a35..dbd05117fd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java @@ -419,7 +419,9 @@ public class DirCacheCheckout { for (String path : updated.keySet()) { // ... create/overwrite this file ... file = new File(repo.getWorkTree(), path); - file.getParentFile().mkdirs(); + if (!file.getParentFile().mkdirs()) { + // ignore + } file.createNewFile(); DirCacheEntry entry = dc.getEntry(path); checkoutEntry(repo, file, entry); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java index 5e6e616e51..0088a15e46 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java @@ -72,6 +72,7 @@ import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.events.IndexChangedEvent; +import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.RawParseUtils; /** @@ -937,7 +938,7 @@ public class GitIndex { ObjectLoader ol = db.open(e.sha1, Constants.OBJ_BLOB); File file = new File(wd, e.getName()); file.delete(); - file.getParentFile().mkdirs(); + FileUtils.mkdirs(file.getParentFile(), true); FileOutputStream dst = new FileOutputStream(file); try { ol.copyTo(dst); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java index 28b83b0f9e..cedb59472e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java @@ -239,11 +239,11 @@ public class FileRepository extends Repository { throw new IllegalStateException(MessageFormat.format( JGitText.get().repositoryAlreadyExists, getDirectory())); } - getDirectory().mkdirs(); + FileUtils.mkdirs(getDirectory(), true); refs.create(); objectDatabase.create(); - new File(getDirectory(), "branches").mkdir(); + FileUtils.mkdir(new File(getDirectory(), "branches")); RefUpdate head = updateRef(Constants.HEAD); head.disableRefLog(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java index 52aa7eeb9d..9e637ab4f1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java @@ -60,6 +60,7 @@ import org.eclipse.jgit.JGitText; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.util.FS; +import org.eclipse.jgit.util.FileUtils; /** * Git style file locking and replacement. @@ -122,7 +123,7 @@ public class LockFile { * does not hold the lock. */ public boolean lock() throws IOException { - lck.getParentFile().mkdirs(); + FileUtils.mkdirs(lck.getParentFile(), true); if (lck.createNewFile()) { haveLck = true; try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java index 021a91b6d8..745c18fdb0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java @@ -171,9 +171,9 @@ public class ObjectDirectory extends FileObjectDatabase { @Override public void create() throws IOException { - objects.mkdirs(); - infoDirectory.mkdir(); - packDirectory.mkdir(); + FileUtils.mkdirs(objects); + FileUtils.mkdir(infoDirectory); + FileUtils.mkdir(packDirectory); } @Override @@ -491,7 +491,7 @@ public class ObjectDirectory extends FileObjectDatabase { // directories are always lazily created. Note that we // try the rename first as the directory likely does exist. // - dst.getParentFile().mkdir(); + FileUtils.mkdir(dst.getParentFile()); if (tmp.renameTo(dst)) { dst.setReadOnly(); unpackedObjectCache.add(id); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java index 2af7ca3e6d..c8c7d0dd83 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java @@ -97,6 +97,7 @@ import org.eclipse.jgit.revwalk.RevObject; import org.eclipse.jgit.revwalk.RevTag; import org.eclipse.jgit.revwalk.RevWalk; 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.eclipse.jgit.util.RefList; @@ -190,13 +191,14 @@ public class RefDirectory extends RefDatabase { } public void create() throws IOException { - refsDir.mkdir(); - logsDir.mkdir(); - logsRefsDir.mkdir(); - - new File(refsDir, R_HEADS.substring(R_REFS.length())).mkdir(); - new File(refsDir, R_TAGS.substring(R_REFS.length())).mkdir(); - new File(logsRefsDir, R_HEADS.substring(R_REFS.length())).mkdir(); + FileUtils.mkdir(refsDir); + FileUtils.mkdir(logsDir); + FileUtils.mkdir(logsRefsDir); + + FileUtils.mkdir(new File(refsDir, R_HEADS.substring(R_REFS.length()))); + FileUtils.mkdir(new File(refsDir, R_TAGS.substring(R_REFS.length()))); + FileUtils.mkdir(new File(logsRefsDir, + R_HEADS.substring(R_REFS.length()))); } @Override |