Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,15 @@ private FileAccessTree(
this.writePaths = pruneSortedPaths(writePaths).toArray(new String[0]);
}

private static List<String> pruneSortedPaths(List<String> paths) {
// package private for testing
static List<String> pruneSortedPaths(List<String> paths) {
List<String> prunedReadPaths = new ArrayList<>();
if (paths.isEmpty() == false) {
String currentPath = paths.get(0);
prunedReadPaths.add(currentPath);
for (int i = 1; i < paths.size(); ++i) {
String nextPath = paths.get(i);
if (isParent(currentPath, nextPath) == false) {
if (currentPath.equals(nextPath) == false && isParent(currentPath, nextPath) == false) {
prunedReadPaths.add(nextPath);
currentPath = nextPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ public void testInvalidExclusiveAccess() {
assertThat(tree.canWrite(path("a")), is(false));
}

public void testDuplicatePrunedPaths() {
List<String> paths = List.of("/a", "/a", "/a/b", "/a/b", "/b/c", "b/c/d", "b/c/d", "b/c/d", "e/f", "e/f");
paths = FileAccessTree.pruneSortedPaths(paths);
assertEquals(List.of("/a", "/b/c", "b/c/d", "e/f"), paths);
}

public void testWindowsAbsolutPathAccess() {
assumeTrue("Specific to windows for paths with a root (DOS or UNC)", Platform.WINDOWS.isCurrent());

Expand Down