Compare commits

...

1 Commits

Author SHA1 Message Date
19cd4d56e7 fix(command,package): correctly set modtime on zipped files 2023-02-17 17:26:25 +01:00

View File

@ -125,23 +125,34 @@ func copyDir(writer *zip.Writer, baseDir string, zipBasePath string) error {
} }
func copyFile(writer *zip.Writer, srcPath string, zipPath string) error { func copyFile(writer *zip.Writer, srcPath string, zipPath string) error {
r, err := os.Open(srcPath) srcFile, err := os.Open(srcPath)
if err != nil {
return errors.WithStack(err)
}
srcStat, err := os.Stat(srcPath)
if err != nil { if err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }
defer func() { defer func() {
if err := r.Close(); err != nil { if err := srcFile.Close(); err != nil {
panic(errors.WithStack(err)) panic(errors.WithStack(err))
} }
}() }()
f, err := writer.Create(zipPath) fileHeader := &zip.FileHeader{
Name: zipPath,
Modified: srcStat.ModTime().UTC(),
Method: zip.Deflate,
}
file, err := writer.CreateHeader(fileHeader)
if err != nil { if err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }
if _, err = io.Copy(f, r); err != nil { if _, err = io.Copy(file, srcFile); err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }