| OLD | NEW |
| (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 } |
| OLD | NEW |