fix(command,package): correctly set modtime on zipped files
This commit is contained in:
parent
85f50eb9d5
commit
19cd4d56e7
|
@ -125,23 +125,34 @@ func copyDir(writer *zip.Writer, baseDir string, zipBasePath 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 {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := r.Close(); err != nil {
|
||||
if err := srcFile.Close(); err != nil {
|
||||
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 {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if _, err = io.Copy(f, r); err != nil {
|
||||
if _, err = io.Copy(file, srcFile); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue