fix: 软件包上传更新替换文件路径不删除旧软件包文件
This commit is contained in:
@@ -87,7 +87,7 @@ func (s *NeSoftwareController) Add(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
if len(neSoftwares) > 0 {
|
if len(neSoftwares) > 0 {
|
||||||
neSoftware := neSoftwares[0]
|
neSoftware := neSoftwares[0]
|
||||||
s.neSoftwareService.DeleteByIds([]string{neSoftware.ID})
|
s.neSoftwareService.DeleteByIds([]string{neSoftware.ID}, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查属性值唯一
|
// 检查属性值唯一
|
||||||
@@ -163,7 +163,7 @@ func (s *NeSoftwareController) Remove(c *gin.Context) {
|
|||||||
c.JSON(200, result.Err(nil))
|
c.JSON(200, result.Err(nil))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rows, err := s.neSoftwareService.DeleteByIds(uniqueIDs)
|
rows, err := s.neSoftwareService.DeleteByIds(uniqueIDs, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ var NewNeVersion = &NeVersion{
|
|||||||
"id": "ID",
|
"id": "ID",
|
||||||
"ne_type": "NeType",
|
"ne_type": "NeType",
|
||||||
"ne_id": "NeId",
|
"ne_id": "NeId",
|
||||||
"name": "name",
|
"name": "Name",
|
||||||
"version": "Version",
|
"version": "Version",
|
||||||
"path": "Path",
|
"path": "Path",
|
||||||
"pre_name": "preName",
|
"pre_name": "preName",
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ func (r *NeSoftware) Update(neSoftware model.NeSoftware) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteByIds 批量删除信息
|
// DeleteByIds 批量删除信息
|
||||||
func (r *NeSoftware) DeleteByIds(ids []string) (int64, error) {
|
func (r *NeSoftware) DeleteByIds(ids []string, delFile bool) (int64, error) {
|
||||||
// 检查是否存在
|
// 检查是否存在
|
||||||
rows := r.neSoftwareRepository.SelectByIds(ids)
|
rows := r.neSoftwareRepository.SelectByIds(ids)
|
||||||
if len(rows) <= 0 {
|
if len(rows) <= 0 {
|
||||||
@@ -93,14 +93,16 @@ func (r *NeSoftware) DeleteByIds(ids []string) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(rows) == len(ids) {
|
if len(rows) == len(ids) {
|
||||||
// 遍历软件包列表进行文件删除
|
if delFile {
|
||||||
for _, row := range rows {
|
// 遍历软件包列表进行文件删除
|
||||||
// 检查文件是否存在
|
for _, row := range rows {
|
||||||
filePath := file.ParseUploadFilePath(row.Path)
|
// 检查文件是否存在
|
||||||
if _, err := os.Stat(filePath); err != nil {
|
filePath := file.ParseUploadFilePath(row.Path)
|
||||||
continue
|
if _, err := os.Stat(filePath); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
os.Remove(filePath)
|
||||||
}
|
}
|
||||||
os.Remove(filePath)
|
|
||||||
}
|
}
|
||||||
rows := r.neSoftwareRepository.DeleteByIds(ids)
|
rows := r.neSoftwareRepository.DeleteByIds(ids)
|
||||||
return rows, nil
|
return rows, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user