Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit19d7281

Browse files
authored
fix: Fix template create with sub-folders on Windows (#4548)
On Windows, files in tar archives were stored with Windowspath-separators resulting in them being individual files as opposed tocontained in a folder.This commit ensures Unix-based paths (slash) are being used inside tararchives.Exmple of previous output:```/tmp/provisionerd673501182/images:/tmp/provisionerd673501182/:README.mdimagesimages\base.Dockerfileimages\java.Dockerfileimages\node.Dockerfilemain.tf```Fixes#2815
1 parent88f7505 commit19d7281

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

‎provisionersdk/archive.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ func Tar(directory string, limit int64) ([]byte, error) {
8787
// Don't store tfstate!
8888
returnerr
8989
}
90-
header.Name=rel
90+
// Use unix paths in the tar archive.
91+
header.Name=filepath.ToSlash(rel)
9192
iferr:=tarWriter.WriteHeader(header);err!=nil {
9293
returnerr
9394
}
@@ -131,7 +132,7 @@ func Untar(directory string, archive []byte) error {
131132
returnerr
132133
}
133134
// #nosec
134-
target:=filepath.Join(directory,header.Name)
135+
target:=filepath.Join(directory,filepath.FromSlash(header.Name))
135136
switchheader.Typeflag {
136137
casetar.TypeDir:
137138
if_,err:=os.Stat(target);err!=nil {

‎provisionersdk/archive_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package provisionersdk_test
22

33
import (
4-
"fmt"
54
"os"
65
"path/filepath"
76
"testing"
@@ -59,6 +58,7 @@ func TestTar(t *testing.T) {
5958
}}
6059
for_,file:=rangefiles {
6160
newDir:=dir
61+
file.Name=filepath.FromSlash(file.Name)
6262
iffilepath.Base(file.Name)!=file.Name {
6363
newDir=filepath.Join(newDir,filepath.Dir(file.Name))
6464
err:=os.MkdirAll(newDir,0755)
@@ -70,7 +70,6 @@ func TestTar(t *testing.T) {
7070
_=tmpFile.Close()
7171
file.Name,err=filepath.Rel(dir,tmpFile.Name())
7272
require.NoError(t,err)
73-
fmt.Printf("rel")
7473
}
7574
content,err:=provisionersdk.Tar(dir,1024)
7675
require.NoError(t,err)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp