forked from openjdk/jdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8316304: (fs) Add support for BasicFileAttributes.creationTime() for …
…Linux
- Loading branch information
Showing
13 changed files
with
698 additions
and
39 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/java.base/linux/classes/sun/nio/fs/LinuxBasicAttributesView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2023, Red Hat, Inc. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package sun.nio.fs; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
|
||
import sun.nio.fs.UnixFileAttributeViews.Basic; | ||
|
||
class LinuxBasicAttributesView extends Basic { | ||
|
||
LinuxBasicAttributesView(UnixPath file, boolean followLinks) { | ||
super(file, followLinks); | ||
} | ||
|
||
@Override | ||
public BasicFileAttributes readAttributes() throws IOException { | ||
file.checkRead(); | ||
try { | ||
LinuxFileAttributes attrs = | ||
LinuxFileAttributes.get(file, followLinks); | ||
return attrs.asBasicFileAttributes(); | ||
} catch (UnixException x) { | ||
x.rethrowAsIOException(file); | ||
return null; // keep compiler happy | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/java.base/linux/classes/sun/nio/fs/LinuxFileAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) 2023, Red Hat, Inc. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package sun.nio.fs; | ||
|
||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.nio.file.attribute.FileTime; | ||
import java.nio.file.attribute.PosixFileAttributes; | ||
|
||
class LinuxFileAttributes extends UnixFileAttributes implements PosixFileAttributes { | ||
|
||
private final boolean isStatxSupported; | ||
private long stx_birthtime_nsec; | ||
|
||
private LinuxFileAttributes(boolean isStatxSupported) { | ||
this.isStatxSupported = isStatxSupported; | ||
} | ||
|
||
// get the Linux file attributes for a given file | ||
static LinuxFileAttributes get(UnixPath path, boolean followLinks) throws UnixException { | ||
boolean statxSupport = LinuxNativeDispatcher.isStatxSupported(); | ||
LinuxFileAttributes attrs = new LinuxFileAttributes(statxSupport); | ||
if (statxSupport) { | ||
LinuxNativeDispatcher.statx(path, attrs, followLinks); | ||
} else { | ||
// this sets attribute values in attrs | ||
UnixFileAttributes.get(path, followLinks, attrs); | ||
} | ||
return attrs; | ||
} | ||
|
||
// get the LinuxFileAttributes for a given file descriptor | ||
static LinuxFileAttributes get(int fd) throws UnixException { | ||
boolean statxSupport = LinuxNativeDispatcher.isStatxSupported(); | ||
LinuxFileAttributes attrs = new LinuxFileAttributes(statxSupport); | ||
if (statxSupport) { | ||
LinuxNativeDispatcher.statxfd(fd, attrs); | ||
} else { | ||
// this sets attribute values in attrs | ||
UnixFileAttributes.get(fd, attrs); | ||
} | ||
return attrs; | ||
} | ||
|
||
// wrap this object with BasicFileAttributes object to prevent leaking of | ||
// user information | ||
BasicFileAttributes asBasicFileAttributes() { | ||
return UnixAsBasicFileAttributes.wrap(this); | ||
} | ||
|
||
@Override | ||
public FileTime creationTime() { | ||
if (isStatxSupported) { | ||
return UnixFileAttributes.toFileTime(st_birthtime_sec, stx_birthtime_nsec); | ||
} else { | ||
return super.creationTime(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/java.base/linux/classes/sun/nio/fs/LinuxPosixAttributesView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2023, Red Hat, Inc. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package sun.nio.fs; | ||
|
||
import java.io.IOException; | ||
|
||
import sun.nio.fs.UnixFileAttributeViews.Posix; | ||
|
||
class LinuxPosixAttributesView extends Posix { | ||
|
||
LinuxPosixAttributesView(UnixPath file, boolean followLinks) { | ||
super(file, followLinks); | ||
} | ||
|
||
@Override | ||
public UnixFileAttributes readAttributes() throws IOException { | ||
checkReadExtended(); | ||
try { | ||
LinuxFileAttributes attrs = | ||
LinuxFileAttributes.get(file, followLinks); | ||
return attrs; | ||
} catch (UnixException x) { | ||
x.rethrowAsIOException(file); | ||
return null; // keep compiler happy | ||
} | ||
} | ||
} |
Oops, something went wrong.