8220793: (fs) No support for changing modification time of symlink

Reviewed-by: alanb, rriggs
This commit is contained in:
Brian Burkhalter 2019-05-02 13:25:00 -07:00
parent 8e1bb92b09
commit 2c35825433
4 changed files with 207 additions and 14 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -73,15 +73,23 @@ class UnixFileAttributeViews {
boolean haveFd = false;
boolean useFutimes = false;
boolean useLutimes = false;
int fd = -1;
try {
fd = file.openForAttributeAccess(followLinks);
if (fd != -1) {
haveFd = true;
useFutimes = futimesSupported();
if (!followLinks) {
useLutimes = lutimesSupported() &&
UnixFileAttributes.get(file, false).isSymbolicLink();
}
if (!useLutimes) {
fd = file.openForAttributeAccess(followLinks);
if (fd != -1) {
haveFd = true;
useFutimes = futimesSupported();
}
}
} catch (UnixException x) {
if (x.errno() != UnixConstants.ENXIO) {
if (!(x.errno() == UnixConstants.ENXIO ||
(x.errno() == UnixConstants.ELOOP && useLutimes))) {
x.rethrowAsIOException(file);
}
}
@ -112,6 +120,8 @@ class UnixFileAttributeViews {
try {
if (useFutimes) {
futimes(fd, accessValue, modValue);
} else if (useLutimes) {
lutimes(file, accessValue, modValue);
} else {
utimes(file, accessValue, modValue);
}
@ -131,6 +141,8 @@ class UnixFileAttributeViews {
try {
if (useFutimes) {
futimes(fd, accessValue, modValue);
} else if (useLutimes) {
lutimes(file, accessValue, modValue);
} else {
utimes(file, accessValue, modValue);
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -401,7 +401,7 @@ class UnixNativeDispatcher {
static native void fchmod(int fd, int mode) throws UnixException;
/**
* utimes(conar char* path, const struct timeval times[2])
* utimes(const char* path, const struct timeval times[2])
*/
static void utimes(UnixPath path, long times0, long times1)
throws UnixException
@ -417,10 +417,26 @@ class UnixNativeDispatcher {
throws UnixException;
/**
* futimes(int fildes,, const struct timeval times[2])
* futimes(int fildes, const struct timeval times[2])
*/
static native void futimes(int fd, long times0, long times1) throws UnixException;
/**
* lutimes(const char* path, const struct timeval times[2])
*/
static void lutimes(UnixPath path, long times0, long times1)
throws UnixException
{
NativeBuffer buffer = copyToNativeBuffer(path);
try {
lutimes0(buffer.address(), times0, times1);
} finally {
buffer.release();
}
}
private static native void lutimes0(long pathAddress, long times0, long times1)
throws UnixException;
/**
* DIR *opendir(const char* dirname)
*/
@ -578,9 +594,10 @@ class UnixNativeDispatcher {
/**
* Capabilities
*/
private static final int SUPPORTS_OPENAT = 1 << 1; // syscalls
private static final int SUPPORTS_OPENAT = 1 << 1; // syscalls
private static final int SUPPORTS_FUTIMES = 1 << 2;
private static final int SUPPORTS_BIRTHTIME = 1 << 16; // other features
private static final int SUPPORTS_LUTIMES = 1 << 4;
private static final int SUPPORTS_BIRTHTIME = 1 << 16; // other features
private static final int capabilities;
/**
@ -597,6 +614,13 @@ class UnixNativeDispatcher {
return (capabilities & SUPPORTS_FUTIMES) != 0;
}
/**
* Supports lutimes
*/
static boolean lutimesSupported() {
return (capabilities & SUPPORTS_LUTIMES) != 0;
}
/**
* Supports file birth (creation) time attribute
*/