From 820226c72bb481d1507c8552a16d31bd985cadec Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Thu, 1 Dec 2022 11:05:00 -0800 Subject: [PATCH] lib/xexec: rm -rf --- d2plugin/plugin.go | 2 +- go.mod | 2 +- go.sum | 2 ++ lib/xexec/xexec.go | 57 ---------------------------------------------- 4 files changed, 4 insertions(+), 59 deletions(-) delete mode 100644 lib/xexec/xexec.go diff --git a/d2plugin/plugin.go b/d2plugin/plugin.go index 0354b8355..24d9ad379 100644 --- a/d2plugin/plugin.go +++ b/d2plugin/plugin.go @@ -10,7 +10,7 @@ import ( "os/exec" "oss.terrastruct.com/d2/d2graph" - "oss.terrastruct.com/d2/lib/xexec" + "oss.terrastruct.com/util-go/xexec" ) // plugins contains the bundled d2 plugins. diff --git a/go.mod b/go.mod index 93c3ab7dc..dc61ded3f 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( nhooyr.io/websocket v1.8.7 oss.terrastruct.com/cmdlog v0.0.0-20221201100934-012c01b3431c oss.terrastruct.com/diff v1.0.2-0.20221116222035-8bf4dd3ab541 - oss.terrastruct.com/util-go v0.0.0-20221201185848-8cc30ca56bbe + oss.terrastruct.com/util-go v0.0.0-20221201190418-569dcbf6dc3f oss.terrastruct.com/xcontext v0.0.0-20221018000442-50fdafb12f4f oss.terrastruct.com/xdefer v0.0.0-20221017222355-6f3b6e4d1557 oss.terrastruct.com/xjson v0.0.0-20221018000420-4986731c4c4a diff --git a/go.sum b/go.sum index dc98e6487..9ca23e3de 100644 --- a/go.sum +++ b/go.sum @@ -804,6 +804,8 @@ oss.terrastruct.com/diff v1.0.2-0.20221116222035-8bf4dd3ab541 h1:I9B1O1IJ6spivIQ oss.terrastruct.com/diff v1.0.2-0.20221116222035-8bf4dd3ab541/go.mod h1:ags2QDy/T6jr69hT6bpmAmhr2H98n9o8Atf3QlUJPiU= oss.terrastruct.com/util-go v0.0.0-20221201185848-8cc30ca56bbe h1:1CTXmBqea1vbVhYsyZ3NiCYUFZgURIQF/ItjrdlhwlE= oss.terrastruct.com/util-go v0.0.0-20221201185848-8cc30ca56bbe/go.mod h1:bL3CBn27CtTm++1iqRh2p6f8AIWeTdtlTN199Kg9JYM= +oss.terrastruct.com/util-go v0.0.0-20221201190418-569dcbf6dc3f h1:ADVDj5TeMMxXMEKAxC9RKLCQq4gaW6GKynAeojB9VQQ= +oss.terrastruct.com/util-go v0.0.0-20221201190418-569dcbf6dc3f/go.mod h1:bL3CBn27CtTm++1iqRh2p6f8AIWeTdtlTN199Kg9JYM= oss.terrastruct.com/xcontext v0.0.0-20221018000442-50fdafb12f4f h1:7voRCwKM7TZkTo9u7hj+uV/zXoVB8czWrTq6MVIh3dg= oss.terrastruct.com/xcontext v0.0.0-20221018000442-50fdafb12f4f/go.mod h1:Y0coTLsWwX0q3a+/Ndq797t+vWyxm42T49Ik3bzaDKY= oss.terrastruct.com/xdefer v0.0.0-20221017222355-6f3b6e4d1557 h1:rPbhJbN1q7B4tnppSPoAMwq0t6Pk5SrQDQ5S6uoNNHg= diff --git a/lib/xexec/xexec.go b/lib/xexec/xexec.go deleted file mode 100644 index aa93afecf..000000000 --- a/lib/xexec/xexec.go +++ /dev/null @@ -1,57 +0,0 @@ -package xexec - -import ( - "errors" - "io/fs" - "os" - "path/filepath" - "strings" -) - -// findExecutable is from package exec -func findExecutable(file string) error { - d, err := os.Stat(file) - if err != nil { - return err - } - if m := d.Mode(); !m.IsDir() && m&0111 != 0 { - return nil - } - return fs.ErrPermission -} - -// SearchPath searches for all executables that have prefix in their names in -// the directories named by the PATH environment variable. -func SearchPath(prefix string) ([]string, error) { - var matches []string - envPath := os.Getenv("PATH") - dirSet := make(map[string]struct{}) - for _, dir := range filepath.SplitList(envPath) { - if dir == "" { - // From exec package: - // Unix shell semantics: path element "" means "." - dir = "." - } - if _, ok := dirSet[dir]; ok { - continue - } - dirSet[dir] = struct{}{} - files, err := os.ReadDir(dir) - if err != nil { - if errors.Is(err, fs.ErrNotExist) { - continue - } - return nil, err - } - for _, f := range files { - if strings.HasPrefix(f.Name(), prefix) { - match := filepath.Join(dir, f.Name()) - if err := findExecutable(match); err == nil { - matches = append(matches, match) - } - } - } - - } - return matches, nil -}