fix(safeio): retain private file parent handles

This commit is contained in:
2026-08-18 08:51:59 +02:00
parent 0b77d1e850
commit e7a7f4f066
11 changed files with 359 additions and 212 deletions
@@ -2,22 +2,20 @@
package safeio
import (
"errors"
"path/filepath"
"golang.org/x/sys/windows"
)
import "golang.org/x/sys/windows"
func preflightPrivateDirectory(path string) (bool, error) {
parents, target, err := openCanonicalWindowsParent(path)
if err != nil {
if err != nil || parents == nil || len(parents.handles) == 0 {
if parents != nil {
parents.Close()
}
return false, ErrUnsafeFile
}
defer parents.Close()
handle, err := openWindowsComponent(filepath.Join(parents.directory, target), true)
handle, err := openWindowsRelativeComponent(parents.handles[len(parents.handles)-1], target, true, windows.GENERIC_READ)
if err != nil {
if errors.Is(err, windows.ERROR_FILE_NOT_FOUND) {
if isWindowsRelativeNotFound(err) {
writableParent, accessErr := openWindowsComponentWithAccess(
parents.directory,
true,