fix: Fix the issue of preserving archive modification time during the decompression process of gz files (#12297)

This commit is contained in:
蘭
2026-03-23 07:52:04 +00:00
committed by GitHub
parent ec9eba0b9a
commit 569363530a
+7 -2
View File
@@ -999,6 +999,11 @@ func ZipFile(files []archiver.File, dst afero.File) error {
}
func (f FileOp) DecompressGzFile(srcFile, dst string) error {
var archiveModTime time.Time
if st, err := f.Fs.Stat(srcFile); err == nil {
archiveModTime = st.ModTime()
}
in, err := f.Fs.Open(srcFile)
if err != nil {
return fmt.Errorf("open source file failed: %w", err)
@@ -1030,8 +1035,8 @@ func (f FileOp) DecompressGzFile(srcFile, dst string) error {
return fmt.Errorf("copy content failed: %w", err)
}
if !gr.ModTime.IsZero() {
_ = os.Chtimes(outPath, gr.ModTime, gr.ModTime)
if !archiveModTime.IsZero() {
_ = os.Chtimes(outPath, archiveModTime, archiveModTime)
}
return nil