summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorRobin Stocker <robin@nibor.org>2013-04-12 14:21:02 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2013-04-29 01:00:35 +0200
commit8bd1e86bb74da17f18272a7f2e8b6857c800a2cc (patch)
treecfbf7ea626f07d5dd55159e5d9d3f72f1f414738 /org.eclipse.jgit/src
parent46a3863f21dcb57f5bd5a4487855c14545f57d98 (diff)
downloadjgit-8bd1e86bb74da17f18272a7f2e8b6857c800a2cc.tar.gz
jgit-8bd1e86bb74da17f18272a7f2e8b6857c800a2cc.zip
Abort before delete in FileUtils.delete EMPTY_DIRECTORIES_ONLY|RECURSIVE
Depending on the order in which items are traversed for RECURSIVE, an empty directory may come first before detecting that there is a file and aborting. This fixes it by traversing files first. Bug: 405558 Change-Id: I638b7da58e33ffeb0fee172b96f4c823943d29e9 Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java
index 5fbbda7c50..c4fdd6fff9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java
@@ -49,6 +49,8 @@ import java.io.File;
import java.io.IOException;
import java.nio.channels.FileLock;
import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.jgit.internal.JGitText;
@@ -130,8 +132,20 @@ public class FileUtils {
if ((options & RECURSIVE) != 0 && f.isDirectory()) {
final File[] items = f.listFiles();
if (items != null) {
+ List<File> files = new ArrayList<File>();
+ List<File> dirs = new ArrayList<File>();
for (File c : items)
- delete(c, options);
+ if (c.isFile())
+ files.add(c);
+ else
+ dirs.add(c);
+ // Try to delete files first, otherwise options
+ // EMPTY_DIRECTORIES_ONLY|RECURSIVE will delete empty
+ // directories before aborting, depending on order.
+ for (File file : files)
+ delete(file, options);
+ for (File d : dirs)
+ delete(d, options);
}
}