Skip to content

Commit 26dba5e

Browse files
committed
IO-319 document behavior with size > long and stop counting when long is < 0.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1326766 13f79535-47bb-0310-9956-ffa450edef68
1 parent 45650b6 commit 26dba5e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/main/java/org/apache/commons/io/FileUtils.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,10 +2353,13 @@ public static long sizeOf(File file) {
23532353

23542354
/**
23552355
* Counts the size of a directory recursively (sum of the length of all files).
2356-
*
2357-
* @param directory directory to inspect, must not be {@code null}
2358-
* @return size of directory in bytes, 0 if directory is security restricted
2359-
* @throws NullPointerException if the directory is {@code null}
2356+
*
2357+
* @param directory
2358+
* directory to inspect, must not be {@code null}
2359+
* @return size of directory in bytes, 0 if directory is security restricted, a negative number when the real total
2360+
* is greater than {@link Long#MAX_VALUE}.
2361+
* @throws NullPointerException
2362+
* if the directory is {@code null}
23602363
*/
23612364
public static long sizeOfDirectory(File directory) {
23622365
if (!directory.exists()) {
@@ -2377,6 +2380,9 @@ public static long sizeOfDirectory(File directory) {
23772380
try {
23782381
if (!isSymlink(file)) {
23792382
size += sizeOf(file);
2383+
if (size < 0) {
2384+
break;
2385+
}
23802386
}
23812387
} catch (IOException ioe) {
23822388
// Ignore exceptions caught when asking if a File is a symlink.

0 commit comments

Comments
 (0)