Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: common/system/prober/probe_unix.go

Issue 2932443002: Initial transfer. (Closed)
Patch Set: move to system Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/system/prober/probe_test.go ('k') | common/system/prober/probe_windows.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/system/prober/probe_unix.go
diff --git a/common/system/prober/probe_unix.go b/common/system/prober/probe_unix.go
new file mode 100644
index 0000000000000000000000000000000000000000..e3681a101b17c7d7ab0cf96b525ed05e9dbccec6
--- /dev/null
+++ b/common/system/prober/probe_unix.go
@@ -0,0 +1,52 @@
+// Copyright 2017 The LUCI Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
+
+package prober
+
+import (
+ "os"
+ "path/filepath"
+
+ "github.com/luci/luci-go/common/errors"
+ "github.com/luci/luci-go/common/system/environ"
+)
+
+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 os.ErrPermission
+}
+
+// findInDir is a paraphrased and trimmed version of "exec.LookPath"
+// (for Windows),
+//
+// Copied from:
+// https://github.com/golang/go/blob/d234f9a75413fdae7643e4be9471b4aeccf02478/src/os/exec/lp_unix.go
+//
+// Modified to:
+// - Use a supplied "dir" instead of scanning through PATH.
+// - Not consider cases where "file" is an absolute path
+// - Ignore the possibility that "file" may be in the CWD; only look in "dir".
+func findInDir(file, dir string, env environ.Env) (string, error) {
+ // NOTE(rsc): I wish we could use the Plan 9 behavior here
+ // (only bypass the path if file begins with / or ./ or ../)
+ // but that would not match all the Unix shells.
+
+ if dir == "" {
+ // Unix shell semantics: path element "" means "."
+ dir = "."
+ }
+ path := filepath.Join(dir, file)
+ if err := findExecutable(path); err == nil {
+ return path, nil
+ }
+ return "", errors.New("not found")
+}
« no previous file with comments | « common/system/prober/probe_test.go ('k') | common/system/prober/probe_windows.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698