forked from forgejo/forgejo
Backport #22392 Fix #22386 `GetDirectorySize` moved as `getDirectorySize` because it becomes a special function which should not be put in `util`. Co-authored-by: Jason Song <i@wolfogre.com>
This commit is contained in:
parent
af8151cbb9
commit
9a6d78eaa8
5 changed files with 42 additions and 18 deletions
|
@ -23,20 +23,6 @@ func EnsureAbsolutePath(path, absoluteBase string) string {
|
|||
return filepath.Join(absoluteBase, path)
|
||||
}
|
||||
|
||||
const notRegularFileMode os.FileMode = os.ModeSymlink | os.ModeNamedPipe | os.ModeSocket | os.ModeDevice | os.ModeCharDevice | os.ModeIrregular
|
||||
|
||||
// GetDirectorySize returns the disk consumption for a given path
|
||||
func GetDirectorySize(path string) (int64, error) {
|
||||
var size int64
|
||||
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
|
||||
if info != nil && (info.Mode()¬RegularFileMode) == 0 {
|
||||
size += info.Size()
|
||||
}
|
||||
return err
|
||||
})
|
||||
return size, err
|
||||
}
|
||||
|
||||
// IsDir returns true if given path is a directory,
|
||||
// or returns false when it's a file or does not exist.
|
||||
func IsDir(dir string) (bool, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue