8201407: Files.move throws DirectoryNonEmptyException when moving directory across file system

Alan Bateman Alan.Bateman at oracle.com
Sun Jun 3 19:33:23 UTC 2018


On 01/06/2018 02:01, Brian Burkhalter wrote:
>
> An updated version is here:
>
> http://cr.openjdk.java.net/~bpb/8201407/webrev.02/ 
> <http://cr.openjdk.java.net/%7Ebpb/8201407/webrev.02/>
>
> As ensureEmptyDir() method was added for each platform family. Note 
> that the logic of this for UnixCopyFile has been updated especially at 
> lines 381-393. This test passed on all platforms and further tests 
> will be run.
>
The javadoc and test update looks okay. The Windows implementation look 
okay too, just a minor nit in the comment where it says "is appropriate" 
instead of "not empty".

The Unix implementation could be a lot simpler, can you try this instead:

    static boolean isEmpty(UnixPath dir) throws IOException {
         try {
             long ptr = opendir(dir);
             try (UnixDirectoryStream stream = new 
UnixDirectoryStream(dir, ptr, e -> true)) {
                 return !stream.iterator().hasNext();
             }
         } catch (UnixException e) {
             e.rethrowAsIOException(dir);
             return false;
         }
     }

-Alan






More information about the nio-dev mailing list