mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-25 16:00:56 +00:00
feat(app): delete parent dir after uninstall app (#8350)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -416,4 +416,7 @@ ErrAlert: "告警信息格式错误,请检查后重试!"
|
||||
ErrAlertPush: "告警信息推送错误,请检查后重试!"
|
||||
ErrAlertSave: "告警信息保存错误,请检查后重试!"
|
||||
ErrAlertSync: "告警信息同步错误,请检查后重试!"
|
||||
ErrAlertRemote: "告警信息远端错误,请检查后重试!"
|
||||
ErrAlertRemote: "告警信息远端错误,请检查后重试!"
|
||||
|
||||
#task - runtime
|
||||
ErrInstallExtension: "已有安装任务正在进行,请等待任务结束"
|
||||
Reference in New Issue
Block a user