提交 3bf81d3e 编写于 作者: R robm

7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys

Reviewed-by: alanb
上级 2d3972eb
/*
* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2013, 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
......@@ -199,7 +199,7 @@ static BOOL getFileInformation(const WCHAR *path,
/**
* If the given attributes are the attributes of a reparse point, then
* read and return the attributes of the final target.
* read and return the attributes of the special cases.
*/
DWORD getFinalAttributesIfReparsePoint(WCHAR *path, DWORD a)
{
......@@ -213,6 +213,28 @@ DWORD getFinalAttributesIfReparsePoint(WCHAR *path, DWORD a)
return a;
}
/**
* Take special cases into account when retrieving the attributes
* of path
*/
DWORD getFinalAttributes(WCHAR *path)
{
DWORD attr = INVALID_FILE_ATTRIBUTES;
WIN32_FILE_ATTRIBUTE_DATA wfad;
WIN32_FIND_DATAW wfd;
HANDLE h;
if (GetFileAttributesExW(path, GetFileExInfoStandard, &wfad)) {
attr = getFinalAttributesIfReparsePoint(path, wfad.dwFileAttributes);
} else if (GetLastError() == ERROR_SHARING_VIOLATION &&
(h = FindFirstFileW(path, &wfd)) != INVALID_HANDLE_VALUE) {
attr = getFinalAttributesIfReparsePoint(path, wfd.dwFileAttributes);
CloseHandle(h);
}
return attr;
}
JNIEXPORT jstring JNICALL
Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this,
jstring pathname)
......@@ -337,38 +359,21 @@ JNIEXPORT jint JNICALL
Java_java_io_WinNTFileSystem_getBooleanAttributes(JNIEnv *env, jobject this,
jobject file)
{
jint rv = 0;
jint pathlen;
/* both pagefile.sys and hiberfil.sys have length 12 */
#define SPECIALFILE_NAMELEN 12
WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
WIN32_FILE_ATTRIBUTE_DATA wfad;
if (pathbuf == NULL)
return rv;
if (!isReservedDeviceNameW(pathbuf)) {
if (GetFileAttributesExW(pathbuf, GetFileExInfoStandard, &wfad)) {
DWORD a = getFinalAttributesIfReparsePoint(pathbuf, wfad.dwFileAttributes);
if (a != INVALID_FILE_ATTRIBUTES) {
rv = (java_io_FileSystem_BA_EXISTS
| ((a & FILE_ATTRIBUTE_DIRECTORY)
? java_io_FileSystem_BA_DIRECTORY
: java_io_FileSystem_BA_REGULAR)
| ((a & FILE_ATTRIBUTE_HIDDEN)
? java_io_FileSystem_BA_HIDDEN : 0));
}
} else { /* pagefile.sys is a special case */
if (GetLastError() == ERROR_SHARING_VIOLATION) {
rv = java_io_FileSystem_BA_EXISTS;
if ((pathlen = (jint)wcslen(pathbuf)) >= SPECIALFILE_NAMELEN &&
(_wcsicmp(pathbuf + pathlen - SPECIALFILE_NAMELEN,
L"pagefile.sys") == 0) ||
(_wcsicmp(pathbuf + pathlen - SPECIALFILE_NAMELEN,
L"hiberfil.sys") == 0))
rv |= java_io_FileSystem_BA_REGULAR;
}
DWORD a = getFinalAttributes(pathbuf);
if (a != INVALID_FILE_ATTRIBUTES) {
rv = (java_io_FileSystem_BA_EXISTS
| ((a & FILE_ATTRIBUTE_DIRECTORY)
? java_io_FileSystem_BA_DIRECTORY
: java_io_FileSystem_BA_REGULAR)
| ((a & FILE_ATTRIBUTE_HIDDEN)
? java_io_FileSystem_BA_HIDDEN : 0));
}
}
free(pathbuf);
......
/*
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2013, 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
......@@ -46,6 +46,11 @@ public class IsHidden {
Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);
}
private static void checkHidden(File f) {
if (!f.isHidden())
throw new RuntimeException(f + " should be hidden");
}
private static void testWin32() throws Exception {
File f = new File(dir, "test");
f.deleteOnExit();
......@@ -58,6 +63,11 @@ public class IsHidden {
}
ck(".foo", false);
ck("foo", false);
File pagefile = new File("C:\\pagefile.sys");
File hiberfil = new File("C:\\hiberfil.sys");
if (pagefile.exists()) checkHidden(pagefile);
if (hiberfil.exists()) checkHidden(hiberfil);
}
private static void testUnix() throws Exception {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册