Files
sfdupes/internal/sfdupes/exclude_darwin.go
T
sneak b5ff4f720f
check / check (push) Failing after 20m3s
Move the command to cmd/sfdupes and the code to internal/sfdupes (closes #157)
The root held every .go file in package main, so no ref had the
path cmd/sfdupes that go install was given. cmd/sfdupes/main.go now
only calls sfdupes.Main; the rest is package internal/sfdupes, with
main.go renamed to cli.go. The Makefile builds ./cmd/sfdupes and sets
Version by its new import path. README and TODO.md give the new
install path and file paths.

The test files carry //nolint:testpackage: they test unexported
functions, which the linter allowed only in package main.

Model: opus-5-5
2026-11-10 19:50:51 +00:00

53 lines
1.2 KiB
Go

//go:build darwin
package sfdupes
import (
"slices"
"golang.org/x/sys/unix"
)
// nonPersistentFilesystems returns the device ID of every mounted
// filesystem that is not persistent, with its type, from the system's
// list of mounted filesystems. The device ID is read with lstat on the
// mount point. Where one filesystem is mounted over another on the same
// mount point, the later one in the list counts. A mount point that
// lstat cannot reach is left out.
func nonPersistentFilesystems() (map[uint64]string, error) {
// The first call counts the filesystems, the second lists them.
n, err := unix.Getfsstat(nil, unix.MNT_NOWAIT)
if err != nil {
return nil, err
}
list := make([]unix.Statfs_t, n)
n, err = unix.Getfsstat(list, unix.MNT_NOWAIT)
if err != nil {
return nil, err
}
mounts := make(map[string]string, n)
for _, st := range list[:n] {
mounts[unix.ByteSliceToString(st.Mntonname[:])] =
unix.ByteSliceToString(st.Fstypename[:])
}
types := nonPersistentFilesystemTypes()
devices := make(map[uint64]string)
for mountPoint, fsType := range mounts {
if !slices.Contains(types, fsType) {
continue
}
if dev, ok := deviceOfPath(mountPoint); ok {
devices[dev] = fsType
}
}
return devices, nil
}