mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-17 12:58:51 +08:00
fix: Fix version upgrade failure in some scenarios (#11322)
This commit is contained in:
parent
3db8e47679
commit
9424d061fa
2 changed files with 21 additions and 2 deletions
|
|
@ -156,13 +156,13 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error {
|
|||
|
||||
global.LOG.Info("backup original data successful, now start to upgrade!")
|
||||
|
||||
if err := files.CopyItem(false, true, path.Join(tmpDir, "1panel-core"), "/usr/local/bin"); err != nil {
|
||||
if err := files.CopyFileWithRename(path.Join(tmpDir, "1panel-core"), "/usr/local/bin/1panel-core.tmp"); err != nil {
|
||||
global.LOG.Errorf("upgrade 1panel-core failed, err: %v", err)
|
||||
_ = settingRepo.Update("SystemStatus", "Free")
|
||||
u.handleRollback(originalDir, 1)
|
||||
return
|
||||
}
|
||||
if err := files.CopyItem(false, true, path.Join(tmpDir, "1panel-agent"), "/usr/local/bin"); err != nil {
|
||||
if err := files.CopyFileWithRename(path.Join(tmpDir, "1panel-agent"), "/usr/local/bin/1panel-agent.tmp"); err != nil {
|
||||
global.LOG.Errorf("upgrade 1panel-agent failed, err: %v", err)
|
||||
_ = settingRepo.Update("SystemStatus", "Free")
|
||||
u.handleRollback(originalDir, 1)
|
||||
|
|
|
|||
|
|
@ -73,6 +73,25 @@ func CopyItem(isDir, withName bool, src, dst string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func CopyFileWithRename(src, dst string) error {
|
||||
srcInfo, err := os.Stat(path.Dir(src))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := os.Stat(path.Dir(dst)); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
_ = os.MkdirAll(path.Dir(dst), srcInfo.Mode())
|
||||
}
|
||||
}
|
||||
if err := cmd.RunDefaultBashCf("cp -f %s %s.tmp", src, dst); err != nil {
|
||||
return fmt.Errorf("handle cp file failed, err: %v", err)
|
||||
}
|
||||
if err = cmd.RunDefaultBashCf("mv %s.tmp %s", dst, dst); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func HandleTar(sourceDir, targetDir, name, exclusionRules string, secret string) error {
|
||||
if _, err := os.Stat(targetDir); err != nil && os.IsNotExist(err) {
|
||||
if err = os.MkdirAll(targetDir, os.ModePerm); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue