Why do we need LinkOption.NOFOLLOW_LINKS on the target file in CopyMoveHelper.copyToForeignTarget?

Volker Simonis volker.simonis at gmail.com
Mon Dec 23 15:48:29 UTC 2013


Hi,

while running the jdk/jtreg tests for our ppc-aix-port I found a
problem for the demo/zipfs/basic.sh test on AIX:

Exception in thread "main" java.io.IOException: NOFOLLOW_LINKS is not
supported on this platform
    at sun.nio.fs.UnixPath.openForAttributeAccess(UnixPath.java:773)
    at sun.nio.fs.UnixFileAttributeViews$Basic.setTimes(UnixFileAttributeViews.java:74)
    at java.nio.file.CopyMoveHelper.copyToForeignTarget(CopyMoveHelper.java:135)
    at java.nio.file.CopyMoveHelper.moveToForeignTarget(CopyMoveHelper.java:157)
    at java.nio.file.Files.move(Files.java:1395)
    at ZipFSTester.test1(ZipFSTester.java:141)
    at ZipFSTester.main(ZipFSTester.java:50)

The test calls java.nio.file.Files.move() without any CopyOptions.
Files.move() in turn calls
java.nio.file.CopyMoveHelper.moveToForeignTarget() which adds the two
CopyOptions LinkOption.NOFOLLOW_LINKS and
StandardCopyOption.COPY_ATTRIBUTES before calling
CopyMoveHelper.copyToForeignTarget().

CopyMoveHelper.copyToForeignTarget() finally checks that the source
file is no symbolic link and performs the copy operation. In a last
step it also copies the file attributes of the source file to the
target file. For this operation it first calls
Files.getFileAttributeView(target, BasicFileAttributeView.class,
linkOptions) before the new attributes are set with
sun.nio.fs.UnixFileAttributeViews$Basic.setTimes(). But operation will
always fail on system like AIX which do not support NOFOLLOW_LINKS (or
more exactly the O_NOFOLLOW flag to the open system call). See the
stack trace above.

However, I don't think that we need to set the
LinkOption.NOFOLLOW_LINKS option when calling
Files.getFileAttributeView() on the target file, because the target
file can not be a symbolic link anyway for two reasons: first of all,
copyToForeignTarget() already checks that the source file is no
symbolic link and it deletes 'target' it that should exist before.

So from my point of view it would be safe to change
CopyMoveHelper.copyToForeignTarget() as follows to make it work an
systems which don't support NOFOLLOW_LINKS:

--- a/src/share/classes/java/nio/file/CopyMoveHelper.java       Fri
Dec 20 17:52:39 2013 +0100
+++ b/src/share/classes/java/nio/file/CopyMoveHelper.java       Mon
Dec 23 16:33:43 2013 +0100
@@ -130,7 +130,7 @@
         // copy basic attributes to target
         if (opts.copyAttributes) {
             BasicFileAttributeView view =
-                Files.getFileAttributeView(target,
BasicFileAttributeView.class, linkOptions);
+                Files.getFileAttributeView(target,
BasicFileAttributeView.class);
             try {
                 view.setTimes(attrs.lastModifiedTime(),
                               attrs.lastAccessTime(),


What do you think, did I miss something? If nobody objects, I'll put
this small change in the next AIX bug fix collection.

Thank you and best regards,
Volker



More information about the core-libs-dev mailing list