From 8bd1e86bb74da17f18272a7f2e8b6857c800a2cc Mon Sep 17 00:00:00 2001 From: Robin Stocker Date: Fri, 12 Apr 2013 14:21:02 +0200 Subject: 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 Signed-off-by: Matthias Sohn --- .../src/org/eclipse/jgit/util/FileUtils.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'org.eclipse.jgit/src') 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 files = new ArrayList(); + List dirs = new ArrayList(); 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); } } -- cgit v1.2.3