Fix issue with non absolute paths not being absoluted

This commit is contained in:
2024-09-23 16:16:47 +02:00
parent 41123846d1
commit cd42bc1fb8

17
util.go
View File

@@ -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 {