remove temp path

This commit is contained in:
LinkLeong 2022-09-28 16:13:42 +01:00 committed by Tiger Wang
parent aff18fa091
commit f0448cd1b9
10 changed files with 32 additions and 39 deletions

3
.gitignore vendored
View file

@ -35,4 +35,5 @@ __debug_bin
main main
github.com github.com
.all-contributorsrc .all-contributorsrc
dist dist
CasaOS

View file

@ -60,8 +60,8 @@ BUILD_PATH=$(dirname "${BASH_SOURCE[0]}")/../../..
SOURCE_ROOT=${BUILD_PATH}/sysroot SOURCE_ROOT=${BUILD_PATH}/sysroot
APP_NAME="casaos" APP_NAME="casaos"
# APP_NAME_FORMAL="CasaOS" APP_NAME_FORMAL="CasaOS"
APP_NAME_FORMAL="casaos-alpha" #APP_NAME_FORMAL="casaos-alpha"
# check if migration is needed # check if migration is needed
SOURCE_BIN_PATH=${SOURCE_ROOT}/usr/bin SOURCE_BIN_PATH=${SOURCE_ROOT}/usr/bin
@ -153,7 +153,8 @@ pushd "${MIGRATION_SERVICE_DIR}"
continue continue
fi fi
MIGRATION_TOOL_URL=https://github.com/LinkLeong/"${APP_NAME_FORMAL}"/releases/download/"${VER2}"/linux-"${ARCH}"-"${APP_NAME}"-migration-tool-"${VER2}".tar.gz # MIGRATION_TOOL_URL=http://192.168.2.197:8000/v1/package/migration?type=release&name="${APP_NAME_FORMAL}"&version=${VER2}&arch=${ARCH}
MIGRATION_TOOL_URL=https://github.com/IceWhaleTech/"${APP_NAME_FORMAL}"/releases/download/"${VER2}"/linux-"${ARCH}"-"${APP_NAME}"-migration-tool-"${VER2}".tar.gz
echo "Dowloading ${MIGRATION_TOOL_URL}..." echo "Dowloading ${MIGRATION_TOOL_URL}..."
curl -sL -O "${MIGRATION_TOOL_URL}" curl -sL -O "${MIGRATION_TOOL_URL}"
done done

View file

@ -11,7 +11,6 @@ DateFormat = 2006-01-02
DBPath = /var/lib/casaos DBPath = /var/lib/casaos
ShellPath = /usr/share/casaos/shell ShellPath = /usr/share/casaos/shell
UserDataPath = /var/lib/casaos/conf UserDataPath = /var/lib/casaos/conf
TempPath = /var/lib/casaos/temp
[server] [server]
RunMode = release RunMode = release

View file

@ -11,7 +11,6 @@ DateFormat = 2006-01-02
DBPath = /var/lib/casaos DBPath = /var/lib/casaos
ShellPath = /usr/share/casaos/shell ShellPath = /usr/share/casaos/shell
UserDataPath = /var/lib/casaos/conf UserDataPath = /var/lib/casaos/conf
TempPath = /var/lib/casaos/temp
[server] [server]
RunMode = release RunMode = release

View file

@ -12,12 +12,12 @@ package model
import "time" import "time"
//系统配置 // 系统配置
type SysInfoModel struct { type SysInfoModel struct {
Name string //系统名称 Name string //系统名称
} }
//服务配置 // 服务配置
type ServerModel struct { type ServerModel struct {
HttpPort string HttpPort string
RunMode string RunMode string
@ -28,7 +28,7 @@ type ServerModel struct {
SocketPort string SocketPort string
} }
//服务配置 // 服务配置
type APPModel struct { type APPModel struct {
LogPath string LogPath string
LogSaveName string LogSaveName string
@ -40,20 +40,19 @@ type APPModel struct {
DateFormat string DateFormat string
DBPath string DBPath string
ShellPath string ShellPath string
TempPath string
} }
type CommonModel struct { type CommonModel struct {
RuntimePath string RuntimePath string
} }
//公共返回模型 // 公共返回模型
type Result struct { type Result struct {
Success int `json:"success" example:"200"` Success int `json:"success" example:"200"`
Message string `json:"message" example:"ok"` Message string `json:"message" example:"ok"`
Data interface{} `json:"data" example:"返回结果"` Data interface{} `json:"data" example:"返回结果"`
} }
//redis配置文件 // redis配置文件
type RedisModel struct { type RedisModel struct {
Host string Host string
Password string Password string

View file

@ -23,17 +23,17 @@ import (
"github.com/go-ini/ini" "github.com/go-ini/ini"
) )
//系统配置 // 系统配置
var SysInfo = &model.SysInfoModel{} var SysInfo = &model.SysInfoModel{}
//用户相关 // 用户相关
var AppInfo = &model.APPModel{} var AppInfo = &model.APPModel{}
var CommonInfo = &model.CommonModel{} var CommonInfo = &model.CommonModel{}
//var RedisInfo = &model.RedisModel{} //var RedisInfo = &model.RedisModel{}
//server相关 // server相关
var ServerInfo = &model.ServerModel{} var ServerInfo = &model.ServerModel{}
var SystemConfigInfo = &model.SystemConfig{} var SystemConfigInfo = &model.SystemConfig{}
@ -44,7 +44,7 @@ var FileSettingInfo = &model.FileSetting{}
var Cfg *ini.File var Cfg *ini.File
//初始化设置,获取系统的部分信息。 // 初始化设置,获取系统的部分信息。
func InitSetup(config string) { func InitSetup(config string) {
var configDir = USERCONFIGURL var configDir = USERCONFIGURL
@ -86,9 +86,6 @@ func InitSetup(config string) {
if len(AppInfo.UserDataPath) == 0 { if len(AppInfo.UserDataPath) == 0 {
AppInfo.UserDataPath = "/var/lib/casaos/conf" AppInfo.UserDataPath = "/var/lib/casaos/conf"
} }
if len(AppInfo.TempPath) == 0 {
AppInfo.TempPath = "/var/lib/casaos/temp"
}
if len(CommonInfo.RuntimePath) == 0 { if len(CommonInfo.RuntimePath) == 0 {
CommonInfo.RuntimePath = "/var/run/casaos" CommonInfo.RuntimePath = "/var/run/casaos"
} }
@ -97,7 +94,7 @@ func InitSetup(config string) {
} }
//映射 // 映射
func mapTo(section string, v interface{}) { func mapTo(section string, v interface{}) {
err := Cfg.Section(section).MapTo(v) err := Cfg.Section(section).MapTo(v)
if err != nil { if err != nil {

View file

@ -761,7 +761,7 @@ func ChangAppState(c *gin.Context) {
func ContainerLog(c *gin.Context) { func ContainerLog(c *gin.Context) {
appId := c.Param("id") appId := c.Param("id")
log, _ := service.MyService.Docker().DockerContainerLog(appId) log, _ := service.MyService.Docker().DockerContainerLog(appId)
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: log}) c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: string(log)})
} }
// @Summary 获取容器状态 // @Summary 获取容器状态

View file

@ -16,7 +16,6 @@ import (
"sync" "sync"
"github.com/IceWhaleTech/CasaOS/model" "github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/config"
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err" "github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file" "github.com/IceWhaleTech/CasaOS/pkg/utils/file"
"github.com/IceWhaleTech/CasaOS/service" "github.com/IceWhaleTech/CasaOS/service"
@ -267,6 +266,9 @@ func DirPath(c *gin.Context) {
pathList := []model.Path{} pathList := []model.Path{}
for i := 0; i < len(info); i++ { for i := 0; i < len(info); i++ {
if info[i].Name == ".temp" && info[i].IsDir {
continue
}
if _, ok := fileQueue[info[i].Path]; !ok { if _, ok := fileQueue[info[i].Path]; !ok {
pathList = append(pathList, info[i]) pathList = append(pathList, info[i])
} }
@ -367,7 +369,7 @@ func GetFileUpload(c *gin.Context) {
path := c.Query("path") path := c.Query("path")
dirPath := "" dirPath := ""
hash := file.GetHashByContent([]byte(fileName)) hash := file.GetHashByContent([]byte(fileName))
tempDir := config.AppInfo.TempPath + "/" + hash + strconv.Itoa(totalChunks) + "/" tempDir := filepath.Join(path, ".temp", hash+strconv.Itoa(totalChunks)) + "/"
if fileName != relative { if fileName != relative {
dirPath = strings.TrimSuffix(relative, fileName) dirPath = strings.TrimSuffix(relative, fileName)
tempDir += dirPath tempDir += dirPath
@ -406,7 +408,7 @@ func PostFileUpload(c *gin.Context) {
c.JSON(common_err.INVALID_PARAMS, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) c.JSON(common_err.INVALID_PARAMS, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
return return
} }
tempDir := config.AppInfo.TempPath + "/" + hash + strconv.Itoa(totalChunks) + "/" tempDir := filepath.Join(path, ".temp", hash+strconv.Itoa(totalChunks)) + "/"
if fileName != relative { if fileName != relative {
dirPath = strings.TrimSuffix(relative, fileName) dirPath = strings.TrimSuffix(relative, fileName)

View file

@ -130,10 +130,6 @@ func (o *casaService) AsyncGetServerList() (collection model.ServerAppListCollec
errr := json2.Unmarshal(results, &collection) errr := json2.Unmarshal(results, &collection)
if errr != nil { if errr != nil {
loger.Error("marshal error", zap.Any("err", err), zap.Any("content", string(results))) loger.Error("marshal error", zap.Any("err", err), zap.Any("content", string(results)))
} else {
if collection.Version == o.GetCasaosVersion().Version {
return collection, err
}
} }
head := make(map[string]string) head := make(map[string]string)
@ -204,10 +200,6 @@ func (o *casaService) AsyncGetServerCategoryList() ([]model.CategoryList, error)
err := json2.Unmarshal(results, &list) err := json2.Unmarshal(results, &list)
if err != nil { if err != nil {
loger.Error("marshal error", zap.Any("err", err), zap.Any("content", string(results))) loger.Error("marshal error", zap.Any("err", err), zap.Any("content", string(results)))
} else {
if list.Version == o.GetCasaosVersion().Version {
return list.Item, nil
}
} }
item := []model.CategoryList{} item := []model.CategoryList{}
head := make(map[string]string) head := make(map[string]string)

View file

@ -52,7 +52,7 @@ type DockerService interface {
DockerContainerStop(id string) error DockerContainerStop(id string) error
DockerContainerUpdateName(name, id string) (err error) DockerContainerUpdateName(name, id string) (err error)
DockerContainerUpdate(m model.CustomizationPostData, id string) (err error) DockerContainerUpdate(m model.CustomizationPostData, id string) (err error)
DockerContainerLog(name string) (string, error) DockerContainerLog(name string) ([]byte, error)
DockerContainerCommit(name string) DockerContainerCommit(name string)
DockerContainerList() []types.Container DockerContainerList() []types.Container
DockerNetworkModelList() []types.NetworkResource DockerNetworkModelList() []types.NetworkResource
@ -677,23 +677,26 @@ func (ds *dockerService) DockerContainerStart(name string) error {
} }
// 查看日志 // 查看日志
func (ds *dockerService) DockerContainerLog(name string) (string, error) { func (ds *dockerService) DockerContainerLog(name string) ([]byte, error) {
cli, err := client2.NewClientWithOpts(client2.FromEnv) cli, err := client2.NewClientWithOpts(client2.FromEnv)
if err != nil { if err != nil {
return "", err return []byte(""), err
} }
defer cli.Close() defer cli.Close()
body, err := cli.ContainerLogs(context.Background(), name, types.ContainerLogsOptions{ShowStderr: true, ShowStdout: true}) //body, err := cli.ContainerAttach(context.Background(), name, types.ContainerAttachOptions{Logs: true, Stream: false, Stdin: false, Stdout: false, Stderr: false})
body, err := cli.ContainerLogs(context.Background(), name, types.ContainerLogsOptions{ShowStdout: true, ShowStderr: true})
if err != nil { if err != nil {
return "", err return []byte(""), err
} }
defer body.Close() defer body.Close()
content, err := ioutil.ReadAll(body) content, err := ioutil.ReadAll(body)
//content, err := ioutil.ReadAll(body)
if err != nil { if err != nil {
return "", err return []byte(""), err
} }
return string(content), nil return content, nil
} }
func DockerContainerStats1() error { func DockerContainerStats1() error {