feat: delete old file when updating version with new file

If file_path is different from existing file, remove the old file

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-01 10:09:23 +08:00
parent 8cb867e65b
commit fd98c0dcc4
+12
View File
@@ -453,6 +453,18 @@ func handleUpdateVersionGlobal(c *gin.Context) {
log.Printf("[DEBUG] Updates map: %+v\n", updates)
// 如果文件被更新,删除旧文件
if req.FilePath != "" && req.FilePath != version.FilePath {
oldFilePath := filepath.Join(".", version.FilePath)
if _, err := os.Stat(oldFilePath); err == nil {
if err := os.Remove(oldFilePath); err != nil {
log.Printf("[WARN] Failed to remove old file %s: %v\n", oldFilePath, err)
} else {
log.Printf("[INFO] Removed old file: %s\n", oldFilePath)
}
}
}
if len(updates) == 0 {
response.Success(c, nil)
return