8202076: test/jdk/java/io/File/WinSpecialFiles.java on windows with VS2017

Alan Bateman Alan.Bateman at oracle.com
Fri May 18 14:40:01 UTC 2018



On 17/05/2018 01:56, Brian Burkhalter wrote:
> Hi Ivan,
>
> On May 16, 2018, at 2:54 PM, Ivan Gerasimov <ivan.gerasimov at oracle.com> 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.
>
Can the call to _wstati64 be removed? That is, if GetFileAttributesExW 
fails with a sharing violation then just use FindFirstFileW as the fallback.

-Alan




More information about the core-libs-dev mailing list