Move the command to cmd/sfdupes and the code to internal/sfdupes (closes #157)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
`go install sneak.berlin/go/sfdupes/cmd/sfdupes@...` found no package: the command was built from `package main` in the repository root. It now lives in `cmd/sfdupes/main.go`, whose one call is `sfdupes.Main()`, and every other Go file moved with `git mv` to `internal/sfdupes`, as `REPO_POLICIES.md` and the Go style guide require. The `Makefile` builds `./cmd/sfdupes` and sets `Version` by its new import path. README "Install" and `TODO.md` give the new paths; the fleet-written "flat layout" divergence is gone. Rule suppressed: each test file carries `//nolint:testpackage`, since the tests call unexported functions throughout. Model: opus-5-5
This commit was merged in pull request #158.
This commit is contained in:
1 parent
7cb10ed303
commit
1017332d68
27 files changed
+120
-96
No files matched your search
@@ -0,0 +1,52 @@
|
||||
//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
|
||||
}
|
||||
Reference in new issue
Block a user