Skip to content

Commit 8e39c7d

Browse files
author
Gary Gregory
committed
Refactor internals link options, no functional change.
1 parent a75b412 commit 8e39c7d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public static DeletingPathVisitor withLongCounters() {
5555

5656
private final String[] skip;
5757
private final boolean overrideReadOnly;
58+
private final LinkOption[] linkOptions;
5859

5960
/**
6061
* 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[]
7071
Arrays.sort(temp);
7172
this.skip = temp;
7273
this.overrideReadOnly = StandardDeleteOption.overrideReadOnly(deleteOption);
74+
// TODO Files.deleteIfExists() never follows links, so use LinkOption.NOFOLLOW_LINKS in other calls to Files.
75+
this.linkOptions = PathUtils.NOFOLLOW_LINK_OPTION_ARRAY.clone();
7376
}
7477

7578
/**
@@ -133,10 +136,9 @@ public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttribut
133136

134137
@Override
135138
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
136-
// Files.deleteIfExists() never follows links, so use LinkOption.NOFOLLOW_LINKS in other calls to Files.
137-
if (accept(file) && Files.exists(file, LinkOption.NOFOLLOW_LINKS)) {
139+
if (accept(file) && Files.exists(file, linkOptions)) {
138140
if (overrideReadOnly) {
139-
PathUtils.setReadOnly(file, false, LinkOption.NOFOLLOW_LINKS);
141+
PathUtils.setReadOnly(file, false, linkOptions);
140142
}
141143
Files.deleteIfExists(file);
142144
}

0 commit comments

Comments
 (0)