7016704: TEST_BUG: java/nio/file/Files/walk_file_tree.sh fails with new version of find (lnx)
authoralanb
Mon, 14 Feb 2011 18:30:53 +0000
changeset 8391 6fc6aef1be12
parent 8390 f9ed509a2634
child 8393 582bd30ef587
7016704: TEST_BUG: java/nio/file/Files/walk_file_tree.sh fails with new version of find (lnx) Reviewed-by: forax
jdk/test/java/nio/file/Files/walkFileTree/PrintFileTree.java
--- a/jdk/test/java/nio/file/Files/walkFileTree/PrintFileTree.java	Mon Feb 14 09:31:58 2011 -0800
+++ b/jdk/test/java/nio/file/Files/walkFileTree/PrintFileTree.java	Mon Feb 14 18:30:53 2011 +0000
@@ -54,6 +54,7 @@
         if (followLinks)
             options.add(FileVisitOption.FOLLOW_LINKS);
 
+        final boolean follow = followLinks;
         final boolean reportCycles = printCycles;
         Files.walkFileTree(dir, options, Integer.MAX_VALUE, new FileVisitor<Path>() {
             @Override
@@ -63,8 +64,7 @@
             }
             @Override
             public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
-                if (!attrs.isDirectory() || reportCycles)
-                    System.out.println(file);
+                System.out.println(file);
                 return FileVisitResult.CONTINUE;
             }
             @Override
@@ -79,11 +79,13 @@
             public FileVisitResult visitFileFailed(Path file, IOException exc)
                 throws IOException
             {
-                if (reportCycles && (exc instanceof FileSystemLoopException)) {
-                    System.out.println(file);
+                if (follow && (exc instanceof FileSystemLoopException)) {
+                    if (reportCycles)
+                        System.out.println(file);
                     return FileVisitResult.CONTINUE;
+                } else {
+                    throw exc;
                 }
-                throw exc;
             }
         });
     }