scan: skip OS default excludes, and record nothing on filesystems that are not persistent (closes #124)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
scan never records anything on a filesystem that is not persistent (tmpfs, proc, sysfs and the other kernel or memory-backed types). As it starts it notes the device ID of each such mount point, from /proc/self/mountinfo on Linux and the mounted-filesystem list on macOS, and checks every operand, directory and file the walk meets against them; no flag turns this off. Below an operand the walk also skips the default excludes, a path list per system (Linux, macOS, and Windows, which is not used yet), and --no-default-excludes turns off only those. A default exclude that is itself an operand gets no skip line. The tests stop at once, saying why, when TMPDIR is not on a persistent filesystem. Judgement call: an unreadable mount list fails the scan, and no flag gets round it. Judgement call: a file on such a filesystem below an operand gets the same line as a directory. Judgement call: an operand on such a filesystem that another operand's walk also reaches is named twice. Unverified: the macOS mount list is built for macOS but never run; bind mounts need root to test. Model: opus-5-5
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
//go:build darwin
|
||||
|
||||
package main
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
// mountedFilesystems returns every mount point with the type of its
|
||||
// filesystem, from the system's list of mounted filesystems. Where one
|
||||
// filesystem is mounted over another, the later one in the list counts.
|
||||
func mountedFilesystems() (map[string]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[:])
|
||||
}
|
||||
|
||||
return mounts, nil
|
||||
}
|
||||
Reference in New Issue
Block a user