Skip to content

Commit 4bdcc63

Browse files
committedMay 9, 2023
change deletion approach to fix permission issues
1 parent d17862b commit 4bdcc63

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed
 

‎common/src/test/java/com/synopsys/integration/common/test/util/finder/SimpleFileFinderTest.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
import java.nio.file.Files;
1212
import java.nio.file.Path;
1313
import java.util.Arrays;
14+
import java.util.Comparator;
1415
import java.util.List;
1516
import java.util.function.Predicate;
17+
import java.util.stream.Stream;
1618

17-
import org.apache.commons.io.FileUtils;
1819
import org.junit.jupiter.api.AfterEach;
1920
import org.junit.jupiter.api.BeforeEach;
2021
import org.junit.jupiter.api.Test;
@@ -35,8 +36,12 @@ public void setup() throws IOException {
3536
public void cleanup() throws IOException {
3637
try {
3738
Files.delete(initialDirectoryPath);
38-
} catch (DirectoryNotEmptyException e) {
39-
FileUtils.deleteDirectory(initialDirectoryPath.toFile());
39+
} catch (DirectoryNotEmptyException e) {
40+
try (Stream<Path> walk = Files.walk(initialDirectoryPath)) {
41+
walk.sorted(Comparator.reverseOrder())
42+
.map(Path::toFile)
43+
.forEach(File::delete);
44+
}
4045
}
4146
}
4247

‎detector/src/test/java/com/synopsys/integration/detector/finder/DirectoryFinderTest.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
import java.io.IOException;
99
import java.nio.file.Files;
1010
import java.nio.file.Path;
11+
import java.util.Comparator;
1112
import java.util.Optional;
1213
import java.util.Set;
1314
import java.util.function.Predicate;
15+
import java.util.stream.Stream;
1416

15-
import org.apache.commons.io.FileUtils;
1617
import org.apache.commons.lang3.SystemUtils;
1718
import org.jetbrains.annotations.NotNull;
1819
import org.junit.jupiter.api.AfterAll;
@@ -33,7 +34,13 @@ public static void setup() throws IOException {
3334

3435
@AfterAll
3536
public static void cleanup() throws IOException {
36-
FileUtils.deleteDirectory(initialDirectoryPath.toFile());
37+
if (Files.exists(initialDirectoryPath)) {
38+
try (Stream<Path> walk = Files.walk(initialDirectoryPath)) {
39+
walk.sorted(Comparator.reverseOrder())
40+
.map(Path::toFile)
41+
.forEach(File::delete);
42+
}
43+
}
3744
}
3845

3946
@Test
@@ -115,7 +122,11 @@ private void testSymLinks(boolean followSymLinks) throws IOException {
115122
assertEquals("regularDir", subDirContentsName);
116123
}
117124

118-
FileUtils.deleteDirectory(initialDirectory);
125+
try (Stream<Path> walk = Files.walk(initialDirectory.toPath())) {
126+
walk.sorted(Comparator.reverseOrder())
127+
.map(Path::toFile)
128+
.forEach(File::delete);
129+
}
119130
}
120131

121132
@NotNull

0 commit comments

Comments
 (0)
Please sign in to comment.