You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/12/06 19:09:51 UTC
[commons-io] 01/03: Refactor internals link options,
no functional change.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 8e39c7dbba317da4fb5606ead507fa8bcfd6372f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 6 12:51:35 2020 -0500
Refactor internals link options, no functional change.
---
src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java b/src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
index 371a465..6235b56 100644
--- a/src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
+++ b/src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
@@ -55,6 +55,7 @@ public class DeletingPathVisitor extends CountingPathVisitor {
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 class DeletingPathVisitor extends CountingPathVisitor {
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 class DeletingPathVisitor extends CountingPathVisitor {
@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);
}