mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8202110: (fs) Remove FileSystem support for resolving against a default directory (chdir configuration)
Reviewed-by: alanb
This commit is contained in:
parent
d2df36b073
commit
05cc02b243
15 changed files with 44 additions and 104 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue