Deprecate PathUtils.NOFOLLOW_LINK_OPTION_ARRAY in favor of
noFollowLinkOptionArray().
MODIFY
src/changes/changes.xml
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.

MODIFY
src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
@@ -67,7 +67,7 @@ public static DeletingPathVisitor withLongCounters() {
* @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 DeletingPathVisitor(final PathCounters pathCounter, final LinkOption[] li
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();
}
/**

MODIFY
src/main/java/org/apache/commons/io/file/PathUtils.java
src/main/java/org/apache/commons/io/file/PathUtils.java
@@ -175,7 +175,9 @@ private RelativeSortedPaths(final Path dir1, final Path dir2, final int maxDepth
* {@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};
/**
@@ -197,6 +199,13 @@ private RelativeSortedPaths(final Path dir1, final Path dir2, final int maxDepth
*/
public static final Path[] EMPTY_PATH_ARRAY = {};
+ /**
+ * Does allow to instantiate.
+ */
+ private PathUtils() {
+ // do not instantiate.
+ }
+
/**
* Accumulates file tree information in a {@link AccumulatorPathVisitor}.
*
@@ -363,10 +372,6 @@ public static Path createParentDirectories(final Path path, final LinkOption lin
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 static PathCounters deleteDirectory(final Path directory) throws IOExcept
* @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 static PathCounters deleteFile(final Path file) throws IOException {
*/
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 @@ static OutputStream newOutputStream(final Path path, final LinkOption[] linkOpti
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 static DosFileAttributes readDosFileAttributes(final Path path, final Lin
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 static Path writeString(final Path path, final CharSequence charSequence,
return path;
}
- /**
- * Does allow to instantiate.
- */
- private PathUtils() {
- // do not instantiate.
- }
-
}

[IO-758] Deprecate PathUtils.NOFOLLOW_LINK_OPTION_ARRAY in favor of
noFollowLinkOptionArray().