mirror of
https://github.com/acepanel/panel.git
synced 2026-02-06 08:47:16 +08:00
feat: new tools methods
This commit is contained in:
@@ -150,3 +150,30 @@ func Cp(src, dst string) bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Size 获取路径大小
|
||||
func Size(path string) int64 {
|
||||
var size int64
|
||||
|
||||
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
|
||||
size += info.Size()
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
facades.Log().Errorf("[面板][Helpers] 获取路径 %s 大小失败: %s", path, err.Error())
|
||||
return 0
|
||||
}
|
||||
|
||||
return size
|
||||
}
|
||||
|
||||
// FileSize 获取文件大小
|
||||
func FileSize(path string) int64 {
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
facades.Log().Errorf("[面板][Helpers] 获取文件 %s 大小失败: %s", path, err.Error())
|
||||
return 0
|
||||
}
|
||||
|
||||
return info.Size()
|
||||
}
|
||||
|
||||
@@ -104,3 +104,13 @@ func (s *SystemHelperTestSuite) TestEmpty() {
|
||||
s.True(Empty("/tmp/123"))
|
||||
s.False(Empty("/tmp"))
|
||||
}
|
||||
|
||||
func (s *SystemHelperTestSuite) TestSize() {
|
||||
s.Equal(int64(0), Size("/tmp/123"))
|
||||
s.NotEqual(int64(0), Size("/tmp"))
|
||||
}
|
||||
|
||||
func (s *SystemHelperTestSuite) TestFileSize() {
|
||||
s.Equal(int64(0), FileSize("/tmp/123"))
|
||||
s.NotEqual(int64(0), FileSize("/tmp"))
|
||||
}
|
||||
|
||||
@@ -63,8 +63,7 @@ Prepare_system() {
|
||||
useradd -s /sbin/nologin -g www www
|
||||
fi
|
||||
|
||||
rm -rf /etc/localtime
|
||||
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
||||
timedatectl set-timezone Asia/Shanghai
|
||||
|
||||
[ -s /etc/selinux/config ] && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
|
||||
setenforce 0 > /dev/null 2>&1
|
||||
|
||||
Reference in New Issue
Block a user