diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index b10e0beef..96e49d86a 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -153,7 +153,7 @@ func (a AppInstallService) Operate(req request.AppInstalledOperate) error { install.Status = constant.Running case constant.Delete: tx, ctx := getTxAndContext() - if err := deleteAppInstall(ctx, install, req.ForceDelete, req.DeleteBackup); err != nil { + if err := deleteAppInstall(ctx, install, req.DeleteBackup); err != nil && !req.ForceDelete { tx.Rollback() return err } diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index ce98a39e8..930d1e0b7 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -152,7 +152,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall return nil } -func deleteAppInstall(ctx context.Context, install model.AppInstall, forceDelete bool, deleteBackup bool) error { +func deleteAppInstall(ctx context.Context, install model.AppInstall, deleteBackup bool) error { op := files.NewFileOp() appDir := install.GetPath() dir, _ := os.Stat(appDir) @@ -168,7 +168,7 @@ func deleteAppInstall(ctx context.Context, install model.AppInstall, forceDelete if err := appInstallRepo.Delete(ctx, install); err != nil { return err } - if err := deleteLink(ctx, &install); err != nil && !forceDelete { + if err := deleteLink(ctx, &install); err != nil { return err } if deleteBackup { diff --git a/backend/app/service/website.go b/backend/app/service/website.go index 87211354a..b4be7f59a 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -101,12 +101,18 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) error { req.Name = create.AppInstall.Name req.AppDetailId = create.AppInstall.AppDetailId req.Params = create.AppInstall.Params - var installErr error - appInstall, installErr = ServiceGroupApp.Install(ctx, req) - if installErr != nil { - return installErr + install, err := ServiceGroupApp.Install(ctx, req) + if err != nil { + return err } - website.AppInstallID = appInstall.ID + website.AppInstallID = install.ID + appInstall = install + } else { + install, err := appInstallRepo.GetFirst(commonRepo.WithByID(create.AppInstallID)) + if err != nil { + return err + } + appInstall = &install } } @@ -265,7 +271,7 @@ func (w WebsiteService) DeleteWebsite(req request.WebsiteDelete) error { return err } if !reflect.DeepEqual(model.AppInstall{}, appInstall) { - if err := deleteAppInstall(ctx, appInstall, req.ForceDelete, true); err != nil { + if err := deleteAppInstall(ctx, appInstall, true); err != nil && !req.ForceDelete { return err } } diff --git a/backend/app/service/website_utils.go b/backend/app/service/website_utils.go index eaaf1674e..2949e0eb5 100644 --- a/backend/app/service/website_utils.go +++ b/backend/app/service/website_utils.go @@ -408,7 +408,7 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri if err != nil { return err } - nginxConfFile := fmt.Sprintf("%s/nginx/%s/conf/conf.d/%s.conf", constant.AppInstallDir, nginxInfo.Name, website.PrimaryDomain) + nginxConfFile := fmt.Sprintf("%s/nginx/%s/conf/conf.d/%s.conf", constant.AppInstallDir, nginxInfo.Name, website.Alias) fileOp := files.NewFileOp() if err := fileOp.CopyFile(nginxConfFile, tmpDir); err != nil { return err @@ -423,12 +423,12 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri return err } websiteDir := fmt.Sprintf("%s/%s/%s", constant.AppInstallDir, app.App.Key, app.Name) - if err := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.app.tar.gz", website.PrimaryDomain), ""); err != nil { + if err := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.app.tar.gz", website.Alias), ""); err != nil { return err } } - websiteDir := path.Join(constant.AppInstallDir, "nginx", nginxInfo.Name, "www", "sites", website.PrimaryDomain) - if err := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.web.tar.gz", website.PrimaryDomain), ""); err != nil { + websiteDir := path.Join(constant.AppInstallDir, "nginx", nginxInfo.Name, "www", "sites", website.Alias) + if err := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.web.tar.gz", website.Alias), ""); err != nil { return err } if err := handleTar(tmpDir, fmt.Sprintf("%s/%s", baseDir, backupDir), backupName+".tar.gz", ""); err != nil {