From 82e9e72c704c2cd58675da780d4a222c4e78ca33 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:55:49 +0800 Subject: [PATCH] feat: Fix the initialization errors of GeoIP (#7345) --- backend/app/service/upgrade.go | 3 ++- backend/init/lang/lang.go | 2 +- cmd/server/cmd/restore.go | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/app/service/upgrade.go b/backend/app/service/upgrade.go index 378632e79..bcc5fe667 100644 --- a/backend/app/service/upgrade.go +++ b/backend/app/service/upgrade.go @@ -212,7 +212,8 @@ func (u *UpgradeService) handleRollback(originalDir string, errStep int) { global.LOG.Errorf("rollback 1panel failed, err: %v", err) } _, _ = cmd.Execf("cp -r %s /usr/local/bin", path.Join(originalDir, "lang")) - _, _ = cmd.Execf("cp %s %s", path.Join(originalDir, "GeoIP.mmdb"), path.Join(global.CONF.System.BaseDir, "1panel/geo/")) + geoPath := path.Join(global.CONF.System.BaseDir, "1panel/geo") + _, _ = cmd.Execf("mkdir %s && cp %s %s/", geoPath, path.Join(originalDir, "GeoIP.mmdb"), geoPath) if errStep == 2 { return diff --git a/backend/init/lang/lang.go b/backend/init/lang/lang.go index 4dfe30ba6..e5a041376 100644 --- a/backend/init/lang/lang.go +++ b/backend/init/lang/lang.go @@ -74,7 +74,7 @@ func initLang() { downloadGeoFromRemote(fileOp, geoPath) return } - std, err := cmd.Execf("cp %s %s/", path.Join(tmpPath, "GeoIP.mmdb"), path.Dir(geoPath)) + std, err := cmd.Execf("mkdir %s && cp %s %s/", path.Dir(geoPath), path.Join(tmpPath, "GeoIP.mmdb"), path.Dir(geoPath)) if err != nil { global.LOG.Errorf("load geo ip from package failed, std: %s, err: %v", std, err) return diff --git a/cmd/server/cmd/restore.go b/cmd/server/cmd/restore.go index 449a58d22..b41c98eef 100644 --- a/cmd/server/cmd/restore.go +++ b/cmd/server/cmd/restore.go @@ -55,7 +55,8 @@ var restoreCmd = &cobra.Command{ return err } _, _ = cmdUtils.Execf("cp -r %s /usr/local/bin", path.Join(tmpPath, "lang")) - _, _ = cmdUtils.Execf("cp %s %s", path.Join(tmpPath, "GeoIP.mmdb"), path.Join(global.CONF.System.BaseDir, "1panel/geo/")) + geoPath := path.Join(global.CONF.System.BaseDir, "1panel/geo") + _, _ = cmdUtils.Execf("mkdir %s && cp %s %s/", geoPath, path.Join(tmpPath, "GeoIP.mmdb"), geoPath) fmt.Println(i18n.GetMsgByKeyForCmd("RestoreStep3")) if err := common.CopyFile(path.Join(tmpPath, "1panel.service"), "/etc/systemd/system"); err != nil { return err