Skip to content

Commit 507c49a

Browse files
author
Brian Burkhalter
committed
8305664: [BACKOUT] (fs) Remove FileSystem support for resolving against a default directory (chdir configuration)
Reviewed-by: alanb
1 parent 39f12a8 commit 507c49a

File tree

15 files changed

+104
-44
lines changed

15 files changed

+104
-44
lines changed

src/java.base/aix/classes/sun/nio/fs/AixFileSystem.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2013 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -38,8 +38,8 @@
3838

3939
class AixFileSystem extends UnixFileSystem {
4040

41-
AixFileSystem(UnixFileSystemProvider provider) {
42-
super(provider);
41+
AixFileSystem(UnixFileSystemProvider provider, String dir) {
42+
super(provider, dir);
4343
}
4444

4545
@Override

src/java.base/aix/classes/sun/nio/fs/AixFileSystemProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2013 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -38,8 +38,8 @@ public AixFileSystemProvider() {
3838
}
3939

4040
@Override
41-
AixFileSystem newFileSystem() {
42-
return new AixFileSystem(this);
41+
AixFileSystem newFileSystem(String dir) {
42+
return new AixFileSystem(this, dir);
4343
}
4444

4545
/**

src/java.base/linux/classes/sun/nio/fs/LinuxFileSystem.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,8 +41,8 @@
4141
*/
4242

4343
class LinuxFileSystem extends UnixFileSystem {
44-
LinuxFileSystem(UnixFileSystemProvider provider) {
45-
super(provider);
44+
LinuxFileSystem(UnixFileSystemProvider provider, String dir) {
45+
super(provider, dir);
4646
}
4747

4848
@Override

src/java.base/linux/classes/sun/nio/fs/LinuxFileSystemProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -42,8 +42,8 @@ public LinuxFileSystemProvider() {
4242
}
4343

4444
@Override
45-
LinuxFileSystem newFileSystem() {
46-
return new LinuxFileSystem(this);
45+
LinuxFileSystem newFileSystem(String dir) {
46+
return new LinuxFileSystem(this, dir);
4747
}
4848

4949
@Override

src/java.base/macosx/classes/sun/nio/fs/BsdFileSystem.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -46,8 +46,8 @@
4646

4747
class BsdFileSystem extends UnixFileSystem {
4848

49-
BsdFileSystem(UnixFileSystemProvider provider) {
50-
super(provider);
49+
BsdFileSystem(UnixFileSystemProvider provider, String dir) {
50+
super(provider, dir);
5151
}
5252

5353
@Override

src/java.base/macosx/classes/sun/nio/fs/BsdFileSystemProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -39,8 +39,8 @@ public BsdFileSystemProvider() {
3939
}
4040

4141
@Override
42-
BsdFileSystem newFileSystem() {
43-
return new BsdFileSystem(this);
42+
BsdFileSystem newFileSystem(String dir) {
43+
return new BsdFileSystem(this, dir);
4444
}
4545

4646
@Override

src/java.base/macosx/classes/sun/nio/fs/MacOSXFileSystem.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -48,8 +48,8 @@ class MacOSXFileSystem extends BsdFileSystem {
4848
&& ("".equals(value) || Boolean.parseBoolean(value));
4949
}
5050

51-
MacOSXFileSystem(UnixFileSystemProvider provider) {
52-
super(provider);
51+
MacOSXFileSystem(UnixFileSystemProvider provider, String dir) {
52+
super(provider, dir);
5353
}
5454

5555
boolean isCaseInsensitiveAndPreserving() {

src/java.base/macosx/classes/sun/nio/fs/MacOSXFileSystemProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,8 +40,8 @@ public MacOSXFileSystemProvider() {
4040
}
4141

4242
@Override
43-
MacOSXFileSystem newFileSystem() {
44-
return new MacOSXFileSystem(this);
43+
MacOSXFileSystem newFileSystem(String dir) {
44+
return new MacOSXFileSystem(this, dir);
4545
}
4646

4747
@Override

src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import java.util.concurrent.TimeUnit;
5353
import java.util.regex.Pattern;
5454
import jdk.internal.misc.Blocker;
55-
import jdk.internal.util.StaticProperty;
5655
import sun.nio.ch.DirectBuffer;
5756
import sun.nio.ch.IOStatus;
5857
import sun.security.action.GetPropertyAction;
@@ -74,17 +73,39 @@ abstract class UnixFileSystem
7473

7574
private final UnixFileSystemProvider provider;
7675
private final byte[] defaultDirectory;
76+
private final boolean needToResolveAgainstDefaultDirectory;
7777
private final UnixPath rootDirectory;
7878

7979
// package-private
80-
UnixFileSystem(UnixFileSystemProvider provider) {
81-
String dir = StaticProperty.userDir();
80+
UnixFileSystem(UnixFileSystemProvider provider, String dir) {
8281
this.provider = provider;
8382
this.defaultDirectory = Util.toBytes(UnixPath.normalizeAndCheck(dir));
8483
if (this.defaultDirectory[0] != '/') {
8584
throw new RuntimeException("default directory must be absolute");
8685
}
8786

87+
// if process-wide chdir is allowed or default directory is not the
88+
// process working directory then paths must be resolved against the
89+
// default directory.
90+
String propValue = GetPropertyAction
91+
.privilegedGetProperty("sun.nio.fs.chdirAllowed", "false");
92+
boolean chdirAllowed = propValue.isEmpty() ? true : Boolean.parseBoolean(propValue);
93+
if (chdirAllowed) {
94+
this.needToResolveAgainstDefaultDirectory = true;
95+
} else {
96+
byte[] cwd = UnixNativeDispatcher.getcwd();
97+
boolean defaultIsCwd = (cwd.length == defaultDirectory.length);
98+
if (defaultIsCwd) {
99+
for (int i=0; i<cwd.length; i++) {
100+
if (cwd[i] != defaultDirectory[i]) {
101+
defaultIsCwd = false;
102+
break;
103+
}
104+
}
105+
}
106+
this.needToResolveAgainstDefaultDirectory = !defaultIsCwd;
107+
}
108+
88109
// the root directory
89110
this.rootDirectory = new UnixPath(this, "/");
90111
}
@@ -94,6 +115,10 @@ byte[] defaultDirectory() {
94115
return defaultDirectory;
95116
}
96117

118+
boolean needToResolveAgainstDefaultDirectory() {
119+
return needToResolveAgainstDefaultDirectory;
120+
}
121+
97122
boolean isCaseInsensitiveAndPreserving() {
98123
return false;
99124
}

src/java.base/unix/classes/sun/nio/fs/UnixFileSystemProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -75,17 +75,17 @@ public abstract class UnixFileSystemProvider
7575
private final UnixFileSystem theFileSystem;
7676

7777
public UnixFileSystemProvider() {
78-
theFileSystem = newFileSystem();
78+
theFileSystem = newFileSystem(StaticProperty.userDir());
7979
}
8080

8181
UnixFileSystem theFileSystem() {
8282
return theFileSystem;
8383
}
8484

8585
/**
86-
* Constructs a new file system.
86+
* Constructs a new file system using the given default directory.
8787
*/
88-
abstract UnixFileSystem newFileSystem();
88+
abstract UnixFileSystem newFileSystem(String dir);
8989

9090
@Override
9191
public final String getScheme() {

0 commit comments

Comments
 (0)