package pkgtools import ( "io/fs" "math" "os" "strconv" "time" ) const maxLockWait = 10 * time.Second func CopyFile(dst string, src string) error { return ErrNotImplemented } func HumanReadableSize(size int64) string { suffixes := []string{ "B", "K", "M", "G", "T", } base := math.Log(float64(size)) / math.Log(1024) newSize := math.Ceil(math.Pow(1024, base-math.Floor(base))*10) / 10 newSuffix := suffixes[int(math.Floor(base))] ret := strconv.FormatFloat(newSize, 'f', -1, 64) + newSuffix return ret } func IsFile(path string) (bool, error) { info, err := os.Stat(path) if err != nil { return false, err } return info.Mode().IsRegular(), nil } func IsDir(path string) (bool, error) { info, err := os.Stat(path) if err != nil { return false, err } return info.IsDir(), nil } func IsSymlink(path string) (bool, error) { info, err := os.Stat(path) if err != nil { return false, err } return info.Mode() == fs.ModeSymlink, nil } func FileSize(fp string) (int64, error) { info, err := os.Stat(fp) if err != nil { return 0, err } return info.Size(), nil }