Skip to content

Commit

Permalink
Create file headers with modified time set to now in zip archive (#221)
Browse files Browse the repository at this point in the history
This adds a `Create` method to the `ZipFile` struct, which overrides
https://pkg.go.dev/archive/zip#Writer.Create in order to set the file's
modification time to now.
  • Loading branch information
thbkrkr authored Feb 28, 2024
1 parent 8d9b839 commit 7c618f4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"
"os"
"strings"
"time"

"k8s.io/apimachinery/pkg/util/errors"
)
Expand Down Expand Up @@ -64,6 +65,17 @@ func NewZipFile(fileName string, version string, log *log.Logger) (*ZipFile, err
}, nil
}

// Create adds a file to the zip file using the provided name similarly to https://pkg.go.dev/archive/zip#Writer.Create,
// with the addition of the file modification time set to now.
func (z *ZipFile) Create(filename string) (io.Writer, error) {
header := &zip.FileHeader{
Name: filename,
Method: zip.Deflate,
Modified: time.Now(),
}
return z.CreateHeader(header)
}

// Close closes the zip.Writer and the underlying file.
func (z *ZipFile) Close() error {
errs := []error{
Expand Down

0 comments on commit 7c618f4

Please sign in to comment.