mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 10:17:17 +08:00
refactor: 备份重构
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user