8032220: Files.createDirectories throws exception with confusing message for root directories that exist
Reviewed-by: chegar
This commit is contained in:
parent
65bdf9f853
commit
c276ce4f08
@ -752,9 +752,12 @@ public final class Files {
|
|||||||
}
|
}
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
// unable to find existing parent
|
// unable to find existing parent
|
||||||
if (se != null)
|
if (se == null) {
|
||||||
|
throw new FileSystemException(dir.toString(), null,
|
||||||
|
"Unable to determine if root directory exists");
|
||||||
|
} else {
|
||||||
throw se;
|
throw se;
|
||||||
throw new IOException("Root directory does not exist");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create directories
|
// create directories
|
||||||
|
@ -375,11 +375,12 @@ public abstract class UnixFileSystemProvider
|
|||||||
UnixPath dir = UnixPath.toUnixPath(obj);
|
UnixPath dir = UnixPath.toUnixPath(obj);
|
||||||
dir.checkWrite();
|
dir.checkWrite();
|
||||||
|
|
||||||
int mode = UnixFileModeAttribute
|
int mode = UnixFileModeAttribute.toUnixMode(UnixFileModeAttribute.ALL_PERMISSIONS, attrs);
|
||||||
.toUnixMode(UnixFileModeAttribute.ALL_PERMISSIONS, attrs);
|
|
||||||
try {
|
try {
|
||||||
mkdir(dir, mode);
|
mkdir(dir, mode);
|
||||||
} catch (UnixException x) {
|
} catch (UnixException x) {
|
||||||
|
if (x.errno() == EISDIR)
|
||||||
|
throw new FileAlreadyExistsException(dir.toString());
|
||||||
x.rethrowAsIOException(dir);
|
x.rethrowAsIOException(dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -493,6 +493,14 @@ public class WindowsFileSystemProvider
|
|||||||
try {
|
try {
|
||||||
CreateDirectory(dir.getPathForWin32Calls(), sd.address());
|
CreateDirectory(dir.getPathForWin32Calls(), sd.address());
|
||||||
} catch (WindowsException x) {
|
} catch (WindowsException x) {
|
||||||
|
// convert ERROR_ACCESS_DENIED to FileAlreadyExistsException if we can
|
||||||
|
// verify that the directory exists
|
||||||
|
if (x.lastError() == ERROR_ACCESS_DENIED) {
|
||||||
|
try {
|
||||||
|
if (WindowsFileAttributes.get(dir, false).isDirectory())
|
||||||
|
throw new FileAlreadyExistsException(dir.toString());
|
||||||
|
} catch (WindowsException ignore) { }
|
||||||
|
}
|
||||||
x.rethrowAsIOException(dir);
|
x.rethrowAsIOException(dir);
|
||||||
} finally {
|
} finally {
|
||||||
sd.release();
|
sd.release();
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 4313887 6838333 8005566
|
* @bug 4313887 6838333 8005566 8032220
|
||||||
* @summary Unit test for miscellenous methods in java.nio.file.Files
|
* @summary Unit test for miscellenous methods in java.nio.file.Files
|
||||||
* @library ..
|
* @library ..
|
||||||
*/
|
*/
|
||||||
@ -76,6 +76,11 @@ public class Misc {
|
|||||||
createDirectories(file.resolve("y"));
|
createDirectories(file.resolve("y"));
|
||||||
throw new RuntimeException("failure expected");
|
throw new RuntimeException("failure expected");
|
||||||
} catch (IOException x) { }
|
} catch (IOException x) { }
|
||||||
|
|
||||||
|
// the root directory always exists
|
||||||
|
Path root = Paths.get("/");
|
||||||
|
Files.createDirectories(root);
|
||||||
|
Files.createDirectories(root.toAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user