Skip to content

Commit

Permalink
fix: inconsistent output with multiple files
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke committed May 10, 2024
1 parent f0daab2 commit 9f9155e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/provider/tar_archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (a *TarArchiver) ArchiveMultiple(content map[string][]byte) error {
header := &tar.Header{
Name: filepath.ToSlash(filename),
Size: int64(len(content[filename])),
ModTime: time.Now().Round(time.Second),
ModTime: time.Time{},
}

if err := a.addContent(content[filename], header); err != nil {
Expand Down
36 changes: 36 additions & 0 deletions internal/provider/tar_archiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,42 @@ func TestTarArchiver_Multiple(t *testing.T) {
ensureTarContents(t, tarFilePath, content)
}

func TestTarArchiver_Multiple_NoChange(t *testing.T) {
tarFilePath := filepath.Join(t.TempDir(), "archive-content.tar.gz")

content := map[string][]byte{
"file1.txt": []byte("This is file 1"),
"file2.txt": []byte("This is file 2"),
"file3.txt": []byte("This is file 3"),
}

archiver := NewTarGzArchiver(tarFilePath)
if err := archiver.ArchiveMultiple(content); err != nil {
t.Fatalf("unexpected error: %s", err)
}

expectedContents, err := os.ReadFile(tarFilePath)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}

time.Sleep(1 * time.Second)

archiver = NewTarGzArchiver(tarFilePath)
if err := archiver.ArchiveMultiple(content); err != nil {
t.Fatalf("unexpected error: %s", err)
}

actualContents, err := os.ReadFile(tarFilePath)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}

if !bytes.Equal(expectedContents, actualContents) {
t.Fatalf("tar contents do not match, potentially a modified time issue")
}
}

func TestTarArchiver_Dir_With_Symlink_File(t *testing.T) {
tarFilePath := filepath.Join(t.TempDir(), "archive-dir-with-symlink-file.tar.gz")

Expand Down

0 comments on commit 9f9155e

Please sign in to comment.