fix: 软件包上传更新替换文件路径不删除旧软件包文件

This commit is contained in:
TsMask
2025-08-29 17:24:13 +08:00
parent 3c7d24cfde
commit a760f8207a
2 changed files with 13 additions and 10 deletions

View File

@@ -101,7 +101,7 @@ func (s NeSoftwareController) Add(c *gin.Context) {
})
if len(neSoftwares) > 0 {
neSoftware := neSoftwares[0]
s.neSoftwareService.DeleteByIds([]int64{neSoftware.ID})
s.neSoftwareService.DeleteByIds([]int64{neSoftware.ID}, false)
}
// 检查属性值唯一
@@ -183,7 +183,7 @@ func (s NeSoftwareController) Remove(c *gin.Context) {
ids = append(ids, parse.Number(v))
}
rows, err := s.neSoftwareService.DeleteByIds(ids)
rows, err := s.neSoftwareService.DeleteByIds(ids, true)
if err != nil {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
return

View File

@@ -87,7 +87,7 @@ func (r NeSoftware) Update(neSoftware model.NeSoftware) int64 {
}
// DeleteByIds 批量删除信息
func (r NeSoftware) DeleteByIds(ids []int64) (int64, error) {
func (r NeSoftware) DeleteByIds(ids []int64, delFile bool) (int64, error) {
// 检查是否存在
rows := r.neSoftwareRepository.SelectByIds(ids)
if len(rows) <= 0 {
@@ -95,15 +95,18 @@ func (r NeSoftware) DeleteByIds(ids []int64) (int64, error) {
}
if len(rows) == len(ids) {
// 遍历软件包列表进行文件删除
for _, row := range rows {
// 检查文件是否存在
filePath := file.ParseUploadFileAbsPath(row.Path)
if _, err := os.Stat(filePath); err != nil {
continue
if delFile {
// 遍历软件包列表进行文件删除
for _, row := range rows {
// 检查文件是否存在
filePath := file.ParseUploadFileAbsPath(row.Path)
if _, err := os.Stat(filePath); err != nil {
continue
}
os.Remove(filePath)
}
os.Remove(filePath)
}
rows := r.neSoftwareRepository.DeleteByIds(ids)
return rows, nil
}