Skip to content

Commit

Permalink
Add test for deleting symlinks in descendant files
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Sicker <[email protected]>
  • Loading branch information
jvz committed Jan 10, 2019
1 parent c05d00a commit 5dfef2b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions core/src/test/java/jenkins/util/io/PathRemoverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.spi.FileSystemProvider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -324,6 +325,27 @@ public void testForceRemoveRecursive_FailsWhenInterrupted() throws Exception {
assertNotNull(interrupted.get());
}

@Test
public void testForceRemoveRecursive_ContainsSymbolicLinks() throws IOException {
File folder = tmp.newFolder();
File d1 = new File(folder, "d1");
File d1f1 = new File(d1, "d1f1");
File f2 = new File(folder, "f2");
mkdirs(d1);
touchWithFileName(d1f1, f2);
Path path = tmp.newFolder().toPath();
Files.createSymbolicLink(path.resolve("sym-dir"), d1.toPath());
Files.createSymbolicLink(path.resolve("sym-file"), f2.toPath());

PathRemover remover = PathRemover.newSimpleRemover();
remover.forceRemoveRecursive(path);

assertTrue("Unable to delete directory: " + path, Files.notExists(path));
for (File file : Arrays.asList(d1, d1f1, f2)) {
assertTrue("Should not have deleted target: " + file, file.exists());
}
}

private static void mkdirs(File... dirs) {
for (File dir : dirs) {
assertTrue("Could not mkdir " + dir, dir.mkdir());
Expand Down

0 comments on commit 5dfef2b

Please sign in to comment.