提交 083b86dc 编写于 作者: L littlee

7129029: (fs) Unix file system provider should be buildable on platforms that...

7129029: (fs) Unix file system provider should be buildable on platforms that don't support O_NOFOLLOW
Reviewed-by: alanb
上级 39fe76a8
...@@ -36,8 +36,6 @@ import sun.nio.ch.SimpleAsynchronousFileChannelImpl; ...@@ -36,8 +36,6 @@ import sun.nio.ch.SimpleAsynchronousFileChannelImpl;
import sun.misc.SharedSecrets; import sun.misc.SharedSecrets;
import sun.misc.JavaIOFileDescriptorAccess; import sun.misc.JavaIOFileDescriptorAccess;
import com.sun.nio.file.ExtendedOpenOption;
import static sun.nio.fs.UnixNativeDispatcher.*; import static sun.nio.fs.UnixNativeDispatcher.*;
import static sun.nio.fs.UnixConstants.*; import static sun.nio.fs.UnixConstants.*;
...@@ -86,13 +84,13 @@ class UnixChannelFactory { ...@@ -86,13 +84,13 @@ class UnixChannelFactory {
} }
continue; continue;
} }
if (option == LinkOption.NOFOLLOW_LINKS) { if (option == LinkOption.NOFOLLOW_LINKS && supportsNoFollowLinks()) {
flags.noFollowLinks = true; flags.noFollowLinks = true;
continue; continue;
} }
if (option == null) if (option == null)
throw new NullPointerException(); throw new NullPointerException();
throw new UnsupportedOperationException(); throw new UnsupportedOperationException(option + " not supported");
} }
return flags; return flags;
} }
...@@ -220,6 +218,15 @@ class UnixChannelFactory { ...@@ -220,6 +218,15 @@ class UnixChannelFactory {
// follow links by default // follow links by default
boolean followLinks = true; boolean followLinks = true;
if (!flags.createNew && (flags.noFollowLinks || flags.deleteOnClose)) { 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; followLinks = false;
oflags |= O_NOFOLLOW; oflags |= O_NOFOLLOW;
} }
......
...@@ -395,7 +395,7 @@ public abstract class UnixFileSystemProvider ...@@ -395,7 +395,7 @@ public abstract class UnixFileSystemProvider
// can't return SecureDirectoryStream on kernels that don't support // can't return SecureDirectoryStream on kernels that don't support
// openat, etc. // openat, etc.
if (!supportsAtSysCalls()) { if (!supportsAtSysCalls() || !supportsNoFollowLinks()) {
try { try {
long ptr = opendir(dir); long ptr = opendir(dir);
return new UnixDirectoryStream(dir, ptr, filter); return new UnixDirectoryStream(dir, ptr, filter);
......
...@@ -548,6 +548,10 @@ class UnixNativeDispatcher { ...@@ -548,6 +548,10 @@ class UnixNativeDispatcher {
return hasAtSysCalls; return hasAtSysCalls;
} }
static boolean supportsNoFollowLinks() {
return UnixConstants.O_NOFOLLOW != 0;
}
// initialize syscalls and fieldIDs // initialize syscalls and fieldIDs
private static native int init(); private static native int init();
......
...@@ -767,8 +767,11 @@ class UnixPath ...@@ -767,8 +767,11 @@ class UnixPath
// package-private // package-private
int openForAttributeAccess(boolean followLinks) throws IOException { int openForAttributeAccess(boolean followLinks) throws IOException {
int flags = O_RDONLY; int flags = O_RDONLY;
if (!followLinks) if (!followLinks) {
if (!supportsNoFollowLinks())
throw new IOException("NOFOLLOW_LINKS is not supported on this platform");
flags |= O_NOFOLLOW; flags |= O_NOFOLLOW;
}
try { try {
return open(this, flags, 0); return open(this, flags, 0);
} catch (UnixException x) { } catch (UnixException x) {
......
...@@ -64,7 +64,12 @@ int main(int argc, const char* argv[]) { ...@@ -64,7 +64,12 @@ int main(int argc, const char* argv[]) {
DEFX(O_TRUNC); DEFX(O_TRUNC);
DEFX(O_SYNC); DEFX(O_SYNC);
DEFX(O_DSYNC); DEFX(O_DSYNC);
#ifdef O_NOFOLLOW
DEFX(O_NOFOLLOW); DEFX(O_NOFOLLOW);
#else
// not supported (dummy values will not be used at runtime).
emitX("O_NOFOLLOW", 0x0);
#endif
// mode masks // mode masks
emitX("S_IAMB", emitX("S_IAMB",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册