Fix file cut failure
This commit is contained in:
parent
346b0f5d97
commit
bd73141ddf
5 changed files with 33 additions and 118 deletions
|
@ -524,3 +524,26 @@ func DirSizeB(path string) (int64, error) {
|
|||
})
|
||||
return size, err
|
||||
}
|
||||
|
||||
func MoveFile(sourcePath, destPath string) error {
|
||||
inputFile, err := os.Open(sourcePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Couldn't open source file: %s", err)
|
||||
}
|
||||
outputFile, err := os.Create(destPath)
|
||||
if err != nil {
|
||||
inputFile.Close()
|
||||
return fmt.Errorf("Couldn't open dest file: %s", err)
|
||||
}
|
||||
defer outputFile.Close()
|
||||
_, err = io.Copy(outputFile, inputFile)
|
||||
inputFile.Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Writing to output file failed: %s", err)
|
||||
}
|
||||
err = os.Remove(sourcePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed removing original file: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-06-17 14:01:25
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-24 10:13:52
|
||||
* @LastEditTime: 2022-07-04 16:26:22
|
||||
* @FilePath: /CasaOS/pkg/utils/jwt/jwt_helper.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
|
@ -11,12 +11,10 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
|
||||
loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
@ -109,7 +107,7 @@ func GetToken(username, pwd string) string {
|
|||
if err == nil {
|
||||
return token
|
||||
} else {
|
||||
loger2.NewOLoger().Fatal(fmt.Sprintf("Get Token Fail: %V", err))
|
||||
//loger2.NewOLoger().Fatal(fmt.Sprintf("Get Token Fail: %V", err))
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
package loger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
file2 "github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||
)
|
||||
|
||||
//定义一个int的别名
|
||||
type Level int
|
||||
|
||||
type OLog interface {
|
||||
Debug(v ...interface{})
|
||||
Info(v ...interface{})
|
||||
Warn(v ...interface{})
|
||||
Error(v ...interface{})
|
||||
Fatal(v ...interface{})
|
||||
Path() string
|
||||
}
|
||||
|
||||
type oLog struct {
|
||||
}
|
||||
|
||||
var (
|
||||
F *os.File
|
||||
DefaultPrefix = ""
|
||||
DefaultCallerDepth = 2
|
||||
logger *log.Logger
|
||||
logPrefix = ""
|
||||
levelFlags = []string{"DEBUG", "INFO", "WARN", "ERROR", "FATAL"}
|
||||
)
|
||||
|
||||
//iota在const关键字出现时将被重置为0(const内部的第一行之前),const中每新增一行常量声明将使iota计数一次(iota可理解为const语句块中的行索引)。
|
||||
const (
|
||||
DEBUG Level = iota
|
||||
INFO
|
||||
WARN
|
||||
ERROR
|
||||
FATAL
|
||||
)
|
||||
|
||||
//日志初始化
|
||||
func LogSetupOld() {
|
||||
var err error
|
||||
filePath := fmt.Sprintf("%s", config.AppInfo.LogPath)
|
||||
fileName := fmt.Sprintf("%s.%s",
|
||||
config.AppInfo.LogSaveName,
|
||||
config.AppInfo.LogFileExt,
|
||||
)
|
||||
F, err = file2.MustOpen(fileName, filePath)
|
||||
if err != nil {
|
||||
log.Fatalf("logging.Setup err: %v", err)
|
||||
}
|
||||
|
||||
logger = log.New(F, DefaultPrefix, log.LstdFlags)
|
||||
|
||||
}
|
||||
func (o *oLog) Path() string {
|
||||
filePath := fmt.Sprintf("%s", config.AppInfo.LogPath)
|
||||
fileName := fmt.Sprintf("%s.%s",
|
||||
config.AppInfo.LogSaveName,
|
||||
config.AppInfo.LogFileExt,
|
||||
)
|
||||
return filePath + fileName
|
||||
}
|
||||
func (o *oLog) Debug(v ...interface{}) {
|
||||
setPrefix(DEBUG)
|
||||
logger.Println(v)
|
||||
}
|
||||
|
||||
func (o *oLog) Info(v ...interface{}) {
|
||||
setPrefix(INFO)
|
||||
logger.Println(v)
|
||||
}
|
||||
|
||||
func (o *oLog) Warn(v ...interface{}) {
|
||||
setPrefix(WARN)
|
||||
logger.Println(v)
|
||||
}
|
||||
|
||||
func (o *oLog) Error(v ...interface{}) {
|
||||
setPrefix(ERROR)
|
||||
logger.Println(v)
|
||||
}
|
||||
|
||||
func (o *oLog) Fatal(v ...interface{}) {
|
||||
setPrefix(FATAL)
|
||||
logger.Println(v)
|
||||
}
|
||||
|
||||
func setPrefix(level Level) {
|
||||
_, file, line, ok := runtime.Caller(DefaultCallerDepth)
|
||||
if ok {
|
||||
logPrefix = fmt.Sprintf("[%s][%s:%d]", levelFlags[level], filepath.Base(file), line)
|
||||
} else {
|
||||
logPrefix = fmt.Sprintf("[%s]", levelFlags[level])
|
||||
}
|
||||
|
||||
logger.SetPrefix(logPrefix)
|
||||
}
|
||||
|
||||
func NewOLoger() OLog {
|
||||
return &oLog{}
|
||||
}
|
|
@ -518,7 +518,6 @@ func PostOperateFileOrDir(c *gin.Context) {
|
|||
uid := uuid.NewV4().String()
|
||||
service.FileQueue.Store(uid, list)
|
||||
service.OpStrArr = append(service.OpStrArr, uid)
|
||||
|
||||
if len(service.OpStrArr) == 1 {
|
||||
go service.ExecOpFile()
|
||||
go service.CheckFileStatus()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2021-12-20 14:15:46
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-06-16 16:47:46
|
||||
* @LastEditTime: 2022-07-04 16:18:23
|
||||
* @FilePath: /CasaOS/service/file.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
|
@ -101,12 +101,16 @@ func FileOperate(k string) {
|
|||
os.RemoveAll(temp.To + "/" + lastPath)
|
||||
}
|
||||
}
|
||||
|
||||
err := os.Rename(v.From, temp.To+"/"+lastPath)
|
||||
if err != nil {
|
||||
loger.Debug("file move error", zap.Any("err", err))
|
||||
loger.Error("file move error", zap.Any("err", err))
|
||||
err = file.MoveFile(v.From, temp.To+"/"+lastPath)
|
||||
if err != nil {
|
||||
loger.Error("MoveFile error", zap.Any("err", err))
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
} else if temp.Type == "copy" {
|
||||
err := file.CopyDir(v.From, temp.To, temp.Style)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue