From 7c6e96e10e819bd027e9d73cd837d254d3b2f0fb Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Fri, 18 Nov 2022 18:38:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9D=E5=A7=8B=E5=8C=96=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/app_utils.go | 24 +++++++++++------------- backend/init/viper/viper.go | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index cc400af06..31a4963bd 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -524,17 +524,16 @@ func getAppFromOss() error { return err } appDir := constant.AppResourceDir - oldListFile := path.Join(appDir, "list.json") - content, err := os.ReadFile(oldListFile) - if err != nil { - return err - } - list := &dto.AppList{} - if err := json.Unmarshal(content, list); err != nil { - return err - } - if list.Version == ossConfig.Version { - return nil + content, _ := os.ReadFile(path.Join(appDir, "apps.json")) + + if content != nil { + oldConfig := &dto.AppOssConfig{} + if err := json.Unmarshal(content, oldConfig); err != nil { + return err + } + if oldConfig.Version == ossConfig.Version { + return nil + } } fileOp := files.NewFileOp() @@ -542,8 +541,7 @@ func getAppFromOss() error { return err } - packageName := path.Base(ossConfig.Package) - packagePath := path.Join(constant.ResourceDir, packageName) + packagePath := path.Join(constant.ResourceDir, path.Base(ossConfig.Package)) if err := fileOp.DownloadFile(ossConfig.Package, packagePath); err != nil { return err } diff --git a/backend/init/viper/viper.go b/backend/init/viper/viper.go index a75050fe9..5e4a8db60 100644 --- a/backend/init/viper/viper.go +++ b/backend/init/viper/viper.go @@ -5,6 +5,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/configs" "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" + "github.com/1Panel-dev/1Panel/backend/utils/files" "path" "github.com/fsnotify/fsnotify" @@ -42,5 +43,17 @@ func InitDir() { constant.BackupDir = path.Join(constant.DefaultDataDir, "backup") constant.AppBackupDir = path.Join(constant.BackupDir, "apps") - //TODO 创建文件夹 + fileOp := files.NewFileOp() + createDir(fileOp, constant.DefaultDataDir) + createDir(fileOp, constant.ResourceDir) + createDir(fileOp, constant.AppResourceDir) + createDir(fileOp, constant.AppInstallDir) + createDir(fileOp, constant.BackupDir) + createDir(fileOp, constant.AppBackupDir) +} + +func createDir(fileOp files.FileOp, dirPath string) { + if !fileOp.Stat(dirPath) { + _ = fileOp.CreateDir(dirPath, 0755) + } }