diff --git a/internal/pipe/sourcearchive/source_test.go b/internal/pipe/sourcearchive/source_test.go index 048623c96..11164da9c 100644 --- a/internal/pipe/sourcearchive/source_test.go +++ b/internal/pipe/sourcearchive/source_test.go @@ -23,6 +23,8 @@ func TestArchive(t *testing.T) { require.NoError(t, os.WriteFile("code.rb", []byte("not really code"), 0o655)) require.NoError(t, os.WriteFile("code.py", []byte("print 1"), 0o655)) require.NoError(t, os.WriteFile("README.md", []byte("# my dope fake project"), 0o655)) + require.NoError(t, os.WriteFile("ملف.go", []byte("محتوى عربي"), 0o655)) + require.NoError(t, os.WriteFile("🤔.patch", []byte("thinking"), 0o655)) require.NoError(t, os.WriteFile(".gitignore", []byte(` added-later.txt ignored.txt @@ -40,6 +42,8 @@ subfolder/ require.NoError(t, os.WriteFile("added-later.txt", []byte("this file was added later"), 0o655)) require.NoError(t, os.WriteFile("ignored.md", []byte("never added"), 0o655)) require.NoError(t, os.WriteFile("code.txt", []byte("not really code"), 0o655)) + require.NoError(t, os.WriteFile("ملف.txt", []byte("محتوى عربي"), 0o655)) + require.NoError(t, os.WriteFile("🤝", []byte("it works"), 0o655)) require.NoError(t, os.MkdirAll("subfolder", 0o755)) require.NoError(t, os.WriteFile("subfolder/file.md", []byte("a file within a folder, added later"), 0o655)) @@ -68,15 +72,18 @@ subfolder/ format, []string{ "foo-1.0.0/", - "foo-1.0.0/.gitignore", - "foo-1.0.0/.gitattributes", "foo-1.0.0/.VERSION", + "foo-1.0.0/.gitattributes", + "foo-1.0.0/.gitignore", "foo-1.0.0/README.md", + "foo-1.0.0/added-later.txt", "foo-1.0.0/code.py", "foo-1.0.0/code.rb", "foo-1.0.0/code.txt", - "foo-1.0.0/added-later.txt", "foo-1.0.0/subfolder/file.md", + "foo-1.0.0/ملف.go", + "foo-1.0.0/ملف.txt", + "foo-1.0.0/🤔.patch", }, ) }) @@ -102,12 +109,14 @@ subfolder/ format, []string{ "foo-1.0.0/", - "foo-1.0.0/.gitignore", - "foo-1.0.0/.gitattributes", "foo-1.0.0/.VERSION", + "foo-1.0.0/.gitattributes", + "foo-1.0.0/.gitignore", "foo-1.0.0/README.md", "foo-1.0.0/code.py", "foo-1.0.0/code.rb", + "foo-1.0.0/ملف.go", + "foo-1.0.0/🤔.patch", }, ) }) diff --git a/internal/testlib/archive.go b/internal/testlib/archive.go index 8df178822..d631fa4f2 100644 --- a/internal/testlib/archive.go +++ b/internal/testlib/archive.go @@ -136,7 +136,7 @@ func doLsTar(f io.Reader) []string { if h == nil || err == io.EOF { break } - if h.Format == tar.FormatPAX { + if h.Name == "pax_global_header" { continue } paths = append(paths, h.Name) diff --git a/pkg/archive/archive_test.go b/pkg/archive/archive_test.go index 7a2b274e0..579cc91d7 100644 --- a/pkg/archive/archive_test.go +++ b/pkg/archive/archive_test.go @@ -50,18 +50,28 @@ func TestArchive(t *testing.T) { a, err := Copying(f1, f2, format) require.NoError(t, err) + require.NoError(t, f1.Close()) + require.NoError(t, a.Add(config.File{ Source: empty.Name(), Destination: "added_later.txt", })) + require.NoError(t, a.Add(config.File{ + Source: empty.Name(), + Destination: "ملف.txt", + })) require.NoError(t, a.Close()) - require.NoError(t, f1.Close()) require.NoError(t, f2.Close()) - require.Equal(t, []string{"empty.txt", "added_later.txt"}, testlib.LsArchive(t, f2.Name(), format)) + require.ElementsMatch( + t, + []string{"empty.txt", "added_later.txt", "ملف.txt"}, + testlib.LsArchive(t, f2.Name(), format), + ) }) } + // unsupported format... t.Run("7z", func(t *testing.T) { _, err := New(io.Discard, "7z") require.EqualError(t, err, "invalid archive format: 7z") diff --git a/pkg/archive/tar/tar.go b/pkg/archive/tar/tar.go index e3a23ee43..fbb9ad3d6 100644 --- a/pkg/archive/tar/tar.go +++ b/pkg/archive/tar/tar.go @@ -30,13 +30,15 @@ func Copying(source io.Reader, target io.Writer) (Archive, error) { w := New(target) r := tar.NewReader(source) for { - h, err := r.Next() - if err == io.EOF || h == nil { + header, err := r.Next() + if err == io.EOF || header == nil { break } - - w.files[h.Name] = true - if err := w.tw.WriteHeader(h); err != nil { + if err != nil { + return Archive{}, err + } + w.files[header.Name] = true + if err := w.tw.WriteHeader(header); err != nil { return w, err } if _, err := io.Copy(w.tw, r); err != nil { diff --git a/pkg/archive/tar/tar_test.go b/pkg/archive/tar/tar_test.go index 221cd6c48..0b3050fc3 100644 --- a/pkg/archive/tar/tar_test.go +++ b/pkg/archive/tar/tar_test.go @@ -176,6 +176,10 @@ func TestCopying(t *testing.T) { Source: "../testdata/foo.txt", Destination: "foo.txt", })) + require.NoError(t, t1.Add(config.File{ + Source: "../testdata/foo.txt", + Destination: "ملف.txt", + })) require.NoError(t, t1.Close()) require.NoError(t, f1.Close()) @@ -188,10 +192,14 @@ func TestCopying(t *testing.T) { Source: "../testdata/sub1/executable", Destination: "executable", })) + require.NoError(t, t2.Add(config.File{ + Source: "../testdata/sub1/executable", + Destination: "ملف.exe", + })) require.NoError(t, t2.Close()) require.NoError(t, f2.Close()) require.NoError(t, f1.Close()) - require.Equal(t, []string{"foo.txt"}, testlib.LsArchive(t, f1.Name(), "tar")) - require.Equal(t, []string{"foo.txt", "executable"}, testlib.LsArchive(t, f2.Name(), "tar")) + require.Equal(t, []string{"foo.txt", "ملف.txt"}, testlib.LsArchive(t, f1.Name(), "tar")) + require.Equal(t, []string{"foo.txt", "ملف.txt", "executable", "ملف.exe"}, testlib.LsArchive(t, f2.Name(), "tar")) }