Improve filepath resolution for relative paths

This commit is contained in:
2024-09-11 19:43:43 +02:00
parent 290e6fdaba
commit 205f8314d6
3 changed files with 16 additions and 12 deletions

View File

@@ -27,13 +27,13 @@ func FileExists(path string) bool {
return err == nil
}
func NormalizePath(input string) string {
workingdirectory, _ := os.Getwd()
func NormalizePath(input, workdir string) string {
input = filepath.ToSlash(input)
input = strings.ReplaceAll(input, "\"", "")
if !filepath.IsAbs(input) {
input = workingdirectory + "/" + input
log.Printf("Input '%s' is not absolute, prepending work dir '%s'", input, workdir)
input = workdir + "/" + input
}
return filepath.Clean(input)