Refactor internals link options, no functional change.
MODIFY
src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
@@ -55,6 +55,7 @@ public static DeletingPathVisitor withLongCounters() {
private final String[] skip;
private final boolean overrideReadOnly;
+ private final LinkOption[] linkOptions;
/**
* Constructs a new visitor that deletes files except for the files and directories explicitly given.
@@ -70,6 +71,8 @@ public DeletingPathVisitor(final PathCounters pathCounter, final DeleteOption[]
Arrays.sort(temp);
this.skip = temp;
this.overrideReadOnly = StandardDeleteOption.overrideReadOnly(deleteOption);
+ // TODO Files.deleteIfExists() never follows links, so use LinkOption.NOFOLLOW_LINKS in other calls to Files.
+ this.linkOptions = PathUtils.NOFOLLOW_LINK_OPTION_ARRAY.clone();
}
/**
@@ -133,10 +136,9 @@ public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttribut
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
- // Files.deleteIfExists() never follows links, so use LinkOption.NOFOLLOW_LINKS in other calls to Files.
- if (accept(file) && Files.exists(file, LinkOption.NOFOLLOW_LINKS)) {
+ if (accept(file) && Files.exists(file, linkOptions)) {
if (overrideReadOnly) {
- PathUtils.setReadOnly(file, false, LinkOption.NOFOLLOW_LINKS);
+ PathUtils.setReadOnly(file, false, linkOptions);
}
Files.deleteIfExists(file);
}

Refactor internals link options, no functional change.