Skip to content

Commit

Permalink
Behavior seems to have changed from 2.6, use
Browse files Browse the repository at this point in the history
FileVisitOption.FOLLOW_LINKS to remedy.
  • Loading branch information
garydgregory committed Jul 6, 2020
1 parent 19319ea commit 52f3de5
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/main/java/org/apache/commons/io/file/PathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,22 @@ private RelativeSortedPaths(final Path dir1, final Path dir2, final int maxDepth
* @throws IOException if an I/O error is thrown by a visitor method.
*/
public static PathCounters cleanDirectory(final Path directory) throws IOException {
return visitFileTree(CleaningPathVisitor.withLongCounters(), directory).getPathCounters();
return cleanDirectory(directory, FileVisitOption.FOLLOW_LINKS);
}

/**
* Cleans a directory including sub-directories without deleting directories.
*
* @param directory directory to clean.
* @param fileVisitOptions See {@link Files#walkFileTree(Path,Set,int,FileVisitor)}.
* @return The visitation path counters.
* @throws IOException if an I/O error is thrown by a visitor method.
* @since 2.9
*/
public static PathCounters cleanDirectory(final Path directory, final FileVisitOption... fileVisitOptions)
throws IOException {
return visitFileTree(CleaningPathVisitor.withLongCounters(), directory, toFileVisitOptionSet(fileVisitOptions),
Integer.MAX_VALUE).getPathCounters();
}

/**
Expand Down Expand Up @@ -262,6 +277,18 @@ public static PathCounters delete(final Path path) throws IOException {
* @throws IOException if an I/O error is thrown by a visitor method.
*/
public static PathCounters deleteDirectory(final Path directory) throws IOException {
return deleteDirectory(directory, FileVisitOption.FOLLOW_LINKS);
}

/**
* Deletes a directory including sub-directories.
*
* @param directory directory to delete.
* @param fileVisitOptions See {@link Files#walkFileTree(Path,Set,int,FileVisitor)}.
* @return The visitor used to delete the given directory.
* @throws IOException if an I/O error is thrown by a visitor method.
*/
public static PathCounters deleteDirectory(final Path directory, final FileVisitOption... fileVisitOptions) throws IOException {
return visitFileTree(DeletingPathVisitor.withLongCounters(), directory).getPathCounters();
}

Expand Down

0 comments on commit 52f3de5

Please sign in to comment.