]> source.dussan.org Git - jgit.git/commitdiff
[findbugs] Do not ignore exceptional return value of mkdir 04/2104/8
authorMatthias Sohn <matthias.sohn@sap.com>
Fri, 10 Dec 2010 20:58:05 +0000 (21:58 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Fri, 28 Jan 2011 00:11:12 +0000 (01:11 +0100)
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>
23 files changed:
org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IpLogMeta.java
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/eclipse/Iplog.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RepositorySetupWorkDirTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_BasicTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/UnpackedObjectTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java
org.eclipse.jgit/findBugs/FindBugsExcludeFilter.xml
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java

index 372469da0424b24eb44cca0b98ff4c4c591198e6..ba10f6f24ee8aa17248a65f3bc064de797829a4e 100644 (file)
@@ -62,6 +62,7 @@ import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.storage.file.FileBasedConfig;
 import org.eclipse.jgit.storage.file.LockFile;
 import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
 
 /**
  * Manages the {@code .eclipse_iplog} file in a project.
@@ -187,8 +188,7 @@ public class IpLogMeta {
         */
        public void syncCQs(File file, FS fs, URL base, String username,
                        String password) throws IOException, ConfigInvalidException {
-               if (!file.getParentFile().exists())
-                       file.getParentFile().mkdirs();
+               FileUtils.mkdirs(file.getParentFile(), true);
 
                LockFile lf = new LockFile(file, fs);
                if (!lf.lock())
index 3917c487d71de6c641da4c6f8de3173df98c173a..45c6c41f2cc5bc074d46db4bdc4f8eb1548adf84 100644 (file)
@@ -69,6 +69,7 @@ import org.eclipse.jgit.storage.file.FileRepository;
 import org.eclipse.jgit.storage.file.WindowCache;
 import org.eclipse.jgit.storage.file.WindowCacheConfig;
 import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
 import org.eclipse.jgit.util.IO;
 import org.eclipse.jgit.util.SystemReader;
 import org.junit.After;
@@ -389,7 +390,7 @@ public abstract class LocalDiskRepositoryTestCase {
         *             the file could not be written.
         */
        protected void write(final File f, final String body) throws IOException {
-               f.getParentFile().mkdirs();
+               FileUtils.mkdirs(f.getParentFile(), true);
                Writer w = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
                try {
                        w.write(body);
index 84859a805cdc06431ad0fc024c24e8e55e0246d3..86b93a0f84dbac5ba7a9ec85301cc40da512a705 100644 (file)
@@ -59,6 +59,7 @@ import org.eclipse.jgit.revwalk.RevObject;
 import org.eclipse.jgit.revwalk.RevTag;
 import org.eclipse.jgit.revwalk.RevWalk;
 import org.eclipse.jgit.storage.file.LockFile;
+import org.eclipse.jgit.util.FileUtils;
 import org.kohsuke.args4j.Argument;
 import org.kohsuke.args4j.Option;
 
@@ -96,8 +97,7 @@ class Iplog extends TextBuiltin {
                log.scan(db, rw.parseCommit(start), version);
 
                if (output != null) {
-                       if (!output.getParentFile().exists())
-                               output.getParentFile().mkdirs();
+                       FileUtils.mkdirs(output.getParentFile(), true);
                        LockFile lf = new LockFile(output, db.getFS());
                        if (!lf.lock())
                                throw die(MessageFormat.format(CLIText.get().cannotLock, output));
index 33f305d4873045c149427876983185c531d58415..61b099d61d5e5ae9e3a03ae4c8459fa5ed27f090 100644 (file)
@@ -90,7 +90,7 @@ public class AddCommandTest extends RepositoryTestCase {
        @Test
        public void testAddExistingSingleFile() throws IOException, NoFilepatternException {
                File file = new File(db.getWorkTree(), "a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
@@ -106,9 +106,9 @@ public class AddCommandTest extends RepositoryTestCase {
 
        @Test
        public void testAddExistingSingleFileInSubDir() throws IOException, NoFilepatternException {
-               new File(db.getWorkTree(), "sub").mkdir();
+               FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
                File file = new File(db.getWorkTree(), "sub/a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
@@ -125,7 +125,7 @@ public class AddCommandTest extends RepositoryTestCase {
        @Test
        public void testAddExistingSingleFileTwice() throws IOException, NoFilepatternException {
                File file = new File(db.getWorkTree(), "a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
@@ -149,7 +149,7 @@ public class AddCommandTest extends RepositoryTestCase {
        @Test
        public void testAddExistingSingleFileTwiceWithCommit() throws Exception {
                File file = new File(db.getWorkTree(), "a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
@@ -175,7 +175,7 @@ public class AddCommandTest extends RepositoryTestCase {
        @Test
        public void testAddRemovedFile() throws Exception {
                File file = new File(db.getWorkTree(), "a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
@@ -197,7 +197,7 @@ public class AddCommandTest extends RepositoryTestCase {
        @Test
        public void testAddRemovedCommittedFile() throws Exception {
                File file = new File(db.getWorkTree(), "a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
@@ -223,13 +223,13 @@ public class AddCommandTest extends RepositoryTestCase {
                // prepare conflict
 
                File file = new File(db.getWorkTree(), "a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
 
                File file2 = new File(db.getWorkTree(), "b.txt");
-               file2.createNewFile();
+               FileUtils.createNewFile(file2);
                writer = new PrintWriter(file2);
                writer.print("content b");
                writer.close();
@@ -275,13 +275,13 @@ public class AddCommandTest extends RepositoryTestCase {
        @Test
        public void testAddTwoFiles() throws Exception  {
                File file = new File(db.getWorkTree(), "a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
 
                File file2 = new File(db.getWorkTree(), "b.txt");
-               file2.createNewFile();
+               FileUtils.createNewFile(file2);
                writer = new PrintWriter(file2);
                writer.print("content b");
                writer.close();
@@ -296,15 +296,15 @@ public class AddCommandTest extends RepositoryTestCase {
 
        @Test
        public void testAddFolder() throws Exception  {
-               new File(db.getWorkTree(), "sub").mkdir();
+               FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
                File file = new File(db.getWorkTree(), "sub/a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
 
                File file2 = new File(db.getWorkTree(), "sub/b.txt");
-               file2.createNewFile();
+               FileUtils.createNewFile(file2);
                writer = new PrintWriter(file2);
                writer.print("content b");
                writer.close();
@@ -319,21 +319,21 @@ public class AddCommandTest extends RepositoryTestCase {
 
        @Test
        public void testAddIgnoredFile() throws Exception  {
-               new File(db.getWorkTree(), "sub").mkdir();
+               FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
                File file = new File(db.getWorkTree(), "sub/a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
 
                File ignoreFile = new File(db.getWorkTree(), ".gitignore");
-               ignoreFile.createNewFile();
+               FileUtils.createNewFile(ignoreFile);
                writer = new PrintWriter(ignoreFile);
                writer.print("sub/b.txt");
                writer.close();
 
                File file2 = new File(db.getWorkTree(), "sub/b.txt");
-               file2.createNewFile();
+               FileUtils.createNewFile(file2);
                writer = new PrintWriter(file2);
                writer.print("content b");
                writer.close();
@@ -348,15 +348,15 @@ public class AddCommandTest extends RepositoryTestCase {
 
        @Test
        public void testAddWholeRepo() throws Exception  {
-               new File(db.getWorkTree(), "sub").mkdir();
+               FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
                File file = new File(db.getWorkTree(), "sub/a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
 
                File file2 = new File(db.getWorkTree(), "sub/b.txt");
-               file2.createNewFile();
+               FileUtils.createNewFile(file2);
                writer = new PrintWriter(file2);
                writer.print("content b");
                writer.close();
@@ -375,15 +375,15 @@ public class AddCommandTest extends RepositoryTestCase {
        // file c exists in workdir but not in index -> added
        @Test
        public void testAddWithoutParameterUpdate() throws Exception {
-               new File(db.getWorkTree(), "sub").mkdir();
+               FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
                File file = new File(db.getWorkTree(), "sub/a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
 
                File file2 = new File(db.getWorkTree(), "sub/b.txt");
-               file2.createNewFile();
+               FileUtils.createNewFile(file2);
                writer = new PrintWriter(file2);
                writer.print("content b");
                writer.close();
@@ -400,7 +400,7 @@ public class AddCommandTest extends RepositoryTestCase {
 
                // new unstaged file sub/c.txt
                File file3 = new File(db.getWorkTree(), "sub/c.txt");
-               file3.createNewFile();
+               FileUtils.createNewFile(file3);
                writer = new PrintWriter(file3);
                writer.print("content c");
                writer.close();
@@ -429,15 +429,15 @@ public class AddCommandTest extends RepositoryTestCase {
        // file c exists in workdir but not in index -> unchanged
        @Test
        public void testAddWithParameterUpdate() throws Exception {
-               new File(db.getWorkTree(), "sub").mkdir();
+               FileUtils.mkdir(new File(db.getWorkTree(), "sub"));
                File file = new File(db.getWorkTree(), "sub/a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
 
                File file2 = new File(db.getWorkTree(), "sub/b.txt");
-               file2.createNewFile();
+               FileUtils.createNewFile(file2);
                writer = new PrintWriter(file2);
                writer.print("content b");
                writer.close();
@@ -454,7 +454,7 @@ public class AddCommandTest extends RepositoryTestCase {
 
                // new unstaged file sub/c.txt
                File file3 = new File(db.getWorkTree(), "sub/c.txt");
-               file3.createNewFile();
+               FileUtils.createNewFile(file3);
                writer = new PrintWriter(file3);
                writer.print("content c");
                writer.close();
index 67a9a1b3f3fef007eb3ae08e9dfcd3ac74095a0d..bc313e87e52f805da76432d068558f86fda7a857 100644 (file)
@@ -66,6 +66,7 @@ import org.eclipse.jgit.lib.RefUpdate;
 import org.eclipse.jgit.lib.RepositoryTestCase;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.util.FileUtils;
 
 public class CommitAndLogCommandTests extends RepositoryTestCase {
        public void testSomeCommits() throws NoHeadException, NoMessageException,
@@ -169,7 +170,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
                        JGitInternalException, WrongRepositoryStateException,
                        NoFilepatternException {
                File file = new File(db.getWorkTree(), "a.txt");
-               file.createNewFile();
+               FileUtils.createNewFile(file);
                PrintWriter writer = new PrintWriter(file);
                writer.print("content");
                writer.close();
index 755370c92dab01534dbd42600424c5fb671d955a..15aafc9060b7591659a094d3d1833ee000df02f8 100644 (file)
@@ -51,6 +51,7 @@ import java.io.IOException;
 
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.lib.RepositoryTestCase;
+import org.eclipse.jgit.util.FileUtils;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -93,16 +94,8 @@ public class InitCommandTest extends RepositoryTestCase {
        public static File createTempDirectory(String name) throws IOException {
                final File temp;
                temp = File.createTempFile(name, Long.toString(System.nanoTime()));
-
-               if (!(temp.delete())) {
-                       throw new IOException("Could not delete temp file: "
-                                       + temp.getAbsolutePath());
-               }
-
-               if (!(temp.mkdir())) {
-                       throw new IOException("Could not create temp directory: "
-                                       + temp.getAbsolutePath());
-               }
+               FileUtils.delete(temp);
+               FileUtils.mkdir(temp);
                return temp;
        }
 
index 80b853ee7c7a71ab3425f50963aa43494d31f616..c25ee4c04a9ea677dbcf4f5e27568cbad6a06d87 100644 (file)
@@ -53,6 +53,7 @@ import java.util.TreeSet;
 import org.eclipse.jgit.treewalk.FileTreeIterator;
 import org.eclipse.jgit.treewalk.FileTreeIteratorWithTimeControl;
 import org.eclipse.jgit.treewalk.NameConflictTreeWalk;
+import org.eclipse.jgit.util.FileUtils;
 
 public class RacyGitTests extends RepositoryTestCase {
        public void testIterator() throws IllegalStateException, IOException,
@@ -61,19 +62,19 @@ public class RacyGitTests extends RepositoryTestCase {
                File lastFile = null;
                for (int i = 0; i < 10; i++) {
                        lastFile = new File(db.getWorkTree(), "0." + i);
-                       lastFile.createNewFile();
+                       FileUtils.createNewFile(lastFile);
                        if (i == 5)
                                fsTick(lastFile);
                }
                modTimes.add(fsTick(lastFile));
                for (int i = 0; i < 10; i++) {
                        lastFile = new File(db.getWorkTree(), "1." + i);
-                       lastFile.createNewFile();
+                       FileUtils.createNewFile(lastFile);
                }
                modTimes.add(fsTick(lastFile));
                for (int i = 0; i < 10; i++) {
                        lastFile = new File(db.getWorkTree(), "2." + i);
-                       lastFile.createNewFile();
+                       FileUtils.createNewFile(lastFile);
                        if (i % 4 == 0)
                                fsTick(lastFile);
                }
index 2f989e32cf99a5a6cf5fe279c4e03f08d275e7b5..cfb526d63b0ebda681d9127f7a42f99aaba33d76 100644 (file)
@@ -68,6 +68,7 @@ import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectReader;
 import org.eclipse.jgit.revwalk.RevBlob;
 import org.eclipse.jgit.transport.PackedObjectInfo;
+import org.eclipse.jgit.util.FileUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -176,7 +177,7 @@ public class AbbreviationTest extends LocalDiskRepositoryTestCase {
                File packDir = new File(db.getObjectDatabase().getDirectory(), "pack");
                File idxFile = new File(packDir, packName + ".idx");
                File packFile = new File(packDir, packName + ".pack");
-               packDir.mkdir();
+               FileUtils.mkdir(packDir, true);
                OutputStream dst = new BufferedOutputStream(new FileOutputStream(
                                idxFile));
                try {
index 385c8531c421941c60001a86773a7868c8c565d6..80e0f1a920ea487e3fec5edccec50c0b63f7f856 100644 (file)
@@ -48,6 +48,7 @@ import static org.junit.Assert.assertEquals;
 import java.io.File;
 
 import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
+import org.eclipse.jgit.util.FileUtils;
 import org.junit.Test;
 
 public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
@@ -55,7 +56,7 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
        public void testShouldAutomagicallyDetectGitDirectory() throws Exception {
                FileRepository r = createWorkRepository();
                File d = new File(r.getDirectory(), "sub-dir");
-               d.mkdir();
+               FileUtils.mkdir(d);
 
                assertEquals(r.getDirectory(), new FileRepositoryBuilder()
                                .findGitDir(d).getGitDir());
index 99d99a5e5c75a9efe5d0131add14ed7ffa3ebc54..1781c3d62dcc5dc00462bc921303c4d592c1c545 100644 (file)
@@ -59,6 +59,7 @@ import org.eclipse.jgit.lib.ConfigConstants;
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
 import org.junit.Test;
 
 /**
@@ -182,12 +183,12 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
                }
        }
 
-       private File getFile(String... pathComponents) {
+       private File getFile(String... pathComponents) throws IOException {
                String rootPath = new File(new File("target"), "trash").getPath();
                for (String pathComponent : pathComponents)
                        rootPath = rootPath + File.separatorChar + pathComponent;
                File result = new File(rootPath);
-               result.mkdir();
+               FileUtils.mkdirs(result, true);
                return result;
        }
 
index 7f0436b83e6bf9c11833dbff3fdc5db6b59dff19..ec5c8848fd1805effd1ca654733875b9c4208d17 100644 (file)
@@ -81,6 +81,7 @@ import org.eclipse.jgit.lib.TreeFormatter;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.revwalk.RevTag;
 import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.util.FileUtils;
 import org.junit.Test;
 
 public class T0003_BasicTest extends SampleDataRepositoryTestCase {
@@ -202,7 +203,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
                        throws IOException {
                File repo1Parent = new File(trash.getParentFile(), "r1");
                File workdir = new File(trash.getParentFile(), "rw");
-               workdir.mkdir();
+               FileUtils.mkdir(workdir);
                FileRepository repo1initial = new FileRepository(new File(repo1Parent,
                                Constants.DOT_GIT));
                repo1initial.create();
@@ -231,7 +232,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
                        throws IOException {
                File repo1Parent = new File(trash.getParentFile(), "r1");
                File workdir = new File(trash.getParentFile(), "rw");
-               workdir.mkdir();
+               FileUtils.mkdir(workdir);
                FileRepository repo1initial = new FileRepository(new File(repo1Parent,
                                Constants.DOT_GIT));
                repo1initial.create();
index c6199c34232c8510a9f7bccee29ec67bf78bc95b..0e6881ef91abeee56caa06d56319a3971d9cd169 100644 (file)
@@ -71,6 +71,7 @@ import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectInserter;
 import org.eclipse.jgit.lib.ObjectLoader;
 import org.eclipse.jgit.lib.ObjectStream;
+import org.eclipse.jgit.util.FileUtils;
 import org.eclipse.jgit.util.IO;
 import org.junit.After;
 import org.junit.Before;
@@ -567,7 +568,7 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
 
        private void write(ObjectId id, byte[] data) throws IOException {
                File path = path(id);
-               path.getParentFile().mkdirs();
+               FileUtils.mkdirs(path.getParentFile());
                FileOutputStream out = new FileOutputStream(path);
                try {
                        out.write(data);
index 966cd98127323b4458c85d3d38bd6e1dba2f8eef..67123a44b308f490755d6e7d49897b554110689c 100644 (file)
@@ -54,6 +54,7 @@ import java.io.OutputStreamWriter;
 
 import org.eclipse.jgit.lib.RepositoryTestCase;
 import org.eclipse.jgit.transport.OpenSshConfig.Host;
+import org.eclipse.jgit.util.FileUtils;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -69,10 +70,10 @@ public class OpenSshConfigTest extends RepositoryTestCase {
                super.setUp();
 
                home = new File(trash, "home");
-               home.mkdir();
+               FileUtils.mkdir(home);
 
                configFile = new File(new File(home, ".ssh"), "config");
-               configFile.getParentFile().mkdir();
+               FileUtils.mkdir(configFile.getParentFile());
 
                System.setProperty("user.name", "jex_junit");
                osc = new OpenSshConfig(home, configFile);
index ad8917a9267a21bf2d8b371a4066435c3a819c76..0b12058c8810bbc24eaa8861f4d395de97d72456 100644 (file)
@@ -110,8 +110,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
        public void testEmptyIfRootIsEmpty() throws Exception {
                final File r = new File(trash, "not-existing-file");
                assertFalse(r.exists());
-               r.mkdir();
-               assertTrue(r.isDirectory());
+               FileUtils.mkdir(r);
 
                final FileTreeIterator fti = new FileTreeIterator(r, db.getFS(),
                                db.getConfig().get(WorkingTreeOptions.KEY));
index d81e686c14d1c42fc239500f9fdc680ec6f34804..08e755752b2dc42ffb70e3636b344f99a818c70a 100644 (file)
@@ -71,7 +71,7 @@ public class FileUtilTest {
        @Test
        public void testDeleteFile() throws IOException {
                File f = new File(trash, "test");
-               assertTrue(f.createNewFile());
+               FileUtils.createNewFile(f);
                FileUtils.delete(f);
                assertFalse(f.exists());
 
@@ -92,10 +92,10 @@ public class FileUtilTest {
        @Test
        public void testDeleteRecursive() throws IOException {
                File f1 = new File(trash, "test/test/a");
-               f1.mkdirs();
-               f1.createNewFile();
+               FileUtils.mkdirs(f1.getParentFile());
+               FileUtils.createNewFile(f1);
                File f2 = new File(trash, "test/test/b");
-               f2.createNewFile();
+               FileUtils.createNewFile(f2);
                File d = new File(trash, "test");
                FileUtils.delete(d, FileUtils.RECURSIVE);
                assertFalse(d.exists());
@@ -132,7 +132,7 @@ public class FileUtilTest {
 
                assertTrue(d.delete());
                File f = new File(trash, "test");
-               assertTrue(f.createNewFile());
+               FileUtils.createNewFile(f);
                try {
                        FileUtils.mkdir(d);
                        fail("creation of directory having same path as existing file must"
@@ -164,7 +164,7 @@ public class FileUtilTest {
 
                FileUtils.delete(root, FileUtils.RECURSIVE);
                File f = new File(trash, "test");
-               assertTrue(f.createNewFile());
+               FileUtils.createNewFile(f);
                try {
                        FileUtils.mkdirs(d);
                        fail("creation of directory having path conflicting with existing"
index 948308e778df14dd97311afdbd4c112f184342d2..073f3da9d562c785da0333eaea38d68a84f34bb1 100644 (file)
@@ -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>
index 36c06702a990136a5a50c5cd2356ed4d47e1a003..e5e6045920f2f24e9f1e85c5f12aa0363cc4f4b3 100644 (file)
@@ -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());
index 25acf16a35cc17bbfac06e5f36acabacca191b68..dbd05117fddf14ba49ac17bba78d355ae945a580 100644 (file)
@@ -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);
index 5e6e616e5173c3de161c693d1880893b93eb476d..0088a15e46e6c183140798d2fbbe1c07992df725 100644 (file)
@@ -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);
index 28b83b0f9e05096011361301a80caa84ca98ab5c..cedb59472eb6ef770c7d808bf6f99b9b937a8739 100644 (file)
@@ -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();
index 52aa7eeb9db104b3cd843ce34d9c7256e84f72bf..9e637ab4f1012f9a32b4009c38d6a2368bdde870 100644 (file)
@@ -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 {
index 021a91b6d81f1b6e2e94b494c246b645edb3ab56..745c18fdb06ecc49feb0528cb8ccf71d92f334cf 100644 (file)
@@ -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);
index 2af7ca3e6dfb40fd8f29ae2599512622466d1b5c..c8c7d0dd83f956b221619aeb5b40f3602eda2f8e 100644 (file)
@@ -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