Skip to content

Commit d67dfe2

Browse files
feat(app): delete parent dir after uninstall app (#8350)
1 parent 00885c5 commit d67dfe2

9 files changed

Lines changed: 34 additions & 11 deletions

File tree

agent/app/repo/task.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ func (t TaskRepo) CountExecutingTask() (int64, error) {
112112
return count, err
113113
}
114114

115-
func (u TaskRepo) Delete(opts ...DBOption) error {
115+
func (t TaskRepo) Delete(opts ...DBOption) error {
116116
db := global.TaskDB
117117
for _, opt := range opts {
118118
db = opt(db)
119119
}
120120
return db.Delete(&model.Task{}).Error
121121
}
122122

123-
func (u TaskRepo) DeleteAll() error {
123+
func (t TaskRepo) DeleteAll() error {
124124
return global.TaskDB.Where("1 = 1").Delete(&model.Task{}).Error
125125
}

agent/app/service/app_utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"os/exec"
1313
"path"
14+
"path/filepath"
1415
"reflect"
1516
"regexp"
1617
"strconv"
@@ -428,6 +429,11 @@ func deleteAppInstall(deleteReq request.AppInstallDelete) error {
428429
}
429430
}
430431
_ = op.DeleteDir(appDir)
432+
parentDir := filepath.Dir(appDir)
433+
entries, err := os.ReadDir(parentDir)
434+
if err == nil && len(entries) == 0 {
435+
_ = op.DeleteDir(parentDir)
436+
}
431437
tx.Commit()
432438
return nil
433439
}

agent/app/service/runtime.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,9 @@ func (r *RuntimeService) InstallPHPExtension(req request.PHPExtensionInstallReq)
736736
if err != nil {
737737
return err
738738
}
739+
if task.CheckResourceTaskIsExecuting(task.TaskInstall, task.TaskScopeRuntimeExtension, runtime.ID) {
740+
return buserr.New("ErrInstallExtension")
741+
}
739742
installTask, err := task.NewTaskWithOps(req.Name, task.TaskInstall, task.TaskScopeRuntimeExtension, req.TaskID, runtime.ID)
740743
if err != nil {
741744
return err

agent/app/task/task.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ func CheckTaskIsExecuting(name string) error {
100100
return nil
101101
}
102102

103+
func CheckResourceTaskIsExecuting(operate, scope string, resourceID uint) bool {
104+
taskRepo := repo.NewITaskRepo()
105+
task, _ := taskRepo.GetFirst(
106+
taskRepo.WithByStatus(constant.StatusExecuting),
107+
taskRepo.WithResourceID(resourceID),
108+
taskRepo.WithOperate(operate),
109+
repo.WithByType(scope))
110+
return task.ID != ""
111+
}
112+
103113
func NewTask(name, operate, taskScope, taskID string, resourceID uint) (*Task, error) {
104114
if taskID == "" {
105115
taskID = uuid.New().String()

agent/i18n/lang/zh.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,7 @@ ErrAlert: "告警信息格式错误,请检查后重试!"
416416
ErrAlertPush: "告警信息推送错误,请检查后重试!"
417417
ErrAlertSave: "告警信息保存错误,请检查后重试!"
418418
ErrAlertSync: "告警信息同步错误,请检查后重试!"
419-
ErrAlertRemote: "告警信息远端错误,请检查后重试!"
419+
ErrAlertRemote: "告警信息远端错误,请检查后重试!"
420+
421+
#task - runtime
422+
ErrInstallExtension: "已有安装任务正在进行,请等待任务结束"

frontend/src/lang/modules/en.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,8 +2707,8 @@ const message = {
27072707
env: 'Environment',
27082708
noenv: 'None',
27092709
net: 'Network Connection',
2710-
laddr: 'Source address/port',
2711-
raddr: 'Destination address/port',
2710+
laddr: 'Local address/port',
2711+
raddr: 'Remote address/port',
27122712
stopProcess: 'End',
27132713
stopProcessWarn: 'Are you sure you want to end this process (PID:{0})? ',
27142714
processName: 'Processname',

frontend/src/lang/modules/zh-Hant.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,8 +2505,8 @@ const message = {
25052505
env: '環境變量',
25062506
noenv: '無',
25072507
net: '網絡連接',
2508-
laddr: '源地址/端口',
2509-
raddr: '目標地址/端口',
2508+
laddr: '本地地址/端口',
2509+
raddr: '远程地址/端口',
25102510
stopProcess: '結束',
25112511
stopProcessWarn: '是否確定結束此進程 (PID:{0})?',
25122512
processName: '進程名稱',

frontend/src/lang/modules/zh.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,8 +2497,8 @@ const message = {
24972497
env: '环境变量',
24982498
noenv: '无',
24992499
net: '网络连接',
2500-
laddr: '源地址/端口',
2501-
raddr: '目标地址/端口',
2500+
laddr: '本地地址/端口',
2501+
raddr: '远程地址/端口',
25022502
stopProcess: '结束',
25032503
stopProcessWarn: '是否确定结束此进程 (PID:{0})?',
25042504
processName: '进程名称',

frontend/src/views/website/runtime/php/extension-management/index.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ const installExtension = async (row: Runtime.SupportExtension) => {
8989
try {
9090
await InstallPHPExtension(req);
9191
taskLogRef.value.openWithTaskID(req.taskID);
92-
92+
} catch (error) {
93+
} finally {
9394
loading.value = false;
94-
} catch (error) {}
95+
}
9596
});
9697
};
9798

0 commit comments

Comments
 (0)