6831461: (sample) Copy -r fails with IllegalArgumentexception: 'maxDepth' is negative
Reviewed-by: chegar
This commit is contained in:
parent
cab29c9b7a
commit
d4a0d0c66d
@ -52,7 +52,7 @@ public class Copy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy source file to target location. If {@code prompt} is true then
|
* Copy source file to target location. If {@code prompt} is true then
|
||||||
* prompted user to overwrite target if it exists. The {@code preserve}
|
* prompt user to overwrite target if it exists. The {@code preserve}
|
||||||
* parameter determines if file attributes should be copied/preserved.
|
* parameter determines if file attributes should be copied/preserved.
|
||||||
*/
|
*/
|
||||||
static void copyFile(Path source, Path target, boolean prompt, boolean preserve) {
|
static void copyFile(Path source, Path target, boolean prompt, boolean preserve) {
|
||||||
@ -63,7 +63,7 @@ public class Copy {
|
|||||||
try {
|
try {
|
||||||
source.copyTo(target, options);
|
source.copyTo(target, options);
|
||||||
} catch (IOException x) {
|
} catch (IOException x) {
|
||||||
System.err.format("Unable to create: %s: %s%n", target, x);
|
System.err.format("Unable to copy: %s: %s%n", source, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,13 +124,13 @@ public class Copy {
|
|||||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
|
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
|
||||||
// fix up modification time of directory when done
|
// fix up modification time of directory when done
|
||||||
if (exc == null && preserve) {
|
if (exc == null && preserve) {
|
||||||
|
Path newdir = target.resolve(source.relativize(dir));
|
||||||
try {
|
try {
|
||||||
BasicFileAttributes attrs = Attributes.readBasicFileAttributes(dir);
|
BasicFileAttributes attrs = Attributes.readBasicFileAttributes(dir);
|
||||||
Path newdir = target.resolve(source.relativize(dir));
|
|
||||||
Attributes.setLastModifiedTime(newdir,
|
Attributes.setLastModifiedTime(newdir,
|
||||||
attrs.lastModifiedTime(), attrs.resolution());
|
attrs.lastModifiedTime(), attrs.resolution());
|
||||||
} catch (IOException x) {
|
} catch (IOException x) {
|
||||||
// ignore
|
System.err.format("Unable to copy all attributes to: %s: %s%n", newdir, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CONTINUE;
|
return CONTINUE;
|
||||||
@ -191,6 +191,7 @@ public class Copy {
|
|||||||
try {
|
try {
|
||||||
isDir = Attributes.readBasicFileAttributes(target).isDirectory();
|
isDir = Attributes.readBasicFileAttributes(target).isDirectory();
|
||||||
} catch (IOException x) {
|
} catch (IOException x) {
|
||||||
|
// ignore (probably target does not exist)
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy each source file/directory to target
|
// copy each source file/directory to target
|
||||||
@ -201,7 +202,7 @@ public class Copy {
|
|||||||
// follow links when copying files
|
// follow links when copying files
|
||||||
EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
|
EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
|
||||||
TreeCopier tc = new TreeCopier(source[i], dest, prompt, preserve);
|
TreeCopier tc = new TreeCopier(source[i], dest, prompt, preserve);
|
||||||
Files.walkFileTree(source[i], opts, -1, tc);
|
Files.walkFileTree(source[i], opts, Integer.MAX_VALUE, tc);
|
||||||
} else {
|
} else {
|
||||||
// not recursive so source must not be a directory
|
// not recursive so source must not be a directory
|
||||||
try {
|
try {
|
||||||
@ -209,7 +210,9 @@ public class Copy {
|
|||||||
System.err.format("%s: is a directory%n", source[i]);
|
System.err.format("%s: is a directory%n", source[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} catch (IOException x) { }
|
} catch (IOException x) {
|
||||||
|
// assume not directory
|
||||||
|
}
|
||||||
copyFile(source[i], dest, prompt, preserve);
|
copyFile(source[i], dest, prompt, preserve);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user