Hi Ivan,
On May 16, 2018, at 2:54 PM, Ivan Gerasimov <[email protected]> wrote:
> Maybe it is better to compare fileData.cFileName with the pathbuf to make
> sure we're dealing with the correct file?
Certainly making this change to the previous proposal would do no harm:
--- a/src/java.base/windows/native/libjava/WinNTFileSystem_md.c
+++ b/src/java.base/windows/native/libjava/WinNTFileSystem_md.c
@@ -541,10 +541,13 @@
WIN32_FIND_DATAW fileData;
HANDLE h = FindFirstFileW(pathbuf, &fileData);
if (h != INVALID_HANDLE_VALUE) {
- ULARGE_INTEGER length;
- length.LowPart = fileData.nFileSizeLow;
- length.HighPart = fileData.nFileSizeHigh;
- rv = (jlong)length.QuadPart;
+ size_t off = wcslen(pathbuf) - wcslen(fileData.cFileName);
+ if (wcscmp(pathbuf + off, fileData.cFileName) == 0) {
+ ULARGE_INTEGER length;
+ length.LowPart = fileData.nFileSizeLow;
+ length.HighPart = fileData.nFileSizeHigh;
+ rv = (jlong)length.QuadPart;
+ }
FindClose(h);
}
}
The offset in the string comparison is necessary as “C:\\pagefile.sys” becomes
“pagefile.sys” in fileData.cFileName. I’m not certain that this will work in
all cases however but it is certainly no worse than before.
Thanks for the suggestion!
Brian