mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8286160: (fs) Files.exists returns unexpected results with C:\pagefile.sys because it's not readable
Reviewed-by: alanb
This commit is contained in:
parent
edff51e5fd
commit
d482d7f5b9
2 changed files with 44 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -374,8 +374,19 @@ class WindowsFileSystemProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check file exists only
|
||||||
|
if (!(r || w || x)) {
|
||||||
|
file.checkRead();
|
||||||
|
try {
|
||||||
|
WindowsFileAttributes.get(file, true);
|
||||||
|
return;
|
||||||
|
} catch (WindowsException exc) {
|
||||||
|
exc.rethrowAsIOException(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// special-case read access to avoid needing to determine effective
|
// special-case read access to avoid needing to determine effective
|
||||||
// access to file; default if modes not specified
|
// access to file
|
||||||
if (!w && !x) {
|
if (!w && !x) {
|
||||||
checkReadAccess(file);
|
checkReadAccess(file);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -22,17 +22,29 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 4313887 6838333 8005566 8032220 8215467 8255576
|
* @bug 4313887 6838333 8005566 8032220 8215467 8255576 8286160
|
||||||
* @summary Unit test for miscellenous methods in java.nio.file.Files
|
* @summary Unit test for miscellenous methods in java.nio.file.Files
|
||||||
* @library ..
|
* @library .. /test/lib
|
||||||
|
* @build jdk.test.lib.Platform
|
||||||
|
* @run main Misc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.nio.file.*;
|
import java.io.IOException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.FileAlreadyExistsException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.attribute.AclEntry;
|
||||||
|
import java.nio.file.attribute.AclEntryPermission;
|
||||||
|
import java.nio.file.attribute.AclEntryType;
|
||||||
|
import java.nio.file.attribute.AclFileAttributeView;
|
||||||
|
import java.nio.file.attribute.DosFileAttributeView;
|
||||||
|
import java.nio.file.attribute.UserPrincipal;
|
||||||
|
import java.util.List;
|
||||||
|
import jdk.test.lib.Platform;
|
||||||
|
|
||||||
import static java.nio.file.Files.*;
|
import static java.nio.file.Files.*;
|
||||||
import static java.nio.file.LinkOption.*;
|
import static java.nio.file.LinkOption.*;
|
||||||
import java.nio.file.attribute.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class Misc {
|
public class Misc {
|
||||||
|
|
||||||
|
@ -78,7 +90,7 @@ public class Misc {
|
||||||
} catch (IOException x) { }
|
} catch (IOException x) { }
|
||||||
|
|
||||||
// the root directory always exists
|
// the root directory always exists
|
||||||
Path root = Paths.get("/");
|
Path root = Path.of("/");
|
||||||
Files.createDirectories(root);
|
Files.createDirectories(root);
|
||||||
Files.createDirectories(root.toAbsolutePath());
|
Files.createDirectories(root.toAbsolutePath());
|
||||||
}
|
}
|
||||||
|
@ -93,7 +105,7 @@ public class Misc {
|
||||||
assertTrue(!isHidden(tmpdir));
|
assertTrue(!isHidden(tmpdir));
|
||||||
|
|
||||||
Path file = tmpdir.resolve(".foo");
|
Path file = tmpdir.resolve(".foo");
|
||||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
if (Platform.isWindows()) {
|
||||||
createFile(file);
|
createFile(file);
|
||||||
try {
|
try {
|
||||||
setAttribute(file, "dos:hidden", true);
|
setAttribute(file, "dos:hidden", true);
|
||||||
|
@ -286,6 +298,13 @@ public class Misc {
|
||||||
assertTrue(exists(tmpdir));
|
assertTrue(exists(tmpdir));
|
||||||
assertTrue(!notExists(tmpdir));
|
assertTrue(!notExists(tmpdir));
|
||||||
|
|
||||||
|
if (Platform.isWindows()) {
|
||||||
|
Path pageFile = Path.of("C:\\pagefile.sys");
|
||||||
|
if (pageFile.toFile().exists()) {
|
||||||
|
System.out.printf("Check page file %s%n", pageFile);
|
||||||
|
assertTrue(exists(pageFile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// sym link exists
|
// sym link exists
|
||||||
if (TestUtil.supportsLinks(tmpdir)) {
|
if (TestUtil.supportsLinks(tmpdir)) {
|
||||||
|
@ -351,7 +370,7 @@ public class Misc {
|
||||||
/**
|
/**
|
||||||
* Test: Windows DOS read-only attribute
|
* Test: Windows DOS read-only attribute
|
||||||
*/
|
*/
|
||||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
if (Platform.isWindows()) {
|
||||||
setAttribute(file, "dos:readonly", true);
|
setAttribute(file, "dos:readonly", true);
|
||||||
try {
|
try {
|
||||||
assertTrue(!isWritable(file));
|
assertTrue(!isWritable(file));
|
||||||
|
@ -381,10 +400,10 @@ public class Misc {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isRoot() {
|
private static boolean isRoot() {
|
||||||
if (System.getProperty("os.name").startsWith("Windows"))
|
if (Platform.isWindows())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Path passwd = Paths.get("/etc/passwd");
|
Path passwd = Path.of("/etc/passwd");
|
||||||
return Files.isWritable(passwd);
|
return Files.isWritable(passwd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue