//go:build windows /* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ package main import ( "golang.org/x/sys/windows" ) /* See * https://cs.opensource.google/go/go/+/refs/tags/go1.22.3:src/os/stat_windows.go;l=102;drc=1d3088effdcb03612dd03eb24feee4aa92070a63 * https://cs.opensource.google/go/go/+/master:src/os/types_windows.go;l=46;drc=dc548bb322387039a12000c04e5b9083a0511639 * https://cs.opensource.google/go/x/sys/+/refs/tags/v0.20.0:windows/zsyscall_windows.go;l=2245;drc=1a50d9738bb732c5dc3de113b13fb9ac06da1369 * https://cs.opensource.google/go/x/sys/+/refs/tags/v0.20.0:windows/zsyscall_windows.go;l=261;drc=1a50d9738bb732c5dc3de113b13fb9ac06da1369 */ type FileSysInfo = *windows.ByHandleFileInformation const FileSysInfoStr = "*windows.ByHandleFileInformation" func fileWasRotated(newSysInfo, curSysInfo FileSysInfo) bool { /* There may very well be corner cases where the following test triggers a frivolous reopen, but this should occur infrequently. If rotation uses ReplaceFileA/W, no change in file ID will occur, and we will be entirely reliant on detecting a sudden drop in file size. If the rotation condition is based on time rather than size, it is not inconceivable that one empty file could be swapped for another without detection. In this case, comparing creation times becomes compulsory. See * https://learn.microsoft.com/en-us/windows/win32/api/fileapi/ns-fileapi-by_handle_file_information#remarks * https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-replacefilew#remarks * https://cs.opensource.google/go/go/+/master:src/syscall/types_windows.go;l=348;drc=d42cd452dcca76819dd385a7775f8453d6255dbd */ return newSysInfo.FileIndexHigh != curSysInfo.FileIndexHigh || newSysInfo.FileIndexLow != curSysInfo.FileIndexLow || newSysInfo.FileSizeHigh < curSysInfo.FileSizeHigh || (newSysInfo.FileSizeHigh == curSysInfo.FileSizeHigh && newSysInfo.FileSizeLow < curSysInfo.FileSizeLow) || newSysInfo.CreationTime.Nanoseconds() > curSysInfo.CreationTime.Nanoseconds() }