From f4a571786ceed95867df1f1b7bdea033804f0681 Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Fri, 21 Oct 2022 14:20:24 +0200 Subject: [PATCH] local: clean absolute paths - fixes #6493 --- backend/local/local.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/backend/local/local.go b/backend/local/local.go index 7d56d8012..654bb02d1 100644 --- a/backend/local/local.go +++ b/backend/local/local.go @@ -1400,30 +1400,27 @@ func (o *Object) writeMetadata(metadata fs.Metadata) (err error) { } func cleanRootPath(s string, noUNC bool, enc encoder.MultiEncoder) string { - if runtime.GOOS == "windows" { - if !filepath.IsAbs(s) && !strings.HasPrefix(s, "\\") { + if runtime.GOOS != "windows" || !strings.HasPrefix(s, "\\") { + if !filepath.IsAbs(s) { s2, err := filepath.Abs(s) if err == nil { s = s2 } + } else { + s = filepath.Clean(s) } + } + if runtime.GOOS == "windows" { s = filepath.ToSlash(s) vol := filepath.VolumeName(s) s = vol + enc.FromStandardPath(s[len(vol):]) s = filepath.FromSlash(s) - if !noUNC { // Convert to UNC s = file.UNCPath(s) } return s } - if !filepath.IsAbs(s) { - s2, err := filepath.Abs(s) - if err == nil { - s = s2 - } - } s = enc.FromStandardPath(s) return s }