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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
6
7 package prober
8
9 import (
10 "os"
11 "path/filepath"
12
13 "github.com/luci/luci-go/common/errors"
14 "github.com/luci/luci-go/common/system/environ"
15 )
16
17 func findExecutable(file string) error {
18 d, err := os.Stat(file)
19 if err != nil {
20 return err
21 }
22 if m := d.Mode(); !m.IsDir() && m&0111 != 0 {
23 return nil
24 }
25 return os.ErrPermission
26 }
27
28 // findInDir is a paraphrased and trimmed version of "exec.LookPath"
29 // (for Windows),
30 //
31 // Copied from:
32 // https://github.com/golang/go/blob/d234f9a75413fdae7643e4be9471b4aeccf02478/sr c/os/exec/lp_unix.go
33 //
34 // Modified to:
35 // - Use a supplied "dir" instead of scanning through PATH.
36 // - Not consider cases where "file" is an absolute path
37 // - Ignore the possibility that "file" may be in the CWD; only look in "di r".
38 func findInDir(file, dir string, env environ.Env) (string, error) {
39 // NOTE(rsc): I wish we could use the Plan 9 behavior here
40 // (only bypass the path if file begins with / or ./ or ../)
41 // but that would not match all the Unix shells.
42
43 if dir == "" {
44 // Unix shell semantics: path element "" means "."
45 dir = "."
46 }
47 path := filepath.Join(dir, file)
48 if err := findExecutable(path); err == nil {
49 return path, nil
50 }
51 return "", errors.New("not found")
52 }
OLDNEW
« 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