Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue with tar paths when compressing on windows #105

Merged
merged 1 commit into from
Nov 19, 2024
Merged

Conversation

mingxiao
Copy link
Contributor

tar only recognizes forward slashes, so replace any windows backslash with a forward slash

`tar` only recognizes forward slashes, so replace any windows backslash with a forward slash

Signed-off-by: Chris Selzo <chris.selzo@broadcom.com>
@selzoc selzoc merged commit 314364a into develop Nov 19, 2024
13 of 14 checks passed
@selzoc selzoc deleted the tar-path-fix branch November 19, 2024 23:19
relPath = relPath + "/"
header.Name = relPath
if runtime.GOOS == "windows" {
header.Name = strings.ReplaceAll(relPath, "\\", "/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to understand how this fixes anything, given that this looks really similar to what https://pkg.go.dev/path/filepath#FromSlash is supposed to be doing:

FromSlash returns the result of replacing each slash ('/') character in path with a separator character. Multiple slashes are replaced by multiple separators.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://pkg.go.dev/archive/tar#FileInfoHeader already appends a / if the path in question is a directory.

We also found that FromSlash does not convert \ to /: https://go.dev/play/p/SxWQTZfK3VO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants