//go:build windows package safeio import "golang.org/x/sys/windows" func preflightPrivateDirectory(path string) (bool, error) { parents, target, err := openCanonicalWindowsParent(path) if err != nil || parents == nil || len(parents.handles) == 0 { if parents != nil { parents.Close() } return false, ErrUnsafeFile } defer parents.Close() handle, err := openWindowsRelativeComponent(parents.handles[len(parents.handles)-1], target, true, windows.GENERIC_READ) if err != nil { if isWindowsRelativeNotFound(err) { writableParent, accessErr := openWindowsComponentWithAccess( parents.directory, true, windows.FILE_APPEND_DATA, // FILE_ADD_SUBDIRECTORY for a directory handle ) if accessErr != nil { return false, ErrUnsafeFile } _ = windows.CloseHandle(writableParent) return false, nil } return false, ErrUnsafeFile } defer windows.CloseHandle(handle) if err := validateOwnerOnlyDACL(handle); err != nil { return false, ErrUnsafeFile } return true, nil }