garydgregory commented on code in PR #827:
URL: https://github.com/apache/commons-io/pull/827#discussion_r2779821874


##########
src/main/java/org/apache/commons/io/file/CountingPathVisitor.java:
##########
@@ -311,7 +311,14 @@ protected void updateDirCounter(final Path dir, final 
IOException exc) {
      */
     protected void updateFileCounters(final Path file, final 
BasicFileAttributes attributes) {
         pathCounters.getFileCounter().increment();
-        pathCounters.getByteCounter().add(attributes.size());
+        // According to the JavaDoc, BasicFileAttributes.size() is only 
well-defined for regular files.
+        // For symbolic links on Linux for example, it counts the # (charset 
dependent?) bytes in the inode name, which is NOT what we want to count here.
+        // Intuitively, the appropriate check would be Files.isRegularFile.
+        // However, for symbolic links, isRegularFile returns true under a 
"follow links" regime.
+        // That would still not give us what we want, so instead we settle for 
a !Files.isSymbolicLink check.
+        if (!Files.isSymbolicLink(file)) {

Review Comment:
   Great documentation. This should be in the Javadoc of this method IMO.



##########
src/main/java/org/apache/commons/io/file/CountingPathVisitor.java:
##########
@@ -311,7 +311,14 @@ protected void updateDirCounter(final Path dir, final 
IOException exc) {
      */
     protected void updateFileCounters(final Path file, final 
BasicFileAttributes attributes) {
         pathCounters.getFileCounter().increment();
-        pathCounters.getByteCounter().add(attributes.size());
+        // According to the JavaDoc, BasicFileAttributes.size() is only 
well-defined for regular files.
+        // For symbolic links on Linux for example, it counts the # (charset 
dependent?) bytes in the inode name, which is NOT what we want to count here.
+        // Intuitively, the appropriate check would be Files.isRegularFile.
+        // However, for symbolic links, isRegularFile returns true under a 
"follow links" regime.
+        // That would still not give us what we want, so instead we settle for 
a !Files.isSymbolicLink check.
+        if (!Files.isSymbolicLink(file)) {

Review Comment:
   Great documentation. This should be in the Javadoc of this method IMO.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to