Skip to content

Commit 5fe2056

Browse files
committed
[IO-857"][Javadoc] PathUtils.cleanDirectory() methods vs FileUtils.
1 parent 0390338 commit 5fe2056

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ The <action> type attribute can be add,update,fix,remove.
6767
<action type="fix" dev="ggregory" due-to="Peter De Maeyer, Gary Gregory" issue="IO-885">Path visits follow links #832.</action>
6868
<action type="fix" dev="ggregory" due-to="Gary Gregory">BOMInputStream fail-fast and tracks its ByteOrderMark as a final #835.</action>
6969
<action type="fix" dev="ggregory" due-to="Gary Gregory">Refactor UnixLineEndingInputStream and WindowsLineEndingInputStream for duplication.</action>
70+
<action type="fix" dev="ggregory" due-to="Peter De Maeyer, Gary Gregory" issue="IO-857">[Javadoc] PathUtils.cleanDirectory() methods vs FileUtils.</action>
7071
<!-- ADD -->
7172
<action type="add" dev="ggregory" due-to="Gary Gregory, Piotr P. Karwasz">Add and use IOUtils.closeQuietlySuppress(Closeable, Throwable) #818.</action>
7273
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ProxyWriter.setReference(Writer).</action>

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@ private static AccumulatorPathVisitor accumulate(final Path directory, final int
281281
}
282282

283283
/**
284-
* Cleans a directory by only deleting files, including in subdirectories, but without deleting the directories.
284+
* Cleans a directory by only deleting files, including in subdirectories, without deleting directories.
285+
* <p>
286+
* This leaves a directory empty of files but the directory and any subdirectories remain.
287+
* </p>
285288
*
286289
* @param directory directory to clean.
287290
* @return The visitation path counters.
@@ -292,7 +295,10 @@ public static PathCounters cleanDirectory(final Path directory) throws IOExcepti
292295
}
293296

294297
/**
295-
* Cleans a directory by only deleting files, including in subdirectories, but without deleting the directories.
298+
* Cleans a directory by only deleting files, including in subdirectories, without deleting directories.
299+
* <p>
300+
* This leaves a directory empty of files but the directory and any subdirectories remain.
301+
* </p>
296302
*
297303
* @param directory directory to clean.
298304
* @param deleteOptions How to handle deletion.

src/test/java/org/apache/commons/io/file/PathUtilsCleanDirectoryTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
package org.apache.commons.io.file;
1919

2020
import static org.apache.commons.io.file.CounterAssertions.assertCounts;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2122

2223
import java.io.IOException;
24+
import java.nio.file.Files;
2325
import java.nio.file.Path;
2426
import java.nio.file.Paths;
2527

@@ -41,6 +43,7 @@ class PathUtilsCleanDirectoryTest {
4143
void testCleanDirectory1FileSize0() throws IOException {
4244
PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-0"), tempDir);
4345
assertCounts(1, 1, 0, PathUtils.cleanDirectory(tempDir));
46+
assertTrue(Files.exists(tempDir));
4447
}
4548

4649
/**
@@ -50,6 +53,7 @@ void testCleanDirectory1FileSize0() throws IOException {
5053
void testCleanDirectory1FileSize1() throws IOException {
5154
PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1"), tempDir);
5255
assertCounts(1, 1, 1, PathUtils.cleanDirectory(tempDir));
56+
assertTrue(Files.exists(tempDir));
5357
}
5458

5559
/**
@@ -59,6 +63,7 @@ void testCleanDirectory1FileSize1() throws IOException {
5963
void testCleanDirectory2FileSize2() throws IOException {
6064
PathUtils.copyDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-2-file-size-2"), tempDir);
6165
assertCounts(3, 2, 2, PathUtils.cleanDirectory(tempDir));
66+
assertTrue(Files.exists(tempDir));
6267
}
6368

6469
/**
@@ -67,5 +72,6 @@ void testCleanDirectory2FileSize2() throws IOException {
6772
@Test
6873
void testCleanEmptyDirectory() throws IOException {
6974
assertCounts(1, 0, 0, PathUtils.cleanDirectory(tempDir));
75+
assertTrue(Files.exists(tempDir));
7076
}
7177
}

0 commit comments

Comments
 (0)