mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-29 00:02:34 +00:00
8366911: (fs) Remove support for normalizing file names to Unicode normalized form D (macOS)
Reviewed-by: alanb
This commit is contained in:
parent
8b92af7d4a
commit
7603e96fa2
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2025, 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
|
||||
@ -27,26 +27,12 @@ package sun.nio.fs;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static sun.nio.fs.MacOSXNativeDispatcher.*;
|
||||
|
||||
/**
|
||||
* MacOS implementation of FileSystem
|
||||
*/
|
||||
|
||||
class MacOSXFileSystem extends BsdFileSystem {
|
||||
|
||||
private static final String PROPERTY_NORMALIZE_FILE_PATHS =
|
||||
"jdk.nio.path.useNormalizationFormD";
|
||||
|
||||
private static final boolean NORMALIZE_FILE_PATHS;
|
||||
|
||||
static {
|
||||
final String name = PROPERTY_NORMALIZE_FILE_PATHS;
|
||||
String value = System.getProperty(name);
|
||||
NORMALIZE_FILE_PATHS = (value != null)
|
||||
&& ("".equals(value) || Boolean.parseBoolean(value));
|
||||
}
|
||||
|
||||
MacOSXFileSystem(UnixFileSystemProvider provider, String dir) {
|
||||
super(provider, dir);
|
||||
}
|
||||
@ -59,30 +45,4 @@ class MacOSXFileSystem extends BsdFileSystem {
|
||||
Pattern compilePathMatchPattern(String expr) {
|
||||
return Pattern.compile(expr, Pattern.CANON_EQ) ;
|
||||
}
|
||||
|
||||
@Override
|
||||
String normalizeNativePath(String path) {
|
||||
if (NORMALIZE_FILE_PATHS) {
|
||||
for (int i = 0; i < path.length(); i++) {
|
||||
char c = path.charAt(i);
|
||||
if (c > 0x80)
|
||||
return new String(normalizepath(path.toCharArray(),
|
||||
kCFStringNormalizationFormD));
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
String normalizeJavaPath(String path) {
|
||||
if (NORMALIZE_FILE_PATHS) {
|
||||
for (int i = 0; i < path.length(); i++) {
|
||||
if (path.charAt(i) > 0x80)
|
||||
return new String(normalizepath(path.toCharArray(),
|
||||
kCFStringNormalizationFormC));
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2021, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.nio.fs;
|
||||
|
||||
/**
|
||||
* MacOSX specific system calls.
|
||||
*/
|
||||
|
||||
class MacOSXNativeDispatcher extends BsdNativeDispatcher {
|
||||
private MacOSXNativeDispatcher() { }
|
||||
|
||||
static final int kCFStringNormalizationFormC = 2;
|
||||
static final int kCFStringNormalizationFormD = 0;
|
||||
static native char[] normalizepath(char[] path, int form);
|
||||
}
|
||||
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include "jni.h"
|
||||
#include "jni_util.h"
|
||||
#include "jvm.h"
|
||||
#include "jlong.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
JNIEXPORT jcharArray JNICALL
|
||||
Java_sun_nio_fs_MacOSXNativeDispatcher_normalizepath(JNIEnv* env, jclass this,
|
||||
jcharArray path,
|
||||
jint form)
|
||||
{
|
||||
jcharArray result = NULL;
|
||||
char *chars;
|
||||
CFMutableStringRef csref = CFStringCreateMutable(NULL, 0);
|
||||
if (csref == NULL) {
|
||||
JNU_ThrowOutOfMemoryError(env, "native heap");
|
||||
return NULL;
|
||||
}
|
||||
chars = (char*)(*env)->GetPrimitiveArrayCritical(env, path, 0);
|
||||
if (chars != NULL) {
|
||||
char chars_buf[(PATH_MAX + 1) * 2]; // utf16 + zero padding
|
||||
jsize len = (*env)->GetArrayLength(env, path);
|
||||
CFStringAppendCharacters(csref, (const UniChar*)chars, len);
|
||||
(*env)->ReleasePrimitiveArrayCritical(env, path, chars, 0);
|
||||
CFStringNormalize(csref, form);
|
||||
len = CFStringGetLength(csref);
|
||||
if (len < PATH_MAX) {
|
||||
if (CFStringGetCString(csref, chars_buf, sizeof(chars_buf), kCFStringEncodingUTF16)) {
|
||||
result = (*env)->NewCharArray(env, len);
|
||||
if (result != NULL) {
|
||||
(*env)->SetCharArrayRegion(env, result, 0, len, (jchar*)&chars_buf);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int ulen = (len + 1) * 2;
|
||||
chars = malloc(ulen);
|
||||
if (chars == NULL) {
|
||||
JNU_ThrowOutOfMemoryError(env, "native heap");
|
||||
} else {
|
||||
if (CFStringGetCString(csref, chars, ulen, kCFStringEncodingUTF16)) {
|
||||
result = (*env)->NewCharArray(env, len);
|
||||
if (result != NULL) {
|
||||
(*env)->SetCharArrayRegion(env, result, 0, len, (jchar*)chars);
|
||||
}
|
||||
}
|
||||
free(chars);
|
||||
}
|
||||
}
|
||||
}
|
||||
CFRelease(csref);
|
||||
return result;
|
||||
}
|
||||
@ -337,20 +337,6 @@ abstract class UnixFileSystem
|
||||
return Pattern.compile(expr);
|
||||
}
|
||||
|
||||
// Override if the platform uses different Unicode normalization form
|
||||
// for native file path. For example on MacOSX, the native path is stored
|
||||
// in Unicode NFD form.
|
||||
String normalizeNativePath(String path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
// Override if the native file path use non-NFC form. For example on MacOSX,
|
||||
// the native path is stored in Unicode NFD form, the path need to be
|
||||
// normalized back to NFC before passed back to Java level.
|
||||
String normalizeJavaPath(String path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
// Unix implementation of Files#copy and Files#move methods.
|
||||
|
||||
// calculate the least common multiple of two values;
|
||||
|
||||
@ -42,6 +42,7 @@ import java.util.Objects;
|
||||
import jdk.internal.access.JavaLangAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.util.ArraysSupport;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import static sun.nio.fs.UnixConstants.*;
|
||||
import static sun.nio.fs.UnixNativeDispatcher.*;
|
||||
@ -59,7 +60,7 @@ class UnixPath implements Path {
|
||||
private final byte[] path;
|
||||
|
||||
// String representation (created lazily, no need to be volatile)
|
||||
private String stringValue;
|
||||
private @Stable String stringValue;
|
||||
|
||||
// cached hashcode (created lazily, no need to be volatile)
|
||||
private int hash;
|
||||
@ -124,7 +125,6 @@ class UnixPath implements Path {
|
||||
|
||||
// encodes the given path-string into a sequence of bytes
|
||||
private static byte[] encode(UnixFileSystem fs, String input) {
|
||||
input = fs.normalizeNativePath(input);
|
||||
try {
|
||||
return JLA.uncheckedGetBytesOrThrow(input, Util.jnuEncoding());
|
||||
} catch (CharacterCodingException cce) {
|
||||
@ -814,7 +814,7 @@ class UnixPath implements Path {
|
||||
// OK if two or more threads create a String
|
||||
String stringValue = this.stringValue;
|
||||
if (stringValue == null) {
|
||||
this.stringValue = stringValue = fs.normalizeJavaPath(Util.toString(path)); // platform encoding
|
||||
this.stringValue = stringValue = Util.toString(path); // platform encoding
|
||||
}
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2025, 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
|
||||
@ -21,20 +21,30 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 7130915 8289689 8366911
|
||||
* @summary Tests file path names with standard encoding on macOS
|
||||
* @requires (os.family == "mac")
|
||||
* @library /test/lib ..
|
||||
* @build jdk.test.lib.Utils
|
||||
* jdk.test.lib.Asserts
|
||||
* jdk.test.lib.JDKToolFinder
|
||||
* jdk.test.lib.JDKToolLauncher
|
||||
* jdk.test.lib.Platform
|
||||
* jdk.test.lib.process.*
|
||||
* TestUtil MacPath
|
||||
* @run main MacPath
|
||||
*/
|
||||
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.text.Normalizer;
|
||||
import java.text.Normalizer.Form;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class MacPath {
|
||||
private static final String PROPERTY_NORMALIZE_FILE_PATHS =
|
||||
"jdk.nio.path.useNormalizationFormD";
|
||||
|
||||
public static void main(String args[]) throws Throwable {
|
||||
System.out.printf("sun.jnu.encoding=%s, file.encoding=%s%n",
|
||||
System.getProperty("file.encoding"),
|
||||
@ -83,11 +93,8 @@ public class MacPath {
|
||||
private static void test(String testdir, String dname, String fname_nfc)
|
||||
throws Throwable
|
||||
{
|
||||
String fname = null;
|
||||
Normalizer.Form form = Boolean.getBoolean(PROPERTY_NORMALIZE_FILE_PATHS)
|
||||
? Normalizer.Form.NFD : Normalizer.Form.NFC;
|
||||
String dname_nfd = Normalizer.normalize(dname, form);
|
||||
String fname_nfd = Normalizer.normalize(fname_nfc, form);
|
||||
String dname_nfd = dname;
|
||||
String fname_nfd = fname_nfc;
|
||||
|
||||
System.out.printf("%n%n--------Testing...----------%n");
|
||||
Path bpath = Paths.get(testdir);
|
||||
@ -100,7 +107,7 @@ public class MacPath {
|
||||
TestUtil.removeAll(bpath);
|
||||
Files.createDirectories(dpath);
|
||||
|
||||
fname = dpath.toString();
|
||||
String fname = dpath.toString();
|
||||
System.out.printf(":Directory [%s][len=%d] created%n", fname, fname.length());
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
@ -142,9 +149,9 @@ public class MacPath {
|
||||
found_file_nfd |= match(fpath_nfd, path);
|
||||
}
|
||||
}
|
||||
if (!found_dir || !found_file_nfc || !found_file_nfd) {
|
||||
if (!found_dir || !found_file_nfc || !found_file_nfd)
|
||||
throw new RuntimeException("File.equal() failed");
|
||||
}
|
||||
|
||||
// glob
|
||||
String glob = "*" + fname_nfd.substring(2); // remove leading "FI" from "FILE..."
|
||||
System.out.println("glob=" + glob);
|
||||
|
||||
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 7130915 8289689
|
||||
* @summary Tests file path with nfc/nfd forms on MacOSX
|
||||
* @requires (os.family == "mac")
|
||||
* @library /test/lib ..
|
||||
* @build jdk.test.lib.Utils
|
||||
* jdk.test.lib.Asserts
|
||||
* jdk.test.lib.JDKToolFinder
|
||||
* jdk.test.lib.JDKToolLauncher
|
||||
* jdk.test.lib.Platform
|
||||
* jdk.test.lib.process.*
|
||||
* TestUtil MacPath
|
||||
* @run main MacPathTest
|
||||
* @run main/othervm -Djdk.nio.path.useNormalizationFormD=true MacPathTest
|
||||
*/
|
||||
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
|
||||
public class MacPathTest {
|
||||
private static final String PROPERTY_NORMALIZE_FILE_PATHS =
|
||||
"jdk.nio.path.useNormalizationFormD";
|
||||
private static final boolean NORMALIZE_FILE_PATHS =
|
||||
Boolean.getBoolean(PROPERTY_NORMALIZE_FILE_PATHS);
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
ProcessBuilder pb;
|
||||
if (NORMALIZE_FILE_PATHS) {
|
||||
String option = "-D" + PROPERTY_NORMALIZE_FILE_PATHS + "=true";
|
||||
pb = ProcessTools.createTestJavaProcessBuilder(option, MacPath.class.getName());
|
||||
} else {
|
||||
pb = ProcessTools.createTestJavaProcessBuilder(MacPath.class.getName());
|
||||
}
|
||||
pb.environment().put("LC_ALL", "en_US.UTF-8");
|
||||
ProcessTools.executeProcess(pb)
|
||||
.outputTo(System.out)
|
||||
.errorTo(System.err)
|
||||
.shouldHaveExitValue(0);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user