Files
magpie/internal/edit/hardlink_windows.go
T
yetone 3d69bde0f6 edit: a config shared with a group keeps its group when magpie writes it (#1499, fjrtdk)
WriteAtomic kept a file's mode but not its group: the temp file renamed
over it takes its folder's group, so a config shared with a group (Aside's
group-writable u/1/models.json, group wheel, on #1499) could end up in the
user's own group and the other writers lose it. The temp file is now given
the old file's group before the rename, best effort (a group the user isn't
in is left as made). Windows has no Unix group; its keepGroup does nothing.

Run: go test ./internal/edit (TestWriteAtomicKeepsGroupAndMode passes; with
keepGroup commented out it fails with the folder's group); gofmt -l;
GOOS=linux and GOOS=windows go vet -tags nogui ./internal/edit.
2026-10-10 23:35:04 +08:00

22 lines
485 B
Go

package edit
import (
"os"
"golang.org/x/sys/windows"
)
// hardLinked reports whether the file at path has other names too.
func hardLinked(path string) bool {
f, err := os.Open(path)
if err != nil {
return false
}
defer f.Close()
var fi windows.ByHandleFileInformation
return windows.GetFileInformationByHandle(windows.Handle(f.Fd()), &fi) == nil && fi.NumberOfLinks > 1
}
// keepGroup: Windows files have no Unix group to keep.
func keepGroup(*os.File, os.FileInfo) {}