1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-16 18:54:43 +08:00

feat: 初始化目录

This commit is contained in:
zhengkunwang223 2022-11-18 18:38:52 +08:00 committed by zhengkunwang223
parent 972d0995e1
commit 7c6e96e10e
2 changed files with 25 additions and 14 deletions

View File

@ -524,17 +524,16 @@ func getAppFromOss() error {
return err return err
} }
appDir := constant.AppResourceDir appDir := constant.AppResourceDir
oldListFile := path.Join(appDir, "list.json") content, _ := os.ReadFile(path.Join(appDir, "apps.json"))
content, err := os.ReadFile(oldListFile)
if err != nil { if content != nil {
return err oldConfig := &dto.AppOssConfig{}
} if err := json.Unmarshal(content, oldConfig); err != nil {
list := &dto.AppList{} return err
if err := json.Unmarshal(content, list); err != nil { }
return err if oldConfig.Version == ossConfig.Version {
} return nil
if list.Version == ossConfig.Version { }
return nil
} }
fileOp := files.NewFileOp() fileOp := files.NewFileOp()
@ -542,8 +541,7 @@ func getAppFromOss() error {
return err return err
} }
packageName := path.Base(ossConfig.Package) packagePath := path.Join(constant.ResourceDir, path.Base(ossConfig.Package))
packagePath := path.Join(constant.ResourceDir, packageName)
if err := fileOp.DownloadFile(ossConfig.Package, packagePath); err != nil { if err := fileOp.DownloadFile(ossConfig.Package, packagePath); err != nil {
return err return err
} }

View File

@ -5,6 +5,7 @@ import (
"github.com/1Panel-dev/1Panel/backend/configs" "github.com/1Panel-dev/1Panel/backend/configs"
"github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/files"
"path" "path"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
@ -42,5 +43,17 @@ func InitDir() {
constant.BackupDir = path.Join(constant.DefaultDataDir, "backup") constant.BackupDir = path.Join(constant.DefaultDataDir, "backup")
constant.AppBackupDir = path.Join(constant.BackupDir, "apps") 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)
}
} }