From c5f0672b47ff3e63b3998ee4b20300522a8b877d Mon Sep 17 00:00:00 2001 From: Danila Gorelko Date: Mon, 8 Jul 2024 20:15:37 +0300 Subject: [PATCH] fix: Handle lsof exit status 1 indicating no use of mount points --- go/lsof/lsof.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/go/lsof/lsof.go b/go/lsof/lsof.go index b2103201814e..62b1f8c7b6f9 100644 --- a/go/lsof/lsof.go +++ b/go/lsof/lsof.go @@ -48,10 +48,14 @@ func (e ExecError) Error() string { // MountPoint returns processes using the mountpoint "lsof /dir" func MountPoint(dir string) ([]Process, error) { - // TODO: Fix lsof to not return error on exit status 1 since it isn't - // really any error, only an indication that there was no use of the - // mount. - return run([]string{"-F", "pcuftn", dir}) + processes, err := run([]string{"-F", "pcuftn", dir}) + if err != nil { + if strings.Contains(err.Error(), "exit status 1") { + return processes, nil + } + return nil, err + } + return processes, nil } func fileTypeFromString(s string) FileType {