-
Notifications
You must be signed in to change notification settings - Fork 584
/
resolve_path.go
42 lines (34 loc) · 952 Bytes
/
resolve_path.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
39
40
41
42
package project
import (
"path/filepath"
"github.com/SAP/jenkins-library/pkg/cnbutils"
"github.com/SAP/jenkins-library/pkg/log"
)
// 1. If "path" is a directory, check for "${path}/${descriptor}"
// 2. If "path" is a file, check for "${PWD}/${descriptor}"
func ResolvePath(descriptor, path string, utils cnbutils.BuildUtils) (string, error) {
isDir, err := utils.DirExists(path)
if err != nil {
return "", err
}
if isDir {
return getFilename(path, descriptor, utils)
}
pwd, err := utils.Getwd()
if err != nil {
return "", err
}
return getFilename(pwd, descriptor, utils)
}
func getFilename(folder, filename string, utils cnbutils.BuildUtils) (string, error) {
descPath := filepath.Join(folder, filename)
exists, err := utils.FileExists(descPath)
if err != nil {
return "", err
}
if exists {
return descPath, nil
}
log.Entry().Infof("Project descriptor with the path '%s' was not found", descPath)
return "", nil
}