fix(deploy): 更新部署文件状态并优化解压流程

- 在部署文件时更新父文件的状态为未使用
- 添加解压文件前的日志记录和删除目标文件夹的操作
This commit is contained in:
zhangtao 2025-08-06 14:43:19 +08:00
parent 41a46a42d3
commit b81126ed0d
1 changed files with 16 additions and 0 deletions

View File

@ -459,6 +459,17 @@ func (s *SysDeployFileService) DeployByID(c *gin.Context) serializer.Response {
// 开始事务
tx := s.Db.Begin()
// 更新状态
if tx.Model(&model.SysDeployFile{}).Where("parent_id = ? and status = '1'", deployFile.ParentId).Updates(map[string]any{
"status": model.FileStatusNotUsed,
"update_time": time.Now(),
"update_by": currentUserId,
}).Error != nil {
tx.Rollback()
logger.Error(c, "更新部署文件状态失败!")
return serializer.DBErr("更新部署文件状态失败!", err)
}
// 更新状态
if tx.Model(&model.SysDeployFile{}).Where("file_id = ?", id).Updates(map[string]any{
"status": model.DeployStatusSuccess,
@ -506,6 +517,11 @@ func (s *SysDeployFileService) validateZipFile(zipPath string) (bool, error) {
// extractZip 解压zip文件到指定目录
func (s *SysDeployFileService) extractZip(zipPath, destDir string) error {
logger.Info(nil, "开始解压文件", zap.String("zipPath", zipPath))
// 删除目标文件夹
if err := os.RemoveAll(destDir); err != nil {
return err
}
reader, err := zip.OpenReader(zipPath)
if err != nil {
return err