7129029: (fs) Unix file system provider should be buildable on platforms that don't support O_NOFOLLOW
authorlittlee
Fri, 13 Jan 2012 13:20:02 +0000
changeset 11525 b0263ecbbdf1
parent 11524 98514f22fc51
child 11526 efcd7eae978f
7129029: (fs) Unix file system provider should be buildable on platforms that don't support O_NOFOLLOW Reviewed-by: alanb
jdk/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java
jdk/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java
jdk/src/solaris/classes/sun/nio/fs/UnixNativeDispatcher.java
jdk/src/solaris/classes/sun/nio/fs/UnixPath.java
jdk/src/solaris/native/sun/nio/fs/genUnixConstants.c
--- a/jdk/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java	Thu Jan 12 18:49:33 2012 -0800
+++ b/jdk/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/jdk/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java	Thu Jan 12 18:49:33 2012 -0800
+++ b/jdk/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/jdk/src/solaris/classes/sun/nio/fs/UnixNativeDispatcher.java	Thu Jan 12 18:49:33 2012 -0800
+++ b/jdk/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/jdk/src/solaris/classes/sun/nio/fs/UnixPath.java	Thu Jan 12 18:49:33 2012 -0800
+++ b/jdk/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/jdk/src/solaris/native/sun/nio/fs/genUnixConstants.c	Thu Jan 12 18:49:33 2012 -0800
+++ b/jdk/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",