fix: Fix the issue of file permissions changing after decompressing files (#13267)

This commit is contained in:
2026-07-15 15:54:05 +08:00
committed by GitHub
parent 2874849557
commit 7b695af996
+12 -3
View File
@@ -621,9 +621,16 @@ func copyDecompressEntry(ctx context.Context, srcPath, dstPath string) (retErr e
return os.Chtimes(dstPath, info.ModTime(), info.ModTime())
}
if err := os.RemoveAll(dstPath); err != nil {
dstInfo, err := os.Lstat(dstPath)
keepExistingFile := err == nil && dstInfo.Mode().IsRegular()
if err != nil && !os.IsNotExist(err) {
return err
}
if !keepExistingFile {
if err := os.RemoveAll(dstPath); err != nil {
return err
}
}
if err := os.MkdirAll(filepath.Dir(dstPath), constant.DirPerm); err != nil {
return err
}
@@ -647,8 +654,10 @@ func copyDecompressEntry(ctx context.Context, srcPath, dstPath string) (retErr e
if _, err := io.Copy(dstFile, srcFile); err != nil {
return err
}
if err := applyDecompressOwnership(srcPath, dstPath); err != nil {
return err
if !keepExistingFile {
if err := applyDecompressOwnership(srcPath, dstPath); err != nil {
return err
}
}
return os.Chtimes(dstPath, info.ModTime(), info.ModTime())
}