feat(app): delete parent dir after uninstall app (#8350)

This commit is contained in:
zhengkunwang
2025-04-08 17:21:16 +08:00
committed by GitHub
parent 00885c5c97
commit d67dfe2dfd
9 changed files with 34 additions and 11 deletions
+2 -2
View File
@@ -112,7 +112,7 @@ func (t TaskRepo) CountExecutingTask() (int64, error) {
return count, err
}
func (u TaskRepo) Delete(opts ...DBOption) error {
func (t TaskRepo) Delete(opts ...DBOption) error {
db := global.TaskDB
for _, opt := range opts {
db = opt(db)
@@ -120,6 +120,6 @@ func (u TaskRepo) Delete(opts ...DBOption) error {
return db.Delete(&model.Task{}).Error
}
func (u TaskRepo) DeleteAll() error {
func (t TaskRepo) DeleteAll() error {
return global.TaskDB.Where("1 = 1").Delete(&model.Task{}).Error
}
+6
View File
@@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"reflect"
"regexp"
"strconv"
@@ -428,6 +429,11 @@ func deleteAppInstall(deleteReq request.AppInstallDelete) error {
}
}
_ = op.DeleteDir(appDir)
parentDir := filepath.Dir(appDir)
entries, err := os.ReadDir(parentDir)
if err == nil && len(entries) == 0 {
_ = op.DeleteDir(parentDir)
}
tx.Commit()
return nil
}
+3
View File
@@ -736,6 +736,9 @@ func (r *RuntimeService) InstallPHPExtension(req request.PHPExtensionInstallReq)
if err != nil {
return err
}
if task.CheckResourceTaskIsExecuting(task.TaskInstall, task.TaskScopeRuntimeExtension, runtime.ID) {
return buserr.New("ErrInstallExtension")
}
installTask, err := task.NewTaskWithOps(req.Name, task.TaskInstall, task.TaskScopeRuntimeExtension, req.TaskID, runtime.ID)
if err != nil {
return err
+10
View File
@@ -100,6 +100,16 @@ func CheckTaskIsExecuting(name string) error {
return nil
}
func CheckResourceTaskIsExecuting(operate, scope string, resourceID uint) bool {
taskRepo := repo.NewITaskRepo()
task, _ := taskRepo.GetFirst(
taskRepo.WithByStatus(constant.StatusExecuting),
taskRepo.WithResourceID(resourceID),
taskRepo.WithOperate(operate),
repo.WithByType(scope))
return task.ID != ""
}
func NewTask(name, operate, taskScope, taskID string, resourceID uint) (*Task, error) {
if taskID == "" {
taskID = uuid.New().String()
+4 -1
View File
@@ -416,4 +416,7 @@ ErrAlert: "告警信息格式错误,请检查后重试!"
ErrAlertPush: "告警信息推送错误,请检查后重试!"
ErrAlertSave: "告警信息保存错误,请检查后重试!"
ErrAlertSync: "告警信息同步错误,请检查后重试!"
ErrAlertRemote: "告警信息远端错误,请检查后重试!"
ErrAlertRemote: "告警信息远端错误,请检查后重试!"
#task - runtime
ErrInstallExtension: "已有安装任务正在进行,请等待任务结束"