//go:build windows package fileops import ( "errors" "golang.org/x/sys/windows" ) func syncDirectory(path string) error { pathPointer, err := windows.UTF16PtrFromString(path) if err != nil { return err } directory, err := windows.CreateFile( pathPointer, windows.GENERIC_WRITE, windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE|windows.FILE_SHARE_DELETE, nil, windows.OPEN_EXISTING, windows.FILE_FLAG_BACKUP_SEMANTICS, 0, ) if err != nil { return err } defer func() { _ = windows.CloseHandle(directory) }() err = windows.FlushFileBuffers(directory) // Windows filesystems may reject flushing a directory handle even when it // was opened correctly. Preserve every error except the documented forms // that mean this operation is unavailable for the handle or filesystem. if errors.Is(err, windows.ERROR_INVALID_FUNCTION) || errors.Is(err, windows.ERROR_INVALID_HANDLE) || errors.Is(err, windows.ERROR_NOT_SUPPORTED) { return nil } return err }