changeset 4926:7e593aa6ad41

7129029: (fs) Unix file system provider should be buildable on platforms that don't support O_NOFOLLOW Reviewed-by: alanb
author littlee
date Fri, 13 Jan 2012 13:20:02 +0000
parents a7ad2fcd7291
children e8e08d46cc37
files src/solaris/classes/sun/nio/fs/UnixChannelFactory.java src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java src/solaris/classes/sun/nio/fs/UnixNativeDispatcher.java src/solaris/classes/sun/nio/fs/UnixPath.java src/solaris/native/sun/nio/fs/genUnixConstants.c
diffstat 5 files changed, 25 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java	Thu Jan 12 18:49:33 2012 -0800
+++ b/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java	Fri Jan 13 13:20:02 2012 +0000
@@ -36,8 +36,6 @@
 import sun.misc.SharedSecrets;
 import sun.misc.JavaIOFileDescriptorAccess;
 
-import com.sun.nio.file.ExtendedOpenOption;
-
 import static sun.nio.fs.UnixNativeDispatcher.*;
 import static sun.nio.fs.UnixConstants.*;
 
@@ -86,13 +84,13 @@
                     }
                     continue;
                 }
-                if (option == LinkOption.NOFOLLOW_LINKS) {
+                if (option == LinkOption.NOFOLLOW_LINKS && supportsNoFollowLinks()) {
                     flags.noFollowLinks = true;
                     continue;
                 }
                 if (option == null)
                     throw new NullPointerException();
-               throw new UnsupportedOperationException();
+               throw new UnsupportedOperationException(option + " not supported");
             }
             return flags;
         }
@@ -220,6 +218,15 @@
         // follow links by default
         boolean followLinks = true;
         if (!flags.createNew && (flags.noFollowLinks || flags.deleteOnClose)) {
+            if (flags.deleteOnClose && !supportsNoFollowLinks()) {
+                try {
+                    if (UnixFileAttributes.get(path, false).isSymbolicLink())
+                        throw new UnixException("DELETE_ON_CLOSE specified and file is a symbolic link");
+                } catch (UnixException x) {
+                    if (!flags.create || x.errno() != ENOENT)
+                        throw x;
+                }
+            }
             followLinks = false;
             oflags |= O_NOFOLLOW;
         }
--- a/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java	Thu Jan 12 18:49:33 2012 -0800
+++ b/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java	Fri Jan 13 13:20:02 2012 +0000
@@ -395,7 +395,7 @@
 
         // can't return SecureDirectoryStream on kernels that don't support
         // openat, etc.
-        if (!supportsAtSysCalls()) {
+        if (!supportsAtSysCalls() || !supportsNoFollowLinks()) {
             try {
                 long ptr = opendir(dir);
                 return new UnixDirectoryStream(dir, ptr, filter);
--- a/src/solaris/classes/sun/nio/fs/UnixNativeDispatcher.java	Thu Jan 12 18:49:33 2012 -0800
+++ b/src/solaris/classes/sun/nio/fs/UnixNativeDispatcher.java	Fri Jan 13 13:20:02 2012 +0000
@@ -548,6 +548,10 @@
         return hasAtSysCalls;
     }
 
+    static boolean supportsNoFollowLinks() {
+        return UnixConstants.O_NOFOLLOW != 0;
+    }
+
     // initialize syscalls and fieldIDs
     private static native int init();
 
--- a/src/solaris/classes/sun/nio/fs/UnixPath.java	Thu Jan 12 18:49:33 2012 -0800
+++ b/src/solaris/classes/sun/nio/fs/UnixPath.java	Fri Jan 13 13:20:02 2012 +0000
@@ -767,8 +767,11 @@
     // package-private
     int openForAttributeAccess(boolean followLinks) throws IOException {
         int flags = O_RDONLY;
-        if (!followLinks)
+        if (!followLinks) {
+            if (!supportsNoFollowLinks())
+                throw new IOException("NOFOLLOW_LINKS is not supported on this platform");
             flags |= O_NOFOLLOW;
+        }
         try {
             return open(this, flags, 0);
         } catch (UnixException x) {
--- a/src/solaris/native/sun/nio/fs/genUnixConstants.c	Thu Jan 12 18:49:33 2012 -0800
+++ b/src/solaris/native/sun/nio/fs/genUnixConstants.c	Fri Jan 13 13:20:02 2012 +0000
@@ -64,7 +64,12 @@
     DEFX(O_TRUNC);
     DEFX(O_SYNC);
     DEFX(O_DSYNC);
+#ifdef O_NOFOLLOW
     DEFX(O_NOFOLLOW);
+#else
+    // not supported (dummy values will not be used at runtime).
+    emitX("O_NOFOLLOW", 0x0);
+#endif
 
     // mode masks
     emitX("S_IAMB",