8202110: (fs) Remove FileSystem support for resolving against a default directory (chdir configuration)

Reviewed-by: alanb
This commit is contained in:
Brian Burkhalter 2023-03-30 16:44:01 +00:00
parent d2df36b073
commit 05cc02b243
15 changed files with 44 additions and 104 deletions

View file

@ -52,6 +52,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import jdk.internal.misc.Blocker;
import jdk.internal.util.StaticProperty;
import sun.nio.ch.DirectBuffer;
import sun.nio.ch.IOStatus;
import sun.security.action.GetPropertyAction;
@ -73,39 +74,17 @@ abstract class UnixFileSystem
private final UnixFileSystemProvider provider;
private final byte[] defaultDirectory;
private final boolean needToResolveAgainstDefaultDirectory;
private final UnixPath rootDirectory;
// package-private
UnixFileSystem(UnixFileSystemProvider provider, String dir) {
UnixFileSystem(UnixFileSystemProvider provider) {
String dir = StaticProperty.userDir();
this.provider = provider;
this.defaultDirectory = Util.toBytes(UnixPath.normalizeAndCheck(dir));
if (this.defaultDirectory[0] != '/') {
throw new RuntimeException("default directory must be absolute");
}
// if process-wide chdir is allowed or default directory is not the
// process working directory then paths must be resolved against the
// default directory.
String propValue = GetPropertyAction
.privilegedGetProperty("sun.nio.fs.chdirAllowed", "false");
boolean chdirAllowed = propValue.isEmpty() ? true : Boolean.parseBoolean(propValue);
if (chdirAllowed) {
this.needToResolveAgainstDefaultDirectory = true;
} else {
byte[] cwd = UnixNativeDispatcher.getcwd();
boolean defaultIsCwd = (cwd.length == defaultDirectory.length);
if (defaultIsCwd) {
for (int i=0; i<cwd.length; i++) {
if (cwd[i] != defaultDirectory[i]) {
defaultIsCwd = false;
break;
}
}
}
this.needToResolveAgainstDefaultDirectory = !defaultIsCwd;
}
// the root directory
this.rootDirectory = new UnixPath(this, "/");
}
@ -115,10 +94,6 @@ abstract class UnixFileSystem
return defaultDirectory;
}
boolean needToResolveAgainstDefaultDirectory() {
return needToResolveAgainstDefaultDirectory;
}
boolean isCaseInsensitiveAndPreserving() {
return false;
}