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

Side by Side Diff: go/src/infra/tools/cr/cmd/firstrun/common.go

Issue 1929153002: Add beginnings of new cr command (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Fix windows arguments Created 4 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 | « no previous file | go/src/infra/tools/cr/cmd/firstrun/firstrun.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 2016 The Chromium 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 // OS-agnostic helper functions which are called from run().
6
7 package firstrun
8
9 import (
10 "errors"
11 "os"
12 "path/filepath"
13
14 "infra/tools/cr/lib/terminal"
15 )
16
17 var getenv = os.Getenv
18 var stat = os.Stat
19
20 // firstrunCheckNotInstalled is a sanity check to make sure that the user really
21 // wants to do firstrun again, if it looks like cr is already installed.
22 func firstrunCheckNotInstalled() (string, error) {
23 terminal.Debug("Checking to make sure cr isn't already installed...")
24 // Look for paths on $PATH that end in /cr/bin.
25 pathenv := getenv("PATH")
26 if pathenv == "" {
27 return "", errors.New("no $PATH variable found in the environmen t")
28 }
29 var possibleDirs []string
30 for _, elem := range filepath.SplitList(pathenv) {
31 head, bindir := filepath.Split(elem)
32 crdir := filepath.Base(head)
33 if crdir == "cr" && bindir == "bin" {
34 possibleDirs = append(possibleDirs, elem)
35 }
36 }
37 // Check to see if an executable called 'cr' is in those paths.
38 var statErr error
39 for _, dir := range possibleDirs {
40 info, err := stat(filepath.Join(dir, executableName))
41 if os.IsNotExist(err) {
42 continue
43 } else if err != nil {
44 statErr = err
45 continue
46 }
47 if info.Mode()&0111 != 0 {
48 return filepath.Join(dir, executableName), nil
49 }
50 }
51 // We didn't find an executable; if we ran into an error, return that.
52 return "", statErr
53 }
OLDNEW
« no previous file with comments | « no previous file | go/src/infra/tools/cr/cmd/firstrun/firstrun.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698