mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-23 12:34:32 +02:00
6926800: TEST_BUG: java/nio/file/Files/walk_file_tree.sh fails with newer versions of find(1)
Reviewed-by: forax
This commit is contained in:
parent
d5dc027db9
commit
bdfb60de8c
2 changed files with 30 additions and 15 deletions
|
@ -28,27 +28,33 @@ import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes Files.walkFileTree to traverse a file tree and prints
|
* Invokes Files.walkFileTree to traverse a file tree and prints
|
||||||
* each of the directories and files. The -L option causes symbolic
|
* each of the directories and files. The -follow option causes symbolic
|
||||||
* links to be followed.
|
* 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 class PrintFileTree {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
boolean followLinks = false;
|
boolean followLinks = false;
|
||||||
Path dir;
|
boolean printCycles = false;
|
||||||
|
int i = 0;
|
||||||
if (args[0].equals("-L")) {
|
while (i < (args.length-1)) {
|
||||||
followLinks = true;
|
switch (args[i]) {
|
||||||
dir = Paths.get(args[1]);
|
case "-follow" : followLinks = true; break;
|
||||||
} else {
|
case "-printCycles" : printCycles = true; break;
|
||||||
dir = Paths.get(args[0]);
|
default:
|
||||||
|
throw new RuntimeException(args[i] + " not recognized");
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
Path dir = Paths.get(args[i]);
|
||||||
|
|
||||||
Set<FileVisitOption> options = new HashSet<FileVisitOption>();
|
Set<FileVisitOption> options = new HashSet<FileVisitOption>();
|
||||||
if (followLinks)
|
if (followLinks)
|
||||||
options.add(FileVisitOption.FOLLOW_LINKS);
|
options.add(FileVisitOption.FOLLOW_LINKS);
|
||||||
|
|
||||||
|
final boolean reportCycles = printCycles;
|
||||||
Files.walkFileTree(dir, options, Integer.MAX_VALUE, new FileVisitor<FileRef>() {
|
Files.walkFileTree(dir, options, Integer.MAX_VALUE, new FileVisitor<FileRef>() {
|
||||||
public FileVisitResult preVisitDirectory(FileRef dir) {
|
public FileVisitResult preVisitDirectory(FileRef dir) {
|
||||||
System.out.println(dir);
|
System.out.println(dir);
|
||||||
|
@ -59,6 +65,7 @@ public class PrintFileTree {
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
}
|
}
|
||||||
public FileVisitResult visitFile(FileRef file, BasicFileAttributes attrs) {
|
public FileVisitResult visitFile(FileRef file, BasicFileAttributes attrs) {
|
||||||
|
if (!attrs.isDirectory() || reportCycles)
|
||||||
System.out.println(file);
|
System.out.println(file);
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,12 +61,20 @@ find "$ROOT" > out2
|
||||||
diff out1 out2
|
diff out1 out2
|
||||||
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
|
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
|
||||||
|
|
||||||
# repeat test following links (use -follow instead of -L
|
# repeat test following links. Some versions of find(1) output
|
||||||
# to allow running on older systems)
|
# cycles (sym links to ancestor directories), other versions do
|
||||||
$JAVA PrintFileTree -L "$ROOT" > out1
|
# not. For that reason we run PrintFileTree with the -printCycles
|
||||||
find "$ROOT" -follow > out2
|
# option when the output without this option differs to find(1).
|
||||||
|
find "$ROOT" -follow > out1
|
||||||
|
$JAVA PrintFileTree -follow "$ROOT" > out2
|
||||||
diff out1 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
|
# test SKIP_SIBLINGS
|
||||||
$JAVA SkipSiblings "$ROOT"
|
$JAVA SkipSiblings "$ROOT"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue