| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 // that can be found in the LICENSE file. | |
| 4 | |
| 5 package main | |
| 6 | |
| 7 import ( | |
| 8 "io/ioutil" | |
| 9 "os" | |
| 10 "path/filepath" | |
| 11 "strings" | |
| 12 | |
| 13 "github.com/luci/luci-go/common/errors" | |
| 14 ) | |
| 15 | |
| 16 const ( | |
| 17 // configExt is the configuration file extension. | |
| 18 configExt = ".cfg" | |
| 19 ) | |
| 20 | |
| 21 func splitSourceRelativePath(path string) []string { | |
| 22 return strings.Split(path, "/") | |
| 23 } | |
| 24 | |
| 25 // deployToNative converts the depoy tool path, path, to a native path. | |
| 26 // | |
| 27 // base is a native base path to prepend to the generated path. If empty, the | |
| 28 // returned path will be relative. | |
| 29 func deployToNative(base, path string) string { | |
| 30 parts := splitSourceRelativePath(path) | |
| 31 path = filepath.Join(parts...) | |
| 32 if base != "" { | |
| 33 path = filepath.Join(base, path) | |
| 34 } | |
| 35 return path | |
| 36 } | |
| 37 | |
| 38 // deployDirname returns the directory name of the source-relative path. | |
| 39 func deployDirname(path string) string { | |
| 40 if idx := strings.LastIndex(path, "/"); idx >= 0 { | |
| 41 return path[:idx] | |
| 42 } | |
| 43 return "" | |
| 44 } | |
| 45 | |
| 46 func isHidden(path string) bool { | |
| 47 return strings.HasPrefix(filepath.Base(path), ".") | |
| 48 } | |
| 49 | |
| 50 func fileURLToPath(path string) string { | |
| 51 if filepath.Separator == '/' { | |
| 52 return path | |
| 53 } | |
| 54 return strings.Replace(path, "/", string(filepath.Separator), -1) | |
| 55 } | |
| 56 | |
| 57 func withTempDir(f func(string) error) error { | |
| 58 // Create a temporary directory. | |
| 59 tdir, err := ioutil.TempDir("", "luci_deploytool") | |
| 60 if err != nil { | |
| 61 return errors.Annotate(err).Reason("failed to create tempdir").E
rr() | |
| 62 } | |
| 63 defer os.RemoveAll(tdir) | |
| 64 | |
| 65 return f(tdir) | |
| 66 } | |
| OLD | NEW |