redis-shake工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
875 B

package utils
import (
"RedisShake/internal/log"
"os"
"path/filepath"
)
func CreateEmptyDir(dir string) {
if IsExist(dir) {
err := os.RemoveAll(dir)
if err != nil {
log.Panicf("remove dir failed. dir=[%s], error=[%v]", dir, err)
}
}
err := os.MkdirAll(dir, 0777)
if err != nil {
log.Panicf("mkdir failed. dir=[%s], error=[%v]", dir, err)
}
log.Debugf("CreateEmptyDir: dir=[%s]", dir)
}
func IsExist(path string) bool {
_, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return false
} else {
log.Panicf(err.Error())
}
}
return true
}
func GetFileSize(path string) uint64 {
fi, err := os.Stat(path)
if err != nil {
log.Panicf(err.Error())
}
return uint64(fi.Size())
}
func GetAbsPath(path string) string {
absolutePath, err := filepath.Abs(path)
if err != nil {
log.Panicf(err.Error())
}
return absolutePath
}