Bug in Files.copy() where the source Path is a directory... It _is_ a bug, right?
Francis Galiegue
fgaliegue at gmail.com
Wed Dec 10 19:48:24 UTC 2014
Well, at least the behaviour is very counterintuitive.
Here is the situation:
$ pwd
/hope/fge/tmp
$ stat -c foo
directory
$ find foo
foo
foo/bar
$ stat -c %F meh
stat: cannot stat ‘meh’: No such file or directory
OK, so:
* foo is a non empty directory;
* there is no meh at this place.
Now, this is the code:
public static void main(final String... args)
throws IOException
{
final Path dir = Paths.get("/home/fge/tmp/foo");
final Path dst = dir.resolveSibling("meh");
Files.copy(dir, dst);
}
This code DOES NOT FAIL (not even with DirectoryNotEmptyException on
the source).
And the result is this:
$ stat -c %F meh
directory
$ find meh
meh
Yep, it only copied the directory entry and no files under it!
--
Francis Galiegue, fgaliegue at gmail.com, https://github.com/fge
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Parsers in pure Java: https://github.com/parboiled1/grappa (redde
Caesaris: https://github.com/sirthias)
More information about the nio-dev
mailing list