8305664: [BACKOUT] (fs) Remove FileSystem support for resolving against a default directory (chdir configuration)
Reviewed-by: alanb
This commit is contained in:
parent
39f12a88e7
commit
507c49a3ab
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2013, 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) {
|
||||
super(provider);
|
||||
AixFileSystem(UnixFileSystemProvider provider, String dir) {
|
||||
super(provider, dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2013, 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() {
|
||||
return new AixFileSystem(this);
|
||||
AixFileSystem newFileSystem(String dir) {
|
||||
return new AixFileSystem(this, dir);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, 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) {
|
||||
super(provider);
|
||||
LinuxFileSystem(UnixFileSystemProvider provider, String dir) {
|
||||
super(provider, dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2018, 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() {
|
||||
return new LinuxFileSystem(this);
|
||||
LinuxFileSystem newFileSystem(String dir) {
|
||||
return new LinuxFileSystem(this, dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, 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) {
|
||||
super(provider);
|
||||
BsdFileSystem(UnixFileSystemProvider provider, String dir) {
|
||||
super(provider, dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, 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() {
|
||||
return new BsdFileSystem(this);
|
||||
BsdFileSystem newFileSystem(String dir) {
|
||||
return new BsdFileSystem(this, dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, 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) {
|
||||
super(provider);
|
||||
MacOSXFileSystem(UnixFileSystemProvider provider, String dir) {
|
||||
super(provider, dir);
|
||||
}
|
||||
|
||||
boolean isCaseInsensitiveAndPreserving() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2018, 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() {
|
||||
return new MacOSXFileSystem(this);
|
||||
MacOSXFileSystem newFileSystem(String dir) {
|
||||
return new MacOSXFileSystem(this, dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,7 +52,6 @@ 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;
|
||||
@ -74,17 +73,39 @@ 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 = StaticProperty.userDir();
|
||||
UnixFileSystem(UnixFileSystemProvider provider, String dir) {
|
||||
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, "/");
|
||||
}
|
||||
@ -94,6 +115,10 @@ abstract class UnixFileSystem
|
||||
return defaultDirectory;
|
||||
}
|
||||
|
||||
boolean needToResolveAgainstDefaultDirectory() {
|
||||
return needToResolveAgainstDefaultDirectory;
|
||||
}
|
||||
|
||||
boolean isCaseInsensitiveAndPreserving() {
|
||||
return false;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, 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();
|
||||
theFileSystem = newFileSystem(StaticProperty.userDir());
|
||||
}
|
||||
|
||||
UnixFileSystem theFileSystem() {
|
||||
@ -83,9 +83,9 @@ public abstract class UnixFileSystemProvider
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new file system.
|
||||
* Constructs a new file system using the given default directory.
|
||||
*/
|
||||
abstract UnixFileSystem newFileSystem();
|
||||
abstract UnixFileSystem newFileSystem(String dir);
|
||||
|
||||
@Override
|
||||
public final String getScheme() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, 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,6 +52,11 @@ class UnixNativeDispatcher {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* char *getcwd(char *buf, size_t size);
|
||||
*/
|
||||
static native byte[] getcwd();
|
||||
|
||||
/**
|
||||
* int dup(int filedes)
|
||||
*/
|
||||
|
@ -138,12 +138,18 @@ class UnixPath implements Path {
|
||||
|
||||
// use this path when making system/library calls
|
||||
byte[] getByteArrayForSysCalls() {
|
||||
if (!isEmpty()) {
|
||||
return path;
|
||||
// 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);
|
||||
} else {
|
||||
// empty path case will access current directory
|
||||
byte[] here = { '.' };
|
||||
return here;
|
||||
if (!isEmpty()) {
|
||||
return path;
|
||||
} else {
|
||||
// empty path case will access current directory
|
||||
byte[] here = { '.' };
|
||||
return here;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,7 +160,11 @@ class UnixPath implements Path {
|
||||
|
||||
// use this path for permission checks
|
||||
String getPathForPermissionCheck() {
|
||||
return toString();
|
||||
if (getFileSystem().needToResolveAgainstDefaultDirectory()) {
|
||||
return Util.toString(getByteArrayForSysCalls());
|
||||
} else {
|
||||
return toString();
|
||||
}
|
||||
}
|
||||
|
||||
// Checks that the given file is a UnixPath
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, 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,6 +324,25 @@ 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)
|
||||
{
|
||||
|
@ -31,7 +31,6 @@ 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
|
||||
@ -43,11 +42,12 @@ class WindowsFileSystem
|
||||
private final String defaultRoot;
|
||||
|
||||
// package-private
|
||||
WindowsFileSystem(WindowsFileSystemProvider provider) {
|
||||
WindowsFileSystem(WindowsFileSystemProvider provider,
|
||||
String dir)
|
||||
{
|
||||
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) &&
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, 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,6 +33,7 @@ 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;
|
||||
|
||||
@ -48,7 +49,7 @@ class WindowsFileSystemProvider
|
||||
private final WindowsFileSystem theFileSystem;
|
||||
|
||||
public WindowsFileSystemProvider() {
|
||||
theFileSystem = new WindowsFileSystem(this);
|
||||
theFileSystem = new WindowsFileSystem(this, StaticProperty.userDir());
|
||||
}
|
||||
|
||||
WindowsFileSystem theFileSystem() {
|
||||
|
Loading…
Reference in New Issue
Block a user