1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +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
}
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
}

View File

@ -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)
}
}