8221262: Cleanups in UnixFileSystem/WinNTFileSystem implementation classes
Reviewed-by: alanb, igerasim
This commit is contained in:
parent
57bf6a1800
commit
6ede0b6bb8
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 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
|
||||
@ -51,10 +51,12 @@ class UnixFileSystem extends FileSystem {
|
||||
|
||||
/* -- Normalization and construction -- */
|
||||
|
||||
@Override
|
||||
public char getSeparator() {
|
||||
return slash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getPathSeparator() {
|
||||
return colon;
|
||||
}
|
||||
@ -84,6 +86,7 @@ class UnixFileSystem extends FileSystem {
|
||||
/* Check that the given pathname is normal. If not, invoke the real
|
||||
normalizer on the part of the pathname that requires normalization.
|
||||
This way we iterate through the whole pathname string only once. */
|
||||
@Override
|
||||
public String normalize(String pathname) {
|
||||
int n = pathname.length();
|
||||
char prevChar = 0;
|
||||
@ -97,11 +100,13 @@ class UnixFileSystem extends FileSystem {
|
||||
return pathname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int prefixLength(String pathname) {
|
||||
if (pathname.isEmpty()) return 0;
|
||||
return (pathname.charAt(0) == '/') ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolve(String parent, String child) {
|
||||
if (child.isEmpty()) return parent;
|
||||
if (child.charAt(0) == '/') {
|
||||
@ -112,10 +117,12 @@ class UnixFileSystem extends FileSystem {
|
||||
return parent + '/' + child;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultParent() {
|
||||
return "/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fromURIPath(String path) {
|
||||
String p = path;
|
||||
if (p.endsWith("/") && (p.length() > 1)) {
|
||||
@ -128,10 +135,12 @@ class UnixFileSystem extends FileSystem {
|
||||
|
||||
/* -- Path operations -- */
|
||||
|
||||
@Override
|
||||
public boolean isAbsolute(File f) {
|
||||
return (f.getPrefixLength() != 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolve(File f) {
|
||||
if (isAbsolute(f)) return f.getPath();
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
@ -153,6 +162,7 @@ class UnixFileSystem extends FileSystem {
|
||||
// canonicalization algorithm
|
||||
private final ExpiringCache javaHomePrefixCache;
|
||||
|
||||
@Override
|
||||
public String canonicalize(String path) throws IOException {
|
||||
if (!useCanonCaches) {
|
||||
return canonicalize0(path);
|
||||
@ -246,6 +256,7 @@ class UnixFileSystem extends FileSystem {
|
||||
|
||||
public native int getBooleanAttributes0(File f);
|
||||
|
||||
@Override
|
||||
public int getBooleanAttributes(File f) {
|
||||
int rv = getBooleanAttributes0(f);
|
||||
String name = f.getName();
|
||||
@ -253,15 +264,25 @@ class UnixFileSystem extends FileSystem {
|
||||
return rv | (hidden ? BA_HIDDEN : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public native boolean checkAccess(File f, int access);
|
||||
|
||||
@Override
|
||||
public native long getLastModifiedTime(File f);
|
||||
|
||||
@Override
|
||||
public native long getLength(File f);
|
||||
|
||||
@Override
|
||||
public native boolean setPermission(File f, int access, boolean enable, boolean owneronly);
|
||||
|
||||
/* -- File operations -- */
|
||||
|
||||
@Override
|
||||
public native boolean createFileExclusively(String path)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public boolean delete(File f) {
|
||||
// Keep canonicalization caches in sync after file deletion
|
||||
// and renaming operations. Could be more clever than this
|
||||
@ -277,8 +298,14 @@ class UnixFileSystem extends FileSystem {
|
||||
return delete0(f);
|
||||
}
|
||||
private native boolean delete0(File f);
|
||||
|
||||
@Override
|
||||
public native String[] list(File f);
|
||||
|
||||
@Override
|
||||
public native boolean createDirectory(File f);
|
||||
|
||||
@Override
|
||||
public boolean rename(File f1, File f2) {
|
||||
// Keep canonicalization caches in sync after file deletion
|
||||
// and renaming operations. Could be more clever than this
|
||||
@ -294,12 +321,16 @@ class UnixFileSystem extends FileSystem {
|
||||
return rename0(f1, f2);
|
||||
}
|
||||
private native boolean rename0(File f1, File f2);
|
||||
public native boolean setLastModifiedTime(File f, long time);
|
||||
public native boolean setReadOnly(File f);
|
||||
|
||||
@Override
|
||||
public native boolean setLastModifiedTime(File f, long time);
|
||||
|
||||
@Override
|
||||
public native boolean setReadOnly(File f);
|
||||
|
||||
/* -- Filesystem interface -- */
|
||||
|
||||
@Override
|
||||
public File[] listRoots() {
|
||||
try {
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
@ -313,12 +344,15 @@ class UnixFileSystem extends FileSystem {
|
||||
}
|
||||
|
||||
/* -- Disk usage -- */
|
||||
|
||||
@Override
|
||||
public native long getSpace(File f, int t);
|
||||
|
||||
/* -- Basic infrastructure -- */
|
||||
|
||||
private native long getNameMax0(String path);
|
||||
|
||||
@Override
|
||||
public int getNameMax(String path) {
|
||||
long nameMax = getNameMax0(path);
|
||||
if (nameMax > Integer.MAX_VALUE) {
|
||||
@ -327,10 +361,12 @@ class UnixFileSystem extends FileSystem {
|
||||
return (int)nameMax;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(File f1, File f2) {
|
||||
return f1.getPath().compareTo(f2.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(File f) {
|
||||
return f.getPath().hashCode() ^ 1234321;
|
||||
}
|
||||
@ -341,5 +377,4 @@ class UnixFileSystem extends FileSystem {
|
||||
static {
|
||||
initIDs();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -284,10 +284,10 @@ Java_java_io_UnixFileSystem_createFileExclusively(JNIEnv *env, jclass cls,
|
||||
fd = handleOpen(path, O_RDWR | O_CREAT | O_EXCL, 0666);
|
||||
if (fd < 0) {
|
||||
if (errno != EEXIST)
|
||||
JNU_ThrowIOExceptionWithLastError(env, path);
|
||||
JNU_ThrowIOExceptionWithLastError(env, "Could not open file");
|
||||
} else {
|
||||
if (close(fd) == -1)
|
||||
JNU_ThrowIOExceptionWithLastError(env, path);
|
||||
JNU_ThrowIOExceptionWithLastError(env, "Could not close file");
|
||||
rv = JNI_TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 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
|
||||
@ -328,7 +328,6 @@ class WinNTFileSystem extends FileSystem {
|
||||
return up + slashify(path.substring(2));
|
||||
char drive = path.charAt(0);
|
||||
String dir = getDriveDirectory(drive);
|
||||
String np;
|
||||
if (dir != null) {
|
||||
/* When resolving a directory-relative path that refers to a
|
||||
drive other than the current drive, insist that the caller
|
||||
@ -641,6 +640,7 @@ class WinNTFileSystem extends FileSystem {
|
||||
// expects the path to be null or a root component ending in a backslash
|
||||
private native int getNameMax0(String path);
|
||||
|
||||
@Override
|
||||
public int getNameMax(String path) {
|
||||
String s = null;
|
||||
if (path != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user