Skip to content

Commit

Permalink
fix: [CI-15249]: fixed bug where restore step failed on windows (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
avijeetsm authored Nov 22, 2024
1 parent cbc170b commit 7c17c63
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions archive/tar/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/go-kit/kit/log"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7c17c63

Please sign in to comment.