2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 10:17:17 +08:00

refactor: 备份重构

This commit is contained in:
耗子
2024-10-13 17:43:36 +08:00
parent bf9c0bc12e
commit 5668bc1afd
18 changed files with 967 additions and 76 deletions

View File

@@ -6,6 +6,8 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
)
// Remove 删除文件/目录
@@ -158,3 +160,29 @@ func IsDir(path string) bool {
}
return info.IsDir()
}
// SizeX 获取路径大小du命令
func SizeX(path string) (int64, error) {
out, err := exec.Command("du", "-sb", path).Output()
if err != nil {
return 0, err
}
parts := strings.Fields(string(out))
if len(parts) == 0 {
return 0, fmt.Errorf("无法解析 du 输出")
}
return strconv.ParseInt(parts[0], 10, 64)
}
// CountX 统计目录下文件数
func CountX(path string) (int64, error) {
out, err := exec.Command("find", path, "-printf", ".").Output()
if err != nil {
return 0, err
}
count := len(string(out))
return int64(count), nil
}