8343020: (fs) Add support for SecureDirectoryStream on macOS
Reviewed-by: bpb, alanb
This commit is contained in:
parent
1341b81321
commit
9f6d5b46ce
src/java.base/unix
test/jdk/java/nio/file/DirectoryStream
@ -569,7 +569,7 @@ class UnixNativeDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supports futimes or futimesat
|
* Supports futimes
|
||||||
*/
|
*/
|
||||||
static boolean futimesSupported() {
|
static boolean futimesSupported() {
|
||||||
return (capabilities & SUPPORTS_FUTIMES) != 0;
|
return (capabilities & SUPPORTS_FUTIMES) != 0;
|
||||||
|
@ -204,7 +204,7 @@ typedef int openat_func(int, const char *, int, ...);
|
|||||||
typedef int fstatat_func(int, const char *, struct stat *, int);
|
typedef int fstatat_func(int, const char *, struct stat *, int);
|
||||||
typedef int unlinkat_func(int, const char*, int);
|
typedef int unlinkat_func(int, const char*, int);
|
||||||
typedef int renameat_func(int, const char*, int, const char*);
|
typedef int renameat_func(int, const char*, int, const char*);
|
||||||
typedef int futimesat_func(int, const char *, const struct timeval *);
|
typedef int futimes_func(int, const struct timeval *);
|
||||||
typedef int futimens_func(int, const struct timespec *);
|
typedef int futimens_func(int, const struct timespec *);
|
||||||
typedef int lutimes_func(const char *, const struct timeval *);
|
typedef int lutimes_func(const char *, const struct timeval *);
|
||||||
typedef DIR* fdopendir_func(int);
|
typedef DIR* fdopendir_func(int);
|
||||||
@ -217,7 +217,7 @@ static openat_func* my_openat_func = NULL;
|
|||||||
static fstatat_func* my_fstatat_func = NULL;
|
static fstatat_func* my_fstatat_func = NULL;
|
||||||
static unlinkat_func* my_unlinkat_func = NULL;
|
static unlinkat_func* my_unlinkat_func = NULL;
|
||||||
static renameat_func* my_renameat_func = NULL;
|
static renameat_func* my_renameat_func = NULL;
|
||||||
static futimesat_func* my_futimesat_func = NULL;
|
static futimes_func* my_futimes_func = NULL;
|
||||||
static futimens_func* my_futimens_func = NULL;
|
static futimens_func* my_futimens_func = NULL;
|
||||||
static lutimes_func* my_lutimes_func = NULL;
|
static lutimes_func* my_lutimes_func = NULL;
|
||||||
static fdopendir_func* my_fdopendir_func = NULL;
|
static fdopendir_func* my_fdopendir_func = NULL;
|
||||||
@ -363,8 +363,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
|
|||||||
/* system calls that might not be available at run time */
|
/* system calls that might not be available at run time */
|
||||||
|
|
||||||
#if defined(_ALLBSD_SOURCE)
|
#if defined(_ALLBSD_SOURCE)
|
||||||
my_openat_func = (openat_func*)dlsym(RTLD_DEFAULT, "openat");
|
my_openat_func = (openat_func*) openat;
|
||||||
my_fstatat_func = (fstatat_func*)dlsym(RTLD_DEFAULT, "fstatat");
|
my_fstatat_func = (fstatat_func*) fstatat;
|
||||||
#else
|
#else
|
||||||
// Make sure we link to the 64-bit version of the functions
|
// Make sure we link to the 64-bit version of the functions
|
||||||
my_openat_func = (openat_func*) dlsym(RTLD_DEFAULT, "openat64");
|
my_openat_func = (openat_func*) dlsym(RTLD_DEFAULT, "openat64");
|
||||||
@ -373,22 +373,22 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
|
|||||||
my_unlinkat_func = (unlinkat_func*) dlsym(RTLD_DEFAULT, "unlinkat");
|
my_unlinkat_func = (unlinkat_func*) dlsym(RTLD_DEFAULT, "unlinkat");
|
||||||
my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat");
|
my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat");
|
||||||
#if defined(__linux__) && defined(__arm__)
|
#if defined(__linux__) && defined(__arm__)
|
||||||
my_futimesat_func = (futimesat_func*) lookup_time_t_function("futimesat",
|
my_futimes_func = (futimes_func*) lookup_time_t_function("futimes",
|
||||||
"__futimesat64");
|
"__futimes64");
|
||||||
my_lutimes_func = (lutimes_func*) lookup_time_t_function("lutimes",
|
my_lutimes_func = (lutimes_func*) lookup_time_t_function("lutimes",
|
||||||
"__lutimes64");
|
"__lutimes64");
|
||||||
my_futimens_func = (futimens_func*) lookup_time_t_function("futimens",
|
my_futimens_func = (futimens_func*) lookup_time_t_function("futimens",
|
||||||
"__futimens64");
|
"__futimens64");
|
||||||
#else
|
#else
|
||||||
#ifndef _ALLBSD_SOURCE
|
my_futimes_func = (futimes_func*) dlsym(RTLD_DEFAULT, "futimes");
|
||||||
my_futimesat_func = (futimesat_func*) dlsym(RTLD_DEFAULT, "futimesat");
|
|
||||||
my_lutimes_func = (lutimes_func*) dlsym(RTLD_DEFAULT, "lutimes");
|
my_lutimes_func = (lutimes_func*) dlsym(RTLD_DEFAULT, "lutimes");
|
||||||
#endif
|
|
||||||
my_futimens_func = (futimens_func*) dlsym(RTLD_DEFAULT, "futimens");
|
my_futimens_func = (futimens_func*) dlsym(RTLD_DEFAULT, "futimens");
|
||||||
#endif
|
#endif
|
||||||
#if defined(_AIX)
|
#if defined(_AIX)
|
||||||
// Make sure we link to the 64-bit version of the function
|
// Make sure we link to the 64-bit version of the function
|
||||||
my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir64");
|
my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir64");
|
||||||
|
#elif defined(_ALLBSD_SOURCE)
|
||||||
|
my_fdopendir_func = (fdopendir_func*) fdopendir;
|
||||||
#else
|
#else
|
||||||
my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir");
|
my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir");
|
||||||
#endif
|
#endif
|
||||||
@ -399,13 +399,13 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
|
|||||||
my_fstatat_func = (fstatat_func*)&fstatat_wrapper;
|
my_fstatat_func = (fstatat_func*)&fstatat_wrapper;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* supports futimes or futimesat, futimens, and/or lutimes */
|
/* supports futimes, futimens, and/or lutimes */
|
||||||
|
|
||||||
#ifdef _ALLBSD_SOURCE
|
#ifdef _ALLBSD_SOURCE
|
||||||
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES;
|
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES;
|
||||||
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES;
|
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES;
|
||||||
#else
|
#else
|
||||||
if (my_futimesat_func != NULL)
|
if (my_futimes_func != NULL)
|
||||||
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES;
|
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES;
|
||||||
if (my_lutimes_func != NULL)
|
if (my_lutimes_func != NULL)
|
||||||
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES;
|
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES;
|
||||||
@ -417,7 +417,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
|
|||||||
|
|
||||||
if (my_openat_func != NULL && my_fstatat_func != NULL &&
|
if (my_openat_func != NULL && my_fstatat_func != NULL &&
|
||||||
my_unlinkat_func != NULL && my_renameat_func != NULL &&
|
my_unlinkat_func != NULL && my_renameat_func != NULL &&
|
||||||
my_futimesat_func != NULL && my_fdopendir_func != NULL)
|
my_futimes_func != NULL && my_fdopendir_func != NULL)
|
||||||
{
|
{
|
||||||
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_OPENAT;
|
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_OPENAT;
|
||||||
}
|
}
|
||||||
@ -914,11 +914,11 @@ Java_sun_nio_fs_UnixNativeDispatcher_futimes0(JNIEnv* env, jclass this, jint fil
|
|||||||
#ifdef _ALLBSD_SOURCE
|
#ifdef _ALLBSD_SOURCE
|
||||||
RESTARTABLE(futimes(filedes, ×[0]), err);
|
RESTARTABLE(futimes(filedes, ×[0]), err);
|
||||||
#else
|
#else
|
||||||
if (my_futimesat_func == NULL) {
|
if (my_futimes_func == NULL) {
|
||||||
JNU_ThrowInternalError(env, "my_futimesat_func is NULL");
|
JNU_ThrowInternalError(env, "my_futimes_func is NULL");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RESTARTABLE((*my_futimesat_func)(filedes, NULL, ×[0]), err);
|
RESTARTABLE((*my_futimes_func)(filedes, ×[0]), err);
|
||||||
#endif
|
#endif
|
||||||
if (err == -1) {
|
if (err == -1) {
|
||||||
throwUnixException(env, errno);
|
throwUnixException(env, errno);
|
||||||
|
@ -22,8 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 4313887 6838333
|
* @bug 4313887 6838333 8343020
|
||||||
* @summary Unit test for java.nio.file.SecureDirectoryStream
|
* @summary Unit test for java.nio.file.SecureDirectoryStream
|
||||||
|
* @requires (os.family == "linux" | os.family == "mac")
|
||||||
* @library ..
|
* @library ..
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -45,11 +46,7 @@ public class SecureDS {
|
|||||||
DirectoryStream<Path> stream = newDirectoryStream(dir);
|
DirectoryStream<Path> stream = newDirectoryStream(dir);
|
||||||
stream.close();
|
stream.close();
|
||||||
if (!(stream instanceof SecureDirectoryStream)) {
|
if (!(stream instanceof SecureDirectoryStream)) {
|
||||||
if (System.getProperty("os.name").equals("Linux"))
|
throw new AssertionError("SecureDirectoryStream not supported.");
|
||||||
throw new AssertionError(
|
|
||||||
"SecureDirectoryStream not supported.");
|
|
||||||
System.out.println("SecureDirectoryStream not supported.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
supportsSymbolicLinks = TestUtil.supportsSymbolicLinks(dir);
|
supportsSymbolicLinks = TestUtil.supportsSymbolicLinks(dir);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user