]> source.dussan.org Git - jgit.git/commitdiff
[findbugs] Do not ignore exceptional return value 55/2055/4
authorMatthias Sohn <matthias.sohn@sap.com>
Mon, 6 Dec 2010 23:58:19 +0000 (00:58 +0100)
committerShawn O. Pearce <spearce@spearce.org>
Wed, 8 Dec 2010 00:18:30 +0000 (16:18 -0800)
java.io.File.delete() reports failure as an exceptional
return value false. Fix the code which silently ignored
this exceptional return value. Also remove some duplicate
deletion helper methods.

Change-Id: I80ed20ca1f07a2bc6e779957a4ad0c713789c5be
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
22 files changed:
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ConcurrentRepackTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
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/Repository.java
org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackLock.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectoryRename.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/IndexPack.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java

index e74af8cf71a4a4a4f14f0173a7d79b2eabb39f5a..71446a0dceb10e4b6a6d385925532043ea7e35fc 100644 (file)
@@ -97,6 +97,7 @@ import org.eclipse.jgit.storage.file.PackIndex.MutableEntry;
 import org.eclipse.jgit.storage.pack.PackWriter;
 import org.eclipse.jgit.treewalk.TreeWalk;
 import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
+import org.eclipse.jgit.util.FileUtils;
 
 /**
  * Wrapper to make creating test data easier.
@@ -651,10 +652,10 @@ public class TestRepository<R extends Repository> {
                }
        }
 
-       private void prunePacked(ObjectDirectory odb) {
+       private void prunePacked(ObjectDirectory odb) throws IOException {
                for (PackFile p : odb.getPacks()) {
                        for (MutableEntry e : p)
-                               odb.fileFor(e.toObjectId()).delete();
+                               FileUtils.delete(odb.fileFor(e.toObjectId()));
                }
        }
 
index 4357f8b0c172fb1f414ce3299f078a05a82fdf5d..556fc12086c164c192e594a51e44b4b7b667ed6c 100644 (file)
@@ -57,6 +57,7 @@ import org.eclipse.jgit.lib.FileMode;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectInserter;
 import org.eclipse.jgit.lib.RepositoryTestCase;
+import org.eclipse.jgit.util.FileUtils;
 
 public class AddCommandTest extends RepositoryTestCase {
 
@@ -172,7 +173,7 @@ public class AddCommandTest extends RepositoryTestCase {
                DirCache dc = git.add().addFilepattern("a.txt").call();
 
                dc.getEntry(0).getObjectId();
-               file.delete();
+               FileUtils.delete(file);
 
                // is supposed to do nothing
                dc = git.add().addFilepattern("a.txt").call();
@@ -195,7 +196,7 @@ public class AddCommandTest extends RepositoryTestCase {
                git.commit().setMessage("commit a.txt").call();
 
                dc.getEntry(0).getObjectId();
-               file.delete();
+               FileUtils.delete(file);
 
                // is supposed to do nothing
                dc = git.add().addFilepattern("a.txt").call();
@@ -392,7 +393,7 @@ public class AddCommandTest extends RepositoryTestCase {
                writer.close();
 
                // file sub/b.txt is deleted
-               file2.delete();
+               FileUtils.delete(file2);
 
                git.add().addFilepattern("sub").call();
                // change in sub/a.txt is staged
@@ -444,7 +445,7 @@ public class AddCommandTest extends RepositoryTestCase {
                writer.print("modified content");
                writer.close();
 
-               file2.delete();
+               FileUtils.delete(file2);
 
                // change in sub/a.txt is staged
                // deletion of sub/b.txt is staged
index ea7820428f35c71fd497dfa9849ed8f19ed9edb4..f5b6bfb6409847ba648061a245732552ea9d0424 100644 (file)
@@ -51,6 +51,7 @@ import org.eclipse.jgit.lib.RepositoryTestCase;
 import org.eclipse.jgit.treewalk.FileTreeIterator;
 import org.eclipse.jgit.treewalk.TreeWalk;
 import org.eclipse.jgit.treewalk.WorkingTreeIterator;
+import org.eclipse.jgit.util.FileUtils;
 
 /**
  * Tests ignore node behavior on the local filesystem.
@@ -128,7 +129,7 @@ public class IgnoreNodeTest extends RepositoryTestCase {
                assertEntry(F, tracked, ".gitignore");
                assertEntry(F, tracked, "out");
 
-               new File(trash, "out").delete();
+               FileUtils.delete(new File(trash, "out"));
                writeTrashFile("out/foo", "");
 
                beginWalk();
index cb82389f6ab85d6bf04fa2399f80e3e95dea3ea4..b4732e2dc1d01462f78e75dad4f297729c9fc536 100644 (file)
@@ -200,7 +200,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
 
                // rule 11
                setupCase(headMap, null, idxMap);
-               new File(trash, "foo").delete();
+               assertTrue(new File(trash, "foo").delete());
                writeTrashFile("foo", "bar");
                db.getIndex().getMembers()[0].forceRecheck();
                go();
@@ -238,7 +238,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
 
                // rules 21
                setupCase(idxMap, mergeMap, idxMap);
-               new File(trash, "foo").delete();
+               assertTrue(new File(trash, "foo").delete());
                writeTrashFile("foo", "bar");
                db.getIndex().getMembers()[0].forceRecheck();
                go();
index 30cec127981b77ff02f021c2441cddb93510e2e9..2e850ce9fbecef3cf52f0f697f71eb1440e79a54 100644 (file)
@@ -62,6 +62,7 @@ import org.eclipse.jgit.dircache.DirCacheEntry;
 import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
 import org.eclipse.jgit.storage.file.FileRepository;
 import org.eclipse.jgit.treewalk.FileTreeIterator;
+import org.eclipse.jgit.util.FileUtils;
 
 /**
  * Base class for most JGit unit tests.
@@ -98,8 +99,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
 
        protected void deleteTrashFile(final String name) throws IOException {
                File path = new File(db.getWorkTree(), name);
-               if (!path.delete())
-                       throw new IOException("Could not delete file " + path.getPath());
+               FileUtils.delete(path);
        }
 
        protected static void checkFile(File f, final String checkData)
@@ -323,7 +323,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
                        }
                        return actTime;
                } finally {
-                       tmp.delete();
+                       FileUtils.delete(tmp);
                }
        }
 }
index 7608a51f2261fa58ce36089fd659abf99eee269b..66b02cb46a6be5ec05ea1e8dcf47c4e2d443dd4d 100644 (file)
@@ -64,6 +64,7 @@ import org.eclipse.jgit.lib.RepositoryTestCase;
 import org.eclipse.jgit.revwalk.RevObject;
 import org.eclipse.jgit.revwalk.RevWalk;
 import org.eclipse.jgit.storage.pack.PackWriter;
+import org.eclipse.jgit.util.FileUtils;
 
 public class ConcurrentRepackTest extends RepositoryTestCase {
        public void setUp() throws Exception {
@@ -236,10 +237,10 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
                touch(begin, files[0].getParentFile());
        }
 
-       private static void delete(final File[] list) {
+       private static void delete(final File[] list) throws IOException {
                final long begin = list[0].getParentFile().lastModified();
                for (final File f : list) {
-                       f.delete();
+                       FileUtils.delete(f);
                        assertFalse(f + " was removed", f.exists());
                }
                touch(begin, list[0].getParentFile());
index 838a56c13fd7e2285cd4a11fee63ad0b29c7f237..ae519f4eab5a190dae70e8b65e8ac1dea49bae6e 100644 (file)
@@ -51,6 +51,7 @@ import org.eclipse.jgit.lib.FileMode;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectReader;
 import org.eclipse.jgit.lib.RepositoryTestCase;
+import org.eclipse.jgit.util.FileUtils;
 import org.eclipse.jgit.util.RawParseUtils;
 
 public class FileTreeIteratorTest extends RepositoryTestCase {
@@ -170,7 +171,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
 
                // Verify it was cached by removing the file and getting it again.
                //
-               new File(trash, paths[0]).delete();
+               FileUtils.delete(new File(trash, paths[0]));
                assertEquals(expect, top.getEntryObjectId());
        }
 
index 78ddf870795240197e860479ecdb35a8b342b319..eaa96f578a85110c967048f4407e1182931d6ad9 100644 (file)
@@ -78,6 +78,7 @@ import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.lib.RefUpdate.Result;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.util.FileUtils;
 import org.eclipse.jgit.util.IO;
 import org.eclipse.jgit.util.RawParseUtils;
 
@@ -220,7 +221,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
                                        rup = repo.updateRef(Constants.HEAD);
                                        rup.link(headName);
                                }
-                               deleteRecursive(rebaseDir);
+                               FileUtils.delete(rebaseDir, FileUtils.RECURSIVE);
                                return new RebaseResult(Status.OK);
                        }
                        return new RebaseResult(Status.UP_TO_DATE);
@@ -482,7 +483,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
                                }
                        }
                        // cleanup the files
-                       deleteRecursive(rebaseDir);
+                       FileUtils.delete(rebaseDir, FileUtils.RECURSIVE);
                        return new RebaseResult(Status.ABORTED);
 
                } finally {
@@ -490,16 +491,6 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
                }
        }
 
-       private void deleteRecursive(File fileOrFolder) throws IOException {
-               File[] children = fileOrFolder.listFiles();
-               if (children != null) {
-                       for (File child : children)
-                               deleteRecursive(child);
-               }
-               if (!fileOrFolder.delete())
-                       throw new IOException("Could not delete " + fileOrFolder.getPath());
-       }
-
        private String readFile(File directory, String fileName) throws IOException {
                byte[] content = IO.readFully(new File(directory, fileName));
                // strip off the last LF
index e4d5b7698835ad58be7ef605f1c8670947d0894f..11003ff4f03e4cc587211e9a160d7b7508dffab1 100644 (file)
@@ -72,6 +72,7 @@ import org.eclipse.jgit.treewalk.WorkingTreeIterator;
 import org.eclipse.jgit.treewalk.WorkingTreeOptions;
 import org.eclipse.jgit.treewalk.filter.PathFilter;
 import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
 
 /**
  * This class handles checking out one or two trees merging with the index. This
@@ -784,7 +785,10 @@ public class DirCacheCheckout {
                }
                for (String r : removed) {
                        File file = new File(repo.getWorkTree(), r);
-                       file.delete();
+                       if (!file.delete())
+                               throw new CheckoutConflictException(
+                                               MessageFormat.format(JGitText.get().cannotDeleteFile,
+                                                               file.getAbsolutePath()));
                        removeEmptyParents(file);
                }
        }
@@ -854,7 +858,7 @@ public class DirCacheCheckout {
                if (!tmpFile.renameTo(f)) {
                        // tried to rename which failed. Let' delete the target file and try
                        // again
-                       f.delete();
+                       FileUtils.delete(f);
                        if (!tmpFile.renameTo(f)) {
                                throw new IOException(MessageFormat.format(
                                                JGitText.get().couldNotWriteFile, tmpFile.getPath(),
index 8ba6ba5b99e06ac3656ae5a1cb5faa99c38acdcc..70646f16d2be8b2db3f5b1d85d340fccbc3dad5b 100644 (file)
@@ -79,6 +79,7 @@ import org.eclipse.jgit.revwalk.RevWalk;
 import org.eclipse.jgit.storage.file.ReflogReader;
 import org.eclipse.jgit.treewalk.TreeWalk;
 import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
 import org.eclipse.jgit.util.IO;
 import org.eclipse.jgit.util.RawParseUtils;
 
@@ -1186,7 +1187,7 @@ public abstract class Repository {
                                fos.close();
                        }
                } else {
-                       mergeMsgFile.delete();
+                       FileUtils.delete(mergeMsgFile);
                }
        }
 
@@ -1252,7 +1253,7 @@ public abstract class Repository {
                                bos.close();
                        }
                } else {
-                       mergeHeadFile.delete();
+                       FileUtils.delete(mergeHeadFile);
                }
        }
 }
index aea84a1e2aaad7d4839ed548306101016bd03679..135597f65929534110a6dc72c6005669df513a32 100644 (file)
@@ -83,6 +83,7 @@ import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.treewalk.CanonicalTreeParser;
 import org.eclipse.jgit.treewalk.NameConflictTreeWalk;
 import org.eclipse.jgit.treewalk.WorkingTreeIterator;
+import org.eclipse.jgit.util.FileUtils;
 
 /**
  * A three-way merger performing a content-merge if necessary
@@ -261,7 +262,7 @@ public class ResolveMerger extends ThreeWayMerger {
                                p = p.getParentFile();
                        if (p == null || p.isDirectory())
                                throw new IOException(JGitText.get().cannotCreateDirectory);
-                       p.delete();
+                       FileUtils.delete(p);
                        if (!f.mkdirs())
                                throw new IOException(JGitText.get().cannotCreateDirectory);
                }
@@ -530,7 +531,7 @@ public class ResolveMerger extends ThreeWayMerger {
                        } finally {
                                is.close();
                                if (inCore)
-                                       of.delete();
+                                       FileUtils.delete(of);
                        }
                        builder.add(dce);
                        return true;
index 9e137be8ba05b88788677076e2cfb9330126ae90..0f7f7b8d929c8def37dbee0f85fcbc3310daf468 100644 (file)
@@ -216,7 +216,7 @@ class CachedObjectDirectory extends FileObjectDatabase {
 
        @Override
        InsertLooseObjectResult insertUnpackedObject(File tmp, ObjectId objectId,
-                       boolean createDuplicate) {
+                       boolean createDuplicate) throws IOException {
                InsertLooseObjectResult result = wrapped.insertUnpackedObject(tmp,
                                objectId, createDuplicate);
                switch (result) {
index 4e9f5e9823228d537cdc55ae48b3a09c0edebcc3..418c3c0ada9645738c2a4a4947c49b6c3b1dadc4 100644 (file)
@@ -276,7 +276,7 @@ abstract class FileObjectDatabase extends ObjectDatabase {
                        AnyObjectId objectId) throws IOException;
 
        abstract InsertLooseObjectResult insertUnpackedObject(File tmp,
-                       ObjectId id, boolean createDuplicate);
+                       ObjectId id, boolean createDuplicate) throws IOException;
 
        abstract FileObjectDatabase newCachedFileObjectDatabase();
 
index 36d160ce64d5dd4f41b6a5e2a020d455ccd1206c..a145e7725cceeea46e216c0b57149008372a0ffa 100644 (file)
@@ -66,6 +66,7 @@ import org.eclipse.jgit.lib.RefUpdate;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.storage.file.FileObjectDatabase.AlternateHandle;
 import org.eclipse.jgit.storage.file.FileObjectDatabase.AlternateRepository;
+import org.eclipse.jgit.util.FileUtils;
 import org.eclipse.jgit.util.SystemReader;
 
 /**
@@ -240,7 +241,7 @@ public class FileRepository extends Repository {
 
                        getFS().setExecute(tmp, false);
                        final boolean off = getFS().canExecute(tmp);
-                       tmp.delete();
+                       FileUtils.delete(tmp);
 
                        fileMode = on && !off;
                } else {
index 77d2a3fc50a5532f4c541f1831c096e185e93312..c61c773fd62c95e79932918a723dd03c03dad3cd 100644 (file)
@@ -75,6 +75,7 @@ import org.eclipse.jgit.lib.RepositoryCache.FileKey;
 import org.eclipse.jgit.storage.pack.ObjectToPack;
 import org.eclipse.jgit.storage.pack.PackWriter;
 import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
 
 /**
  * Traditional file system based {@link ObjectDatabase}.
@@ -454,15 +455,15 @@ public class ObjectDirectory extends FileObjectDatabase {
 
        @Override
        InsertLooseObjectResult insertUnpackedObject(File tmp, ObjectId id,
-                       boolean createDuplicate) {
+                       boolean createDuplicate) throws IOException {
                // If the object is already in the repository, remove temporary file.
                //
                if (unpackedObjectCache.isUnpacked(id)) {
-                       tmp.delete();
+                       FileUtils.delete(tmp);
                        return InsertLooseObjectResult.EXISTS_LOOSE;
                }
                if (!createDuplicate && has(id)) {
-                       tmp.delete();
+                       FileUtils.delete(tmp);
                        return InsertLooseObjectResult.EXISTS_PACKED;
                }
 
@@ -474,7 +475,7 @@ public class ObjectDirectory extends FileObjectDatabase {
                        // that already exists. We can't be sure renameTo() would
                        // fail on all platforms if dst exists, so we check first.
                        //
-                       tmp.delete();
+                       FileUtils.delete(tmp);
                        return InsertLooseObjectResult.EXISTS_LOOSE;
                }
                if (tmp.renameTo(dst)) {
@@ -493,7 +494,7 @@ public class ObjectDirectory extends FileObjectDatabase {
                }
 
                if (!createDuplicate && has(id)) {
-                       tmp.delete();
+                       FileUtils.delete(tmp);
                        return InsertLooseObjectResult.EXISTS_PACKED;
                }
 
@@ -502,7 +503,7 @@ public class ObjectDirectory extends FileObjectDatabase {
                // either. We really don't know what went wrong, so
                // fail.
                //
-               tmp.delete();
+               FileUtils.delete(tmp);
                return InsertLooseObjectResult.FAILURE;
        }
 
index d922bebe8fd989b9fef9d6d8bd4cd7bc5563566a..5569ff5a78164839dd2ebeb69b696f9a2d593ffa 100644 (file)
@@ -63,6 +63,7 @@ import org.eclipse.jgit.lib.Config;
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectInserter;
+import org.eclipse.jgit.util.FileUtils;
 
 /** Creates loose objects in a {@link ObjectDirectory}. */
 class ObjectDirectoryInserter extends ObjectInserter {
@@ -150,7 +151,7 @@ class ObjectDirectoryInserter extends ObjectInserter {
                        return tmp;
                } finally {
                        if (delete)
-                               tmp.delete();
+                               FileUtils.delete(tmp);
                }
        }
 
index dd08dfbac2df26e36c863f6203215f8d99a7aaed..a6e0a5a0537b98c6c294bb92d0eb48263ba00954 100644 (file)
@@ -48,6 +48,7 @@ import java.io.IOException;
 
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
 
 /** Keeps track of a {@link PackFile}'s associated <code>.keep</code> file. */
 public class PackLock {
@@ -90,8 +91,13 @@ public class PackLock {
                return lf.commit();
        }
 
-       /** Remove the <code>.keep</code> file that holds this pack in place. */
-       public void unlock() {
-               keepFile.delete();
+       /**
+        * Remove the <code>.keep</code> file that holds this pack in place.
+        *
+        * @throws IOException
+        *             if deletion of .keep file failed
+        */
+       public void unlock() throws IOException {
+               FileUtils.delete(keepFile);
        }
 }
index 4f3efe343eff0c0afc63a1311f67321db842166f..4fb225e08f2e77371081a9df72028aaeae54e4a6 100644 (file)
@@ -53,6 +53,7 @@ import org.eclipse.jgit.lib.RefRename;
 import org.eclipse.jgit.lib.RefUpdate;
 import org.eclipse.jgit.lib.RefUpdate.Result;
 import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.util.FileUtils;
 
 /**
  * Rename any reference stored by {@link RefDirectory}.
@@ -175,7 +176,7 @@ class RefDirectoryRename extends RefRename {
                        try {
                                refdb.delete(tmp);
                        } catch (IOException err) {
-                               refdb.fileFor(tmp.getName()).delete();
+                               FileUtils.delete(refdb.fileFor(tmp.getName()));
                        }
                        rw.release();
                }
index f747616749ea36cf0e4ad5816efae329f92a3dee..db08b0608ed743ccdeb45808a7866b163ead07e1 100644 (file)
@@ -110,8 +110,12 @@ class FetchProcess {
                try {
                        executeImp(monitor, result);
                } finally {
+                       try {
                        for (final PackLock lock : packLocks)
                                lock.unlock();
+                       } catch (IOException e) {
+                               throw new TransportException(e.getMessage(), e);
+                       }
                }
        }
 
index 716416a367496a75d14538ba5df2fffa9f945dbf..cb652ecd50f0775858dcaf60b6267f6d2d13a173 100644 (file)
@@ -80,6 +80,7 @@ import org.eclipse.jgit.lib.ObjectReader;
 import org.eclipse.jgit.storage.file.PackIndexWriter;
 import org.eclipse.jgit.storage.file.PackLock;
 import org.eclipse.jgit.storage.pack.BinaryDelta;
+import org.eclipse.jgit.util.FileUtils;
 import org.eclipse.jgit.util.NB;
 
 /** Indexes Git pack files for local use. */
@@ -459,9 +460,9 @@ public class IndexPack {
                        }
                } catch (IOException err) {
                        if (dstPack != null)
-                               dstPack.delete();
+                               FileUtils.delete(dstPack);
                        if (dstIdx != null)
-                               dstIdx.delete();
+                               FileUtils.delete(dstIdx);
                        throw err;
                }
        }
@@ -1144,8 +1145,8 @@ public class IndexPack {
                        repo.openPack(finalPack, finalIdx);
                } catch (IOException err) {
                        keep.unlock();
-                       finalPack.delete();
-                       finalIdx.delete();
+                       FileUtils.delete(finalPack);
+                       FileUtils.delete(finalIdx);
                        throw err;
                }
 
index 4cc9ea58b474669e28ccea9b6f909573ed3399b7..0b98f6c4a48ed8421307bd09fbb0bdac99e01082 100644 (file)
@@ -669,7 +669,7 @@ public class ReceivePack {
                }
        }
 
-       private void unlockPack() {
+       private void unlockPack() throws IOException {
                if (packLock != null) {
                        packLock.unlock();
                        packLock = null;
index a669ac5cec7b553c596a84ddcbc00a91de8a47ab..e789e6dcb64339e5d308619ea4d8ca7fdcab59b2 100644 (file)
@@ -87,6 +87,7 @@ import org.eclipse.jgit.storage.file.PackIndex;
 import org.eclipse.jgit.storage.file.PackLock;
 import org.eclipse.jgit.storage.file.UnpackedObject;
 import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.util.FileUtils;
 
 /**
  * Generic fetch support for dumb transport protocols.
@@ -540,8 +541,12 @@ class WalkFetchConnection extends BaseFetchConnection {
                                // it failed the index and pack are unusable and we
                                // shouldn't consult them again.
                                //
-                               if (pack.tmpIdx != null)
-                                       pack.tmpIdx.delete();
+                               try {
+                                       if (pack.tmpIdx != null)
+                                               FileUtils.delete(pack.tmpIdx);
+                               } catch (IOException e) {
+                                       throw new TransportException(e.getMessage(), e);
+                               }
                                packItr.remove();
                        }
 
@@ -830,7 +835,7 @@ class WalkFetchConnection extends BaseFetchConnection {
                                        fos.close();
                                }
                        } catch (IOException err) {
-                               tmpIdx.delete();
+                               FileUtils.delete(tmpIdx);
                                throw err;
                        } finally {
                                s.in.close();
@@ -838,14 +843,14 @@ class WalkFetchConnection extends BaseFetchConnection {
                        pm.endTask();
 
                        if (pm.isCancelled()) {
-                               tmpIdx.delete();
+                               FileUtils.delete(tmpIdx);
                                return;
                        }
 
                        try {
                                index = PackIndex.open(tmpIdx);
                        } catch (IOException e) {
-                               tmpIdx.delete();
+                               FileUtils.delete(tmpIdx);
                                throw e;
                        }
                }