From 7c17c635c8348363764544819723402859b5c42e Mon Sep 17 00:00:00 2001 From: Avijeet Singh Mandloi Date: Fri, 22 Nov 2024 22:13:42 +0530 Subject: [PATCH] fix: [CI-15249]: fixed bug where restore step failed on windows (#126) --- archive/tar/tar.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/archive/tar/tar.go b/archive/tar/tar.go index 05bd28d9..430cfd46 100644 --- a/archive/tar/tar.go +++ b/archive/tar/tar.go @@ -7,7 +7,6 @@ import ( "io" "os" "path/filepath" - "runtime" "strings" "github.com/go-kit/kit/log" @@ -92,7 +91,7 @@ func writeToArchive(tw *tar.Writer, root string, skipSymlinks bool, written *int } var name string - if strings.HasPrefix(path, getRootPathPrefix()) { + if filepath.IsAbs(path) { name, err = filepath.Abs(path) } else if isRelativePath { name = path @@ -146,14 +145,6 @@ func relative(parent string, path string) (string, error) { return strings.TrimPrefix(filepath.Join(rel, name), "/"), nil } -func getRootPathPrefix() string { - if runtime.GOOS == "windows" { - return `C:\` - } - - return "/" -} - func createSymlinkHeader(fi os.FileInfo, path string) (*tar.Header, error) { lnk, err := os.Readlink(path) if err != nil { @@ -204,7 +195,7 @@ func (a *Archive) Extract(dst string, r io.Reader) (int64, error) { } var target string - if dst == h.Name || strings.HasPrefix(h.Name, getRootPathPrefix()) { + if dst == h.Name || filepath.IsAbs(h.Name) { target = h.Name } else { name, err := relative(dst, h.Name)