forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_helper.go
38 lines (30 loc) · 901 Bytes
/
file_helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package util
import (
boshsys "github.com/cloudfoundry/bosh-utils/system"
gopath "path"
"path/filepath"
"strings"
)
func AbsolutifyPath(pathToManifest string, pathToFile string, fs boshsys.FileSystem) (string, error) {
if strings.HasPrefix(pathToFile, "http") {
return pathToFile, nil
}
if strings.HasPrefix(pathToFile, "file:///") || strings.HasPrefix(pathToFile, "/") {
return pathToFile, nil
}
if strings.HasPrefix(pathToFile, "file://~") {
return pathToFile, nil
}
if strings.HasPrefix(pathToFile, "~") {
return fs.ExpandPath(pathToFile)
}
var absPath string
if !strings.HasPrefix(pathToFile, "file://") {
absPath = filepath.Join(filepath.Dir(pathToManifest), pathToFile)
} else {
pathToFile = strings.Replace(pathToFile, "file://", "", 1)
absPath = gopath.Join(gopath.Dir(pathToManifest), pathToFile)
absPath = "file://" + absPath
}
return absPath, nil
}