Mercurial > hg > openjdk > icedtea > jdk7 > jdk
changeset 5474:38be58d6ee94
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 | 710227d2d966 |
children | 61e52d6a2d80 |
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 Mon Feb 20 11:24:06 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 Mon Feb 20 11:24:06 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 Mon Feb 20 11:24:06 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 Mon Feb 20 11:24:06 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 Mon Feb 20 11:24:06 2012 +0800 +++ b/src/solaris/native/sun/nio/fs/genUnixConstants.c Fri Jan 13 13:20:02 2012 +0000 @@ -69,7 +69,12 @@ #else DEFX(O_DSYNC); #endif +#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",