mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8278356: Improve file creation
Reviewed-by: alanb, rhalade
This commit is contained in:
parent
ee0743801e
commit
395bb5b7f9
4 changed files with 61 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 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
|
||||
|
@ -26,6 +26,7 @@
|
|||
package java.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.BitSet;
|
||||
import java.util.Locale;
|
||||
|
@ -45,6 +46,21 @@ class WinNTFileSystem extends FileSystem {
|
|||
private final char semicolon;
|
||||
private final String userDir;
|
||||
|
||||
// Whether to enable alternative data streams (ADS) by suppressing
|
||||
// checking the path for invalid characters, in particular ":".
|
||||
// ADS support will be enabled if and only if the property is set and
|
||||
// is the empty string or is equal, ignoring case, to the string "true".
|
||||
// By default ADS support is disabled.
|
||||
private static final boolean ENABLE_ADS;
|
||||
static {
|
||||
String enableADS = GetPropertyAction.privilegedGetProperty("jdk.io.File.enableADS");
|
||||
if (enableADS != null) {
|
||||
ENABLE_ADS = "".equals(enableADS) || Boolean.parseBoolean(enableADS);
|
||||
} else {
|
||||
ENABLE_ADS = false;
|
||||
}
|
||||
}
|
||||
|
||||
public WinNTFileSystem() {
|
||||
Properties props = GetPropertyAction.privilegedGetProperties();
|
||||
slash = props.getProperty("file.separator").charAt(0);
|
||||
|
@ -305,6 +321,33 @@ class WinNTFileSystem extends FileSystem {
|
|||
|| (pl == 3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvalid(File f) {
|
||||
if (f.getPath().indexOf('\u0000') >= 0)
|
||||
return true;
|
||||
|
||||
if (ENABLE_ADS)
|
||||
return false;
|
||||
|
||||
// Invalid if there is a ":" at a position greater than 1, or if there
|
||||
// is a ":" at position 1 and the first character is not a letter
|
||||
String pathname = f.getPath();
|
||||
int lastColon = pathname.lastIndexOf(":");
|
||||
if (lastColon > 1 ||
|
||||
(lastColon == 1 && !isLetter(pathname.charAt(0))))
|
||||
return true;
|
||||
|
||||
// Invalid if path creation fails
|
||||
Path path = null;
|
||||
try {
|
||||
path = sun.nio.fs.DefaultFileSystemProvider.theFileSystem().getPath(pathname);
|
||||
return false;
|
||||
} catch (InvalidPathException ignored) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolve(File f) {
|
||||
String path = f.getPath();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue