feat: apply sealed installation plans without interactive setup

This commit is contained in:
Codex
2026-10-06 15:45:18 +02:00
parent c3c9f509bf
commit 8b9a086fd6
31 changed files with 1542 additions and 45 deletions
@@ -0,0 +1,35 @@
package safeio
import (
"golang.org/x/sys/windows"
"os"
"path/filepath"
)
func publishCanonicalNewFile(path string, contents []byte, mode os.FileMode) error {
parents, target, err := openCanonicalWindowsParent(path)
if err != nil {
return ErrUnsafeFile
}
defer parents.Close()
if len(parents.handles) == 0 || validateOwnerOnlyDACL(parents.handles[len(parents.handles)-1]) != nil {
return ErrUnsafeFile
}
temporary, err := writePrivateTemporary(parents.directory, contents)
if err != nil {
return ErrUnsafeFile
}
defer os.Remove(temporary)
from, err := windows.UTF16PtrFromString(temporary)
if err != nil {
return ErrUnsafeFile
}
to, err := windows.UTF16PtrFromString(filepath.Join(parents.directory, target))
if err != nil {
return ErrUnsafeFile
}
if windows.MoveFileEx(from, to, windows.MOVEFILE_WRITE_THROUGH) != nil {
return ErrUnsafeFile
}
return nil
}