Skip to content

Commit

Permalink
remove temp path
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed Sep 28, 2022
1 parent 84dfa7f commit 4bace9b
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ __debug_bin
main
github.com
.all-contributorsrc
dist
dist
CasaOS
7 changes: 4 additions & 3 deletions build/scripts/migration/script.d/03-migrate-casaos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ BUILD_PATH=$(dirname "${BASH_SOURCE[0]}")/../../..
SOURCE_ROOT=${BUILD_PATH}/sysroot

APP_NAME="casaos"
# APP_NAME_FORMAL="CasaOS"
APP_NAME_FORMAL="casaos-alpha"
APP_NAME_FORMAL="CasaOS"
#APP_NAME_FORMAL="casaos-alpha"

# check if migration is needed
SOURCE_BIN_PATH=${SOURCE_ROOT}/usr/bin
Expand Down Expand Up @@ -153,7 +153,8 @@ pushd "${MIGRATION_SERVICE_DIR}"
continue
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}..."
curl -sL -O "${MIGRATION_TOOL_URL}"
done
Expand Down
1 change: 0 additions & 1 deletion build/sysroot/etc/casaos/casaos.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ DateFormat = 2006-01-02
DBPath = /var/lib/casaos
ShellPath = /usr/share/casaos/shell
UserDataPath = /var/lib/casaos/conf
TempPath = /var/lib/casaos/temp

[server]
RunMode = release
Expand Down
1 change: 0 additions & 1 deletion conf/conf.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ DateFormat = 2006-01-02
DBPath = /var/lib/casaos
ShellPath = /usr/share/casaos/shell
UserDataPath = /var/lib/casaos/conf
TempPath = /var/lib/casaos/temp

[server]
RunMode = release
Expand Down
11 changes: 5 additions & 6 deletions model/sys_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ package model

import "time"

//系统配置
// 系统配置
type SysInfoModel struct {
Name string //系统名称
}

//服务配置
// 服务配置
type ServerModel struct {
HttpPort string
RunMode string
Expand All @@ -28,7 +28,7 @@ type ServerModel struct {
SocketPort string
}

//服务配置
// 服务配置
type APPModel struct {
LogPath string
LogSaveName string
Expand All @@ -40,20 +40,19 @@ type APPModel struct {
DateFormat string
DBPath string
ShellPath string
TempPath string
}
type CommonModel struct {
RuntimePath string
}

//公共返回模型
// 公共返回模型
type Result struct {
Success int `json:"success" example:"200"`
Message string `json:"message" example:"ok"`
Data interface{} `json:"data" example:"返回结果"`
}

//redis配置文件
// redis配置文件
type RedisModel struct {
Host string
Password string
Expand Down
13 changes: 5 additions & 8 deletions pkg/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ import (
"github.com/go-ini/ini"
)

//系统配置
// 系统配置
var SysInfo = &model.SysInfoModel{}

//用户相关
// 用户相关
var AppInfo = &model.APPModel{}

var CommonInfo = &model.CommonModel{}

//var RedisInfo = &model.RedisModel{}

//server相关
// server相关
var ServerInfo = &model.ServerModel{}

var SystemConfigInfo = &model.SystemConfig{}
Expand All @@ -44,7 +44,7 @@ var FileSettingInfo = &model.FileSetting{}

var Cfg *ini.File

//初始化设置,获取系统的部分信息。
// 初始化设置,获取系统的部分信息。
func InitSetup(config string) {

var configDir = USERCONFIGURL
Expand Down Expand Up @@ -86,9 +86,6 @@ func InitSetup(config string) {
if len(AppInfo.UserDataPath) == 0 {
AppInfo.UserDataPath = "/var/lib/casaos/conf"
}
if len(AppInfo.TempPath) == 0 {
AppInfo.TempPath = "/var/lib/casaos/temp"
}
if len(CommonInfo.RuntimePath) == 0 {
CommonInfo.RuntimePath = "/var/run/casaos"
}
Expand All @@ -97,7 +94,7 @@ func InitSetup(config string) {

}

//映射
// 映射
func mapTo(section string, v interface{}) {
err := Cfg.Section(section).MapTo(v)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion route/v1/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ func ChangAppState(c *gin.Context) {
func ContainerLog(c *gin.Context) {
appId := c.Param("id")
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 获取容器状态
Expand Down
8 changes: 5 additions & 3 deletions route/v1/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"sync"

"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/file"
"github.com/IceWhaleTech/CasaOS/service"
Expand Down Expand Up @@ -267,6 +266,9 @@ func DirPath(c *gin.Context) {

pathList := []model.Path{}
for i := 0; i < len(info); i++ {
if info[i].Name == ".temp" && info[i].IsDir {
continue
}
if _, ok := fileQueue[info[i].Path]; !ok {
pathList = append(pathList, info[i])
}
Expand Down Expand Up @@ -367,7 +369,7 @@ func GetFileUpload(c *gin.Context) {
path := c.Query("path")
dirPath := ""
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 {
dirPath = strings.TrimSuffix(relative, fileName)
tempDir += dirPath
Expand Down Expand Up @@ -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)})
return
}
tempDir := config.AppInfo.TempPath + "/" + hash + strconv.Itoa(totalChunks) + "/"
tempDir := filepath.Join(path, ".temp", hash+strconv.Itoa(totalChunks)) + "/"

if fileName != relative {
dirPath = strings.TrimSuffix(relative, fileName)
Expand Down
8 changes: 0 additions & 8 deletions service/casa.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ func (o *casaService) AsyncGetServerList() (collection model.ServerAppListCollec
errr := json2.Unmarshal(results, &collection)
if errr != nil {
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)
Expand Down Expand Up @@ -204,10 +200,6 @@ func (o *casaService) AsyncGetServerCategoryList() ([]model.CategoryList, error)
err := json2.Unmarshal(results, &list)
if err != nil {
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{}
head := make(map[string]string)
Expand Down
17 changes: 10 additions & 7 deletions service/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type DockerService interface {
DockerContainerStop(id string) error
DockerContainerUpdateName(name, 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)
DockerContainerList() []types.Container
DockerNetworkModelList() []types.NetworkResource
Expand Down Expand Up @@ -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)
if err != nil {
return "", err
return []byte(""), err
}
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 {
return "", err
return []byte(""), err
}

defer body.Close()
content, err := ioutil.ReadAll(body)
//content, err := ioutil.ReadAll(body)
if err != nil {
return "", err
return []byte(""), err
}
return string(content), nil
return content, nil
}

func DockerContainerStats1() error {
Expand Down

0 comments on commit 4bace9b

Please sign in to comment.