1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

fix: 解决本地应用备份恢复报错的问题 (#2879)

Refs https://github.com/1Panel-dev/1Panel/issues/2854
This commit is contained in:
zhengkunwang 2023-11-10 15:06:07 +08:00 committed by GitHub
parent 24098e397f
commit 8660ac6fe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 7 deletions

View File

@ -27,18 +27,18 @@ type AppInstall struct {
} }
func (i *AppInstall) GetPath() string { func (i *AppInstall) GetPath() string {
return path.Join(i.getAppPath(), i.Name) return path.Join(i.GetAppPath(), i.Name)
} }
func (i *AppInstall) GetComposePath() string { func (i *AppInstall) GetComposePath() string {
return path.Join(i.getAppPath(), i.Name, "docker-compose.yml") return path.Join(i.GetAppPath(), i.Name, "docker-compose.yml")
} }
func (i *AppInstall) GetEnvPath() string { func (i *AppInstall) GetEnvPath() string {
return path.Join(i.getAppPath(), i.Name, ".env") return path.Join(i.GetAppPath(), i.Name, ".env")
} }
func (i *AppInstall) getAppPath() string { func (i *AppInstall) GetAppPath() string {
if i.App.Resource == constant.AppResourceLocal { if i.App.Resource == constant.AppResourceLocal {
return path.Join(constant.LocalAppInstallDir, strings.TrimPrefix(i.App.Key, constant.AppResourceLocal)) return path.Join(constant.LocalAppInstallDir, strings.TrimPrefix(i.App.Key, constant.AppResourceLocal))
} else { } else {

View File

@ -225,7 +225,7 @@ func handleAppRecover(install *model.AppInstall, recoverFile string, isRollback
_ = fileOp.Rename(appDir, backPath) _ = fileOp.Rename(appDir, backPath)
_ = fileOp.CreateDir(appDir, 0755) _ = fileOp.CreateDir(appDir, 0755)
if err := handleUnTar(tmpPath+"/app.tar.gz", fmt.Sprintf("%s/%s", constant.AppInstallDir, install.App.Key)); err != nil { if err := handleUnTar(tmpPath+"/app.tar.gz", install.GetAppPath()); err != nil {
global.LOG.Errorf("handle recover from app.tar.gz failed, err: %v", err) global.LOG.Errorf("handle recover from app.tar.gz failed, err: %v", err)
_ = fileOp.DeleteDir(appDir) _ = fileOp.DeleteDir(appDir)
_ = fileOp.Rename(backPath, appDir) _ = fileOp.Rename(backPath, appDir)
@ -248,8 +248,6 @@ func handleAppRecover(install *model.AppInstall, recoverFile string, isRollback
oldInstall.AppId = install.AppId oldInstall.AppId = install.AppId
oldInstall.AppDetailId = install.AppDetailId oldInstall.AppDetailId = install.AppDetailId
oldInstall.App.ID = install.AppId oldInstall.App.ID = install.AppId
oldInstall.Env = strings.ReplaceAll(oldInstall.Env, oldInstall.ContainerName, install.ContainerName)
oldInstall.ContainerName = install.ContainerName
if err := appInstallRepo.Save(context.Background(), &oldInstall); err != nil { if err := appInstallRepo.Save(context.Background(), &oldInstall); err != nil {
global.LOG.Errorf("save db app install failed, err: %v", err) global.LOG.Errorf("save db app install failed, err: %v", err)
return err return err