check / check (push) Failing after 20m3s
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
53 lines
1.2 KiB
Go
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
|
|
}
|