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

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -38,8 +38,8 @@ import static sun.nio.fs.AixNativeDispatcher.*;
class AixFileSystem extends UnixFileSystem {
AixFileSystem(UnixFileSystemProvider provider, String dir) {
super(provider, dir);
AixFileSystem(UnixFileSystemProvider provider) {
super(provider);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -38,8 +38,8 @@ class AixFileSystemProvider extends UnixFileSystemProvider {
}
@Override
AixFileSystem newFileSystem(String dir) {
return new AixFileSystem(this, dir);
AixFileSystem newFileSystem() {
return new AixFileSystem(this);
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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
@ -41,8 +41,8 @@ import static sun.nio.fs.UnixConstants.*;
*/
class LinuxFileSystem extends UnixFileSystem {
LinuxFileSystem(UnixFileSystemProvider provider, String dir) {
super(provider, dir);
LinuxFileSystem(UnixFileSystemProvider provider) {
super(provider);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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
@ -42,8 +42,8 @@ class LinuxFileSystemProvider extends UnixFileSystemProvider {
}
@Override
LinuxFileSystem newFileSystem(String dir) {
return new LinuxFileSystem(this, dir);
LinuxFileSystem newFileSystem() {
return new LinuxFileSystem(this);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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
@ -46,8 +46,8 @@ import static sun.nio.fs.UnixNativeDispatcher.unlink;
class BsdFileSystem extends UnixFileSystem {
BsdFileSystem(UnixFileSystemProvider provider, String dir) {
super(provider, dir);
BsdFileSystem(UnixFileSystemProvider provider) {
super(provider);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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
@ -39,8 +39,8 @@ class BsdFileSystemProvider extends UnixFileSystemProvider {
}
@Override
BsdFileSystem newFileSystem(String dir) {
return new BsdFileSystem(this, dir);
BsdFileSystem newFileSystem() {
return new BsdFileSystem(this);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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
@ -48,8 +48,8 @@ class MacOSXFileSystem extends BsdFileSystem {
&& ("".equals(value) || Boolean.parseBoolean(value));
}
MacOSXFileSystem(UnixFileSystemProvider provider, String dir) {
super(provider, dir);
MacOSXFileSystem(UnixFileSystemProvider provider) {
super(provider);
}
boolean isCaseInsensitiveAndPreserving() {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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
@ -40,8 +40,8 @@ class MacOSXFileSystemProvider extends BsdFileSystemProvider {
}
@Override
MacOSXFileSystem newFileSystem(String dir) {
return new MacOSXFileSystem(this, dir);
MacOSXFileSystem newFileSystem() {
return new MacOSXFileSystem(this);
}
@Override

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;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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
@ -75,7 +75,7 @@ public abstract class UnixFileSystemProvider
private final UnixFileSystem theFileSystem;
public UnixFileSystemProvider() {
theFileSystem = newFileSystem(StaticProperty.userDir());
theFileSystem = newFileSystem();
}
UnixFileSystem theFileSystem() {
@ -83,9 +83,9 @@ public abstract class UnixFileSystemProvider
}
/**
* Constructs a new file system using the given default directory.
* Constructs a new file system.
*/
abstract UnixFileSystem newFileSystem(String dir);
abstract UnixFileSystem newFileSystem();
@Override
public final String getScheme() {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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
@ -52,11 +52,6 @@ class UnixNativeDispatcher {
return buffer;
}
/**
* char *getcwd(char *buf, size_t size);
*/
static native byte[] getcwd();
/**
* int dup(int filedes)
*/

View File

@ -138,18 +138,12 @@ class UnixPath implements Path {
// use this path when making system/library calls
byte[] getByteArrayForSysCalls() {
// resolve against default directory if required (chdir allowed or
// file system default directory is not working directory)
if (getFileSystem().needToResolveAgainstDefaultDirectory()) {
return resolve(getFileSystem().defaultDirectory(), path);
if (!isEmpty()) {
return path;
} else {
if (!isEmpty()) {
return path;
} else {
// empty path case will access current directory
byte[] here = { '.' };
return here;
}
// empty path case will access current directory
byte[] here = { '.' };
return here;
}
}
@ -160,11 +154,7 @@ class UnixPath implements Path {
// use this path for permission checks
String getPathForPermissionCheck() {
if (getFileSystem().needToResolveAgainstDefaultDirectory()) {
return Util.toString(getByteArrayForSysCalls());
} else {
return toString();
}
return toString();
}
// Checks that the given file is a UnixPath

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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
@ -324,25 +324,6 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
return capabilities;
}
JNIEXPORT jbyteArray JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_getcwd(JNIEnv* env, jclass this) {
jbyteArray result = NULL;
char buf[PATH_MAX+1];
/* EINTR not listed as a possible error */
char* cwd = getcwd(buf, sizeof(buf));
if (cwd == NULL) {
throwUnixException(env, errno);
} else {
jsize len = (jsize)strlen(buf);
result = (*env)->NewByteArray(env, len);
if (result != NULL) {
(*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)buf);
}
}
return result;
}
JNIEXPORT jbyteArray
Java_sun_nio_fs_UnixNativeDispatcher_strerror(JNIEnv* env, jclass this, jint error)
{

View File

@ -31,6 +31,7 @@ import java.nio.file.spi.*;
import java.util.*;
import java.util.regex.Pattern;
import java.io.IOException;
import jdk.internal.util.StaticProperty;
class WindowsFileSystem
extends FileSystem
@ -42,12 +43,11 @@ class WindowsFileSystem
private final String defaultRoot;
// package-private
WindowsFileSystem(WindowsFileSystemProvider provider,
String dir)
{
WindowsFileSystem(WindowsFileSystemProvider provider) {
this.provider = provider;
// parse default directory and check it is absolute
String dir = StaticProperty.userDir();
WindowsPathParser.Result result = WindowsPathParser.parse(dir);
if ((result.type() != WindowsPathType.ABSOLUTE) &&

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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
@ -33,7 +33,6 @@ import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.io.*;
import java.util.*;
import jdk.internal.util.StaticProperty;
import sun.nio.ch.ThreadPool;
import sun.security.util.SecurityConstants;
@ -49,7 +48,7 @@ class WindowsFileSystemProvider
private final WindowsFileSystem theFileSystem;
public WindowsFileSystemProvider() {
theFileSystem = new WindowsFileSystem(this, StaticProperty.userDir());
theFileSystem = new WindowsFileSystem(this);
}
WindowsFileSystem theFileSystem() {