diff --git a/src/main/java/forge/view/FView.java b/src/main/java/forge/view/FView.java index 828c78637a5..164ff5c1bd5 100644 --- a/src/main/java/forge/view/FView.java +++ b/src/main/java/forge/view/FView.java @@ -219,16 +219,29 @@ public enum FView { // will populate remainingFiles with remaining files if not null, returns whether any files have // been added to remainingFiles (or would have been added if remainingFiles is null) // directories listed in profileDirs will not be searched + // removes empty directories to reduce tree conflicts private static boolean _addRemainingFiles(List remainingFiles, List dirRoots, Set profileDirs) { Deque stack = new LinkedList(dirRoots); + Set seenDirs = new HashSet(); boolean ret = false; while (!stack.isEmpty()) { - File cur = stack.pop(); + File cur = stack.peek(); if (profileDirs.contains(cur)) { - // don't search active profile dirs + // don't touch active profile dirs + stack.pop(); continue; } + if (seenDirs.contains(cur)) { + cur = stack.pop(); + if (cur.exists()) { + // remove empty dir (will fail if not empty) + cur.delete(); + } + continue; + } + + seenDirs.add(cur); File[] curListing = cur.listFiles(); if (null == curListing) { continue;