feat:WAF、网站监控增加日志定时清理 (#7057)
Some checks are pending
sync2gitee / repo-sync (push) Waiting to run

This commit is contained in:
zhengkunwang 2024-11-14 18:38:01 +08:00 committed by GitHub
parent 03e9077c9a
commit 82e15cb3e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 18 deletions

View File

@ -24,7 +24,7 @@ type FileTree struct {
}
type DirSizeRes struct {
Size float64 `json:"size" validate:"required"`
Size int64 `json:"size" validate:"required"`
}
type FileProcessKeys struct {

View File

@ -5,7 +5,6 @@ import (
"io"
"io/fs"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
@ -403,19 +402,6 @@ func (f *FileService) DirSize(req request.DirSizeReq) (response.DirSizeRes, erro
if req.Path == "/proc" {
return res, nil
}
cmd := exec.Command("du", "-s", req.Path)
output, err := cmd.Output()
if err == nil {
fields := strings.Fields(string(output))
if len(fields) == 2 {
var cmdSize int64
_, err = fmt.Sscanf(fields[0], "%d", &cmdSize)
if err == nil {
res.Size = float64(cmdSize * 1024)
return res, nil
}
}
}
fo := files.NewFileOp()
size, err := fo.GetDirSize(req.Path)
if err != nil {

View File

@ -12,6 +12,7 @@ import (
"io/fs"
"net/http"
"os"
"os/exec"
"path"
"path/filepath"
"strconv"
@ -502,9 +503,22 @@ func (f FileOp) CopyFile(src, dst string) error {
return cmd.ExecCmd(fmt.Sprintf(`cp -f '%s' '%s'`, src, dst+"/"))
}
func (f FileOp) GetDirSize(path string) (float64, error) {
func (f FileOp) GetDirSize(path string) (int64, error) {
duCmd := exec.Command("du", "-s", path)
output, err := duCmd.Output()
if err == nil {
fields := strings.Fields(string(output))
if len(fields) == 2 {
var cmdSize int64
_, err = fmt.Sscanf(fields[0], "%d", &cmdSize)
if err == nil {
return cmdSize * 1024, nil
}
}
}
var size int64
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
err = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
@ -516,7 +530,7 @@ func (f FileOp) GetDirSize(path string) (float64, error) {
if err != nil {
return 0, err
}
return float64(size), nil
return size, nil
}
func getFormat(cType CompressType) archiver.CompressedArchive {

View File

@ -127,6 +127,7 @@ html {
color: #8f959e;
width: 100%;
display: inline-block;
height: 12px;
}
.input-error {