MCPcopy
hub / github.com/perkeep/perkeep / isInProcMounts

Function isInProcMounts

pkg/fs/fs_test.go:793–813  ·  view source on GitHub ↗

isInProcMounts returns whether dir is found as a mount point of /dev/fuse in proc/mounts. It does not guarantee the dir is usable as such, as it could have been left unmounted by a previously interrupted process ("transport endpoint is not connected" error).

(dir string)

Source from the content-addressed store, hash-verified

791// been left unmounted by a previously interrupted process ("transport endpoint is
792// not connected" error).
793func isInProcMounts(dir string) (error, bool) {
794 if runtime.GOOS != "linux" {
795 return errors.New("only available on linux"), false
796 }
797 data, err := os.ReadFile("/proc/mounts")
798 if err != nil {
799 return err, false
800 }
801 sc := bufio.NewScanner(bytes.NewReader(data))
802 dir = strings.TrimSuffix(dir, "/")
803 for sc.Scan() {
804 l := sc.Text()
805 if !strings.HasPrefix(l, "/dev/fuse") {
806 continue
807 }
808 if strings.Fields(l)[1] == dir {
809 return nil, true
810 }
811 }
812 return sc.Err(), false
813}
814
815// isMounted returns whether dir is considered mounted as far as the filesystem
816// is concerned, when one needs to know whether to unmount dir. It does not

Callers 1

isMountedFunction · 0.85

Calls 3

HasPrefixMethod · 0.80
TextMethod · 0.65
ErrMethod · 0.45

Tested by

no test coverage detected