Fix issue with non absolute paths not being absoluted
This commit is contained in:
17
util.go
17
util.go
@@ -29,20 +29,23 @@ func FileExists(path string) bool {
|
|||||||
|
|
||||||
func NormalizePath(input, workdir string) string {
|
func NormalizePath(input, workdir string) string {
|
||||||
input = filepath.Clean(input)
|
input = filepath.Clean(input)
|
||||||
input, err := filepath.Abs(input)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Failed to get absolute path for %s%s%s: %s%+v%s", SourceColor, input, DefaultColor, ErrorColor, err, DefaultColor)
|
|
||||||
return input
|
|
||||||
}
|
|
||||||
input = filepath.ToSlash(input)
|
input = filepath.ToSlash(input)
|
||||||
input = strings.ReplaceAll(input, "\"", "")
|
input = strings.ReplaceAll(input, "\"", "")
|
||||||
|
|
||||||
if !filepath.IsAbs(input) {
|
if !filepath.IsAbs(input) {
|
||||||
log.Printf("Input '%s' is not absolute, prepending work dir '%s'", input, workdir)
|
log.Printf("Input '%s' is not absolute, prepending work dir '%s'", input, workdir)
|
||||||
input = workdir + "/" + input
|
var err error
|
||||||
|
input = filepath.Join(workdir, input)
|
||||||
|
input, err = filepath.Abs(input)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to get absolute path for %s%s%s: %s%+v%s", SourceColor, input, DefaultColor, ErrorColor, err, DefaultColor)
|
||||||
|
return input
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return filepath.Clean(input)
|
input = filepath.Clean(input)
|
||||||
|
input = filepath.ToSlash(input)
|
||||||
|
return input
|
||||||
}
|
}
|
||||||
|
|
||||||
func AreSame(lhs string, rhs string) bool {
|
func AreSame(lhs string, rhs string) bool {
|
||||||
|
Reference in New Issue
Block a user