1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-14 01:34:47 +08:00

fix: 解决网站选择已有应用安装失败的BUG

This commit is contained in:
zhengkunwang223 2022-12-22 15:44:38 +08:00 committed by zhengkunwang223
parent e33bf51941
commit 505caa4d49
4 changed files with 19 additions and 13 deletions

View File

@ -153,7 +153,7 @@ func (a AppInstallService) Operate(req request.AppInstalledOperate) error {
install.Status = constant.Running install.Status = constant.Running
case constant.Delete: case constant.Delete:
tx, ctx := getTxAndContext() 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() tx.Rollback()
return err return err
} }

View File

@ -152,7 +152,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
return nil 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() op := files.NewFileOp()
appDir := install.GetPath() appDir := install.GetPath()
dir, _ := os.Stat(appDir) 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 { if err := appInstallRepo.Delete(ctx, install); err != nil {
return err return err
} }
if err := deleteLink(ctx, &install); err != nil && !forceDelete { if err := deleteLink(ctx, &install); err != nil {
return err return err
} }
if deleteBackup { if deleteBackup {

View File

@ -101,12 +101,18 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) error {
req.Name = create.AppInstall.Name req.Name = create.AppInstall.Name
req.AppDetailId = create.AppInstall.AppDetailId req.AppDetailId = create.AppInstall.AppDetailId
req.Params = create.AppInstall.Params req.Params = create.AppInstall.Params
var installErr error install, err := ServiceGroupApp.Install(ctx, req)
appInstall, installErr = ServiceGroupApp.Install(ctx, req) if err != nil {
if installErr != nil { return err
return installErr
} }
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 return err
} }
if !reflect.DeepEqual(model.AppInstall{}, appInstall) { 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 return err
} }
} }

View File

@ -408,7 +408,7 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri
if err != nil { if err != nil {
return err 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() fileOp := files.NewFileOp()
if err := fileOp.CopyFile(nginxConfFile, tmpDir); err != nil { if err := fileOp.CopyFile(nginxConfFile, tmpDir); err != nil {
return err return err
@ -423,12 +423,12 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri
return err return err
} }
websiteDir := fmt.Sprintf("%s/%s/%s", constant.AppInstallDir, app.App.Key, app.Name) 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 return err
} }
} }
websiteDir := path.Join(constant.AppInstallDir, "nginx", nginxInfo.Name, "www", "sites", website.PrimaryDomain) websiteDir := path.Join(constant.AppInstallDir, "nginx", nginxInfo.Name, "www", "sites", website.Alias)
if err := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.web.tar.gz", website.PrimaryDomain), ""); err != nil { if err := handleTar(websiteDir, tmpDir, fmt.Sprintf("%s.web.tar.gz", website.Alias), ""); err != nil {
return err return err
} }
if err := handleTar(tmpDir, fmt.Sprintf("%s/%s", baseDir, backupDir), backupName+".tar.gz", ""); err != nil { if err := handleTar(tmpDir, fmt.Sprintf("%s/%s", baseDir, backupDir), backupName+".tar.gz", ""); err != nil {