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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/tools/cr/cmd/firstrun/common.go
diff --git a/go/src/infra/tools/cr/cmd/firstrun/common.go b/go/src/infra/tools/cr/cmd/firstrun/common.go
new file mode 100644
index 0000000000000000000000000000000000000000..5422ba9a3f637dd517cd6b7cfcaf7e143234509b
--- /dev/null
+++ b/go/src/infra/tools/cr/cmd/firstrun/common.go
@@ -0,0 +1,53 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// OS-agnostic helper functions which are called from run().
+
+package firstrun
+
+import (
+ "errors"
+ "os"
+ "path/filepath"
+
+ "infra/tools/cr/lib/terminal"
+)
+
+var getenv = os.Getenv
+var stat = os.Stat
+
+// firstrunCheckNotInstalled is a sanity check to make sure that the user really
+// wants to do firstrun again, if it looks like cr is already installed.
+func firstrunCheckNotInstalled() (string, error) {
+ terminal.Debug("Checking to make sure cr isn't already installed...")
+ // Look for paths on $PATH that end in /cr/bin.
+ pathenv := getenv("PATH")
+ if pathenv == "" {
+ return "", errors.New("no $PATH variable found in the environment")
+ }
+ var possibleDirs []string
+ for _, elem := range filepath.SplitList(pathenv) {
+ head, bindir := filepath.Split(elem)
+ crdir := filepath.Base(head)
+ if crdir == "cr" && bindir == "bin" {
+ possibleDirs = append(possibleDirs, elem)
+ }
+ }
+ // Check to see if an executable called 'cr' is in those paths.
+ var statErr error
+ for _, dir := range possibleDirs {
+ info, err := stat(filepath.Join(dir, executableName))
+ if os.IsNotExist(err) {
+ continue
+ } else if err != nil {
+ statErr = err
+ continue
+ }
+ if info.Mode()&0111 != 0 {
+ return filepath.Join(dir, executableName), nil
+ }
+ }
+ // We didn't find an executable; if we ran into an error, return that.
+ return "", statErr
+}
« 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