Skip to content

fix: Fix template create with sub-folders on Windows #4548

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

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions provisionersdk/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func Tar(directory string, limit int64) ([]byte, error) {
// Don't store tfstate!
return err
}
header.Name = rel
// Use unix paths in the tar archive.
header.Name = filepath.ToSlash(rel)
if err := tarWriter.WriteHeader(header); err != nil {
return err
}
Expand Down Expand Up @@ -131,7 +132,7 @@ func Untar(directory string, archive []byte) error {
return err
}
// #nosec
target := filepath.Join(directory, header.Name)
target := filepath.Join(directory, filepath.FromSlash(header.Name))
switch header.Typeflag {
case tar.TypeDir:
if _, err := os.Stat(target); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions provisionersdk/archive_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package provisionersdk_test

import (
"fmt"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -59,6 +58,7 @@ func TestTar(t *testing.T) {
}}
for _, file := range files {
newDir := dir
file.Name = filepath.FromSlash(file.Name)
if filepath.Base(file.Name) != file.Name {
newDir = filepath.Join(newDir, filepath.Dir(file.Name))
err := os.MkdirAll(newDir, 0755)
Expand All @@ -70,7 +70,6 @@ func TestTar(t *testing.T) {
_ = tmpFile.Close()
file.Name, err = filepath.Rel(dir, tmpFile.Name())
require.NoError(t, err)
fmt.Printf("rel")
}
content, err := provisionersdk.Tar(dir, 1024)
require.NoError(t, err)
Expand Down