From bdfb60de8c3f9cd73f7bca8bbb8d1b0e25db9c0c Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Tue, 23 Feb 2010 18:21:31 +0000 Subject: [PATCH] 6926800: TEST_BUG: java/nio/file/Files/walk_file_tree.sh fails with newer versions of find(1) Reviewed-by: forax --- .../java/nio/file/Files/PrintFileTree.java | 27 ++++++++++++------- .../java/nio/file/Files/walk_file_tree.sh | 18 +++++++++---- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/jdk/test/java/nio/file/Files/PrintFileTree.java b/jdk/test/java/nio/file/Files/PrintFileTree.java index dc2c49f8db1..40d2ab52b14 100644 --- a/jdk/test/java/nio/file/Files/PrintFileTree.java +++ b/jdk/test/java/nio/file/Files/PrintFileTree.java @@ -28,27 +28,33 @@ import java.util.*; /** * Invokes Files.walkFileTree to traverse a file tree and prints - * each of the directories and files. The -L option causes symbolic - * links to be followed. + * each of the directories and files. The -follow option causes symbolic + * links to be followed and the -printCycles option will print links + * where the target of the link is an ancestor directory. */ public class PrintFileTree { public static void main(String[] args) throws Exception { boolean followLinks = false; - Path dir; - - if (args[0].equals("-L")) { - followLinks = true; - dir = Paths.get(args[1]); - } else { - dir = Paths.get(args[0]); + boolean printCycles = false; + int i = 0; + while (i < (args.length-1)) { + switch (args[i]) { + case "-follow" : followLinks = true; break; + case "-printCycles" : printCycles = true; break; + default: + throw new RuntimeException(args[i] + " not recognized"); + } + i++; } + Path dir = Paths.get(args[i]); Set options = new HashSet(); if (followLinks) options.add(FileVisitOption.FOLLOW_LINKS); + final boolean reportCycles = printCycles; Files.walkFileTree(dir, options, Integer.MAX_VALUE, new FileVisitor() { public FileVisitResult preVisitDirectory(FileRef dir) { System.out.println(dir); @@ -59,7 +65,8 @@ public class PrintFileTree { return FileVisitResult.CONTINUE; } public FileVisitResult visitFile(FileRef file, BasicFileAttributes attrs) { - System.out.println(file); + if (!attrs.isDirectory() || reportCycles) + System.out.println(file); return FileVisitResult.CONTINUE; } public FileVisitResult postVisitDirectory(FileRef dir, IOException exc) { diff --git a/jdk/test/java/nio/file/Files/walk_file_tree.sh b/jdk/test/java/nio/file/Files/walk_file_tree.sh index 897625d46ac..b5a173c5392 100644 --- a/jdk/test/java/nio/file/Files/walk_file_tree.sh +++ b/jdk/test/java/nio/file/Files/walk_file_tree.sh @@ -61,12 +61,20 @@ find "$ROOT" > out2 diff out1 out2 if [ $? != 0 ]; then failures=`expr $failures + 1`; fi -# repeat test following links (use -follow instead of -L -# to allow running on older systems) -$JAVA PrintFileTree -L "$ROOT" > out1 -find "$ROOT" -follow > out2 +# repeat test following links. Some versions of find(1) output +# cycles (sym links to ancestor directories), other versions do +# not. For that reason we run PrintFileTree with the -printCycles +# option when the output without this option differs to find(1). +find "$ROOT" -follow > out1 +$JAVA PrintFileTree -follow "$ROOT" > out2 diff out1 out2 -if [ $? != 0 ]; then failures=`expr $failures + 1`; fi +if [ $? != 0 ]; + then + # re-run printing cycles to stdout + $JAVA PrintFileTree -follow -printCycles "$ROOT" > out2 + diff out1 out2 + if [ $? != 0 ]; then failures=`expr $failures + 1`; fi + fi # test SKIP_SIBLINGS $JAVA SkipSiblings "$ROOT"