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 2022/02/06 21:55:33 UTC
[commons-io] branch master updated: [IO-758] Deprecate PathUtils.NOFOLLOW_LINK_OPTION_ARRAY in favor of noFollowLinkOptionArray().
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
The following commit(s) were added to refs/heads/master by this push:
new 359b143 [IO-758] Deprecate PathUtils.NOFOLLOW_LINK_OPTION_ARRAY in favor of noFollowLinkOptionArray().
359b143 is described below
commit 359b1430396e98b9b29e309e1cba9edc77e64860
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 6 16:55:31 2022 -0500
[IO-758] Deprecate PathUtils.NOFOLLOW_LINK_OPTION_ARRAY in favor of
noFollowLinkOptionArray().
---
src/changes/changes.xml | 3 ++
.../commons/io/file/DeletingPathVisitor.java | 4 +--
.../java/org/apache/commons/io/file/PathUtils.java | 35 ++++++++++++++--------
3 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8534971..b004d78 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -147,6 +147,9 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="IO-484" dev="ggregory" type="fix" due-to="David Huang, Gary Gregory">
IOCase.isCaseSensitive(IOCase) result is backward #325.
</action>
+ <action issue="IO-758" dev="ggregory" type="fix" due-to="Marcono1234, Gary Gregory">
+ Deprecate PathUtils.NOFOLLOW_LINK_OPTION_ARRAY in favor of noFollowLinkOptionArray().
+ </action>
<!-- ADD -->
<action issue="IO-726" dev="ggregory" type="fix" due-to="shollander, Gary Gregory">
Add MemoryMappedFileInputStream #215.
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 793d2e1..08c6571 100644
--- a/src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
+++ b/src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
@@ -67,7 +67,7 @@ public class DeletingPathVisitor extends CountingPathVisitor {
* @since 2.8.0
*/
public DeletingPathVisitor(final PathCounters pathCounter, final DeleteOption[] deleteOption, final String... skip) {
- this(pathCounter, PathUtils.NOFOLLOW_LINK_OPTION_ARRAY, deleteOption, skip);
+ this(pathCounter, PathUtils.noFollowLinkOptionArray(), deleteOption, skip);
}
/**
@@ -86,7 +86,7 @@ public class DeletingPathVisitor extends CountingPathVisitor {
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 = linkOptions == null ? PathUtils.NOFOLLOW_LINK_OPTION_ARRAY : linkOptions.clone();
+ this.linkOptions = linkOptions == null ? PathUtils.noFollowLinkOptionArray() : linkOptions.clone();
}
/**
diff --git a/src/main/java/org/apache/commons/io/file/PathUtils.java b/src/main/java/org/apache/commons/io/file/PathUtils.java
index a88781a..a1cb92d 100644
--- a/src/main/java/org/apache/commons/io/file/PathUtils.java
+++ b/src/main/java/org/apache/commons/io/file/PathUtils.java
@@ -175,7 +175,9 @@ public final class PathUtils {
* {@link LinkOption} array for {@link LinkOption#NOFOLLOW_LINKS}.
*
* @since 2.9.0
+ * @deprecated Use {@link #noFollowLinkOptionArray()}.
*/
+ @Deprecated
public static final LinkOption[] NOFOLLOW_LINK_OPTION_ARRAY = {LinkOption.NOFOLLOW_LINKS};
/**
@@ -198,6 +200,13 @@ public final class PathUtils {
public static final Path[] EMPTY_PATH_ARRAY = {};
/**
+ * Does allow to instantiate.
+ */
+ private PathUtils() {
+ // do not instantiate.
+ }
+
+ /**
* Accumulates file tree information in a {@link AccumulatorPathVisitor}.
*
* @param directory The directory to accumulate information.
@@ -363,10 +372,6 @@ public final class PathUtils {
return parent == null ? null : Files.createDirectories(parent, attrs);
}
- private static Path readIfSymbolicLink(final Path path) throws IOException {
- return Files.isSymbolicLink(path) ? Files.readSymbolicLink(path) : path;
- }
-
/**
* Gets the current directory.
*
@@ -463,7 +468,7 @@ public final class PathUtils {
* @since 2.8.0
*/
public static PathCounters deleteDirectory(final Path directory, final DeleteOption... deleteOptions) throws IOException {
- final LinkOption[] linkOptions = PathUtils.NOFOLLOW_LINK_OPTION_ARRAY;
+ final LinkOption[] linkOptions = PathUtils.noFollowLinkOptionArray();
// POSIX ops will noop on non-POSIX.
return withPosixFileAttributes(getParent(directory), linkOptions, overrideReadOnly(deleteOptions),
pfa -> visitFileTree(new DeletingPathVisitor(Counters.longPathCounters(), linkOptions, deleteOptions), directory).getPathCounters());
@@ -507,7 +512,7 @@ public final class PathUtils {
*/
public static PathCounters deleteFile(final Path file, final DeleteOption... deleteOptions) throws IOException {
// Files.deleteIfExists() never follows links, so use LinkOption.NOFOLLOW_LINKS in other calls to Files.
- return deleteFile(file, NOFOLLOW_LINK_OPTION_ARRAY, deleteOptions);
+ return deleteFile(file, noFollowLinkOptionArray(), deleteOptions);
}
/**
@@ -1104,6 +1109,13 @@ public final class PathUtils {
return Files.newOutputStream(path, list.toArray(EMPTY_OPEN_OPTION_ARRAY));
}
+ /**
+ * @return the nofollowLinkOptionArray
+ */
+ public static LinkOption[] noFollowLinkOptionArray() {
+ return NOFOLLOW_LINK_OPTION_ARRAY.clone();
+ }
+
private static boolean notExists(final Path path, final LinkOption... options) {
return Files.notExists(Objects.requireNonNull(path, "path"), options);
}
@@ -1199,6 +1211,10 @@ public final class PathUtils {
return readAttributes(path, DosFileAttributes.class, options);
}
+ private static Path readIfSymbolicLink(final Path path) throws IOException {
+ return Files.isSymbolicLink(path) ? Files.readSymbolicLink(path) : path;
+ }
+
/**
* Reads the PosixFileAttributes or DosFileAttributes from the given path. Returns null instead of throwing
* {@link UnsupportedOperationException}.
@@ -1687,11 +1703,4 @@ public final class PathUtils {
return path;
}
- /**
- * Does allow to instantiate.
- */
- private PathUtils() {
- // do not instantiate.
- }
-
}