73 lines
2.8 KiB
Diff
73 lines
2.8 KiB
Diff
|
|
From 480c546fa5d07a92d09fbe669a7a36e718baedca Mon Sep 17 00:00:00 2001
|
||
|
|
From: xuwei <xuwei43@huawei.com>
|
||
|
|
Date: Fri, 19 Apr 2019 16:15:04 +0000
|
||
|
|
Subject: [PATCH] 8202076: test/jdk/java/io/File/WinSpecialFiles.java on windows with VS2017
|
||
|
|
|
||
|
|
Bug url: https://bugs.openjdk.java.net/browse/JDK-8202076
|
||
|
|
|
||
|
|
---
|
||
|
|
.../native/java/io/WinNTFileSystem_md.c | 40 +++++++++++++++----
|
||
|
|
1 file changed, 33 insertions(+), 7 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/jdk/src/windows/native/java/io/WinNTFileSystem_md.c b/jdk/src/windows/native/java/io/WinNTFileSystem_md.c
|
||
|
|
index 4c61fa5817..8c8494743f 100644
|
||
|
|
--- a/jdk/src/windows/native/java/io/WinNTFileSystem_md.c
|
||
|
|
+++ b/jdk/src/windows/native/java/io/WinNTFileSystem_md.c
|
||
|
|
@@ -35,6 +35,8 @@
|
||
|
|
#include <direct.h>
|
||
|
|
#include <windows.h>
|
||
|
|
#include <io.h>
|
||
|
|
+#include <limits.h>
|
||
|
|
+#include <wchar.h>
|
||
|
|
|
||
|
|
#include "jni.h"
|
||
|
|
#include "io_util.h"
|
||
|
|
@@ -525,13 +527,37 @@ Java_java_io_WinNTFileSystem_getLength(JNIEnv *env, jobject this, jobject file)
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if (GetLastError() == ERROR_SHARING_VIOLATION) {
|
||
|
|
- /* The error is "share violation", which means the file/dir
|
||
|
|
- must exists. Try _wstati64, we know this at least works
|
||
|
|
- for pagefile.sys and hiberfil.sys.
|
||
|
|
- */
|
||
|
|
- struct _stati64 sb;
|
||
|
|
- if (_wstati64(pathbuf, &sb) == 0) {
|
||
|
|
- rv = sb.st_size;
|
||
|
|
+ // The error is a "share violation", which means the file/dir
|
||
|
|
+ // must exist. Try FindFirstFile, we know this at least works
|
||
|
|
+ // for pagefile.sys.
|
||
|
|
+ WIN32_FIND_DATAW fileData;
|
||
|
|
+ HANDLE h = FindFirstFileW(pathbuf, &fileData);
|
||
|
|
+ if (h != INVALID_HANDLE_VALUE) {
|
||
|
|
+ if ((fileData.dwFileAttributes &
|
||
|
|
+ FILE_ATTRIBUTE_REPARSE_POINT) == 0) {
|
||
|
|
+ WCHAR backslash = L'\\';
|
||
|
|
+ WCHAR *pslash = wcsrchr(pathbuf, backslash);
|
||
|
|
+ if (pslash == NULL) {
|
||
|
|
+ pslash = pathbuf;
|
||
|
|
+ } else {
|
||
|
|
+ pslash++;
|
||
|
|
+ }
|
||
|
|
+ WCHAR *fslash = wcsrchr(fileData.cFileName, backslash);
|
||
|
|
+ if (fslash == NULL) {
|
||
|
|
+ fslash = fileData.cFileName;
|
||
|
|
+ } else {
|
||
|
|
+ fslash++;
|
||
|
|
+ }
|
||
|
|
+ if (wcscmp(pslash, fslash) == 0) {
|
||
|
|
+ ULARGE_INTEGER length;
|
||
|
|
+ length.LowPart = fileData.nFileSizeLow;
|
||
|
|
+ length.HighPart = fileData.nFileSizeHigh;
|
||
|
|
+ if (length.QuadPart <= _I64_MAX) {
|
||
|
|
+ rv = (jlong)length.QuadPart;
|
||
|
|
+ }
|
||
|
|
+ }
|
||
|
|
+ }
|
||
|
|
+ FindClose(h);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
--
|
||
|
|
2.19.0
|
||
|
|
|