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.

path.go 974B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package util
  5. import (
  6. "os"
  7. "path/filepath"
  8. )
  9. // EnsureAbsolutePath ensure that a path is absolute, making it
  10. // relative to absoluteBase if necessary
  11. func EnsureAbsolutePath(path string, absoluteBase string) string {
  12. if filepath.IsAbs(path) {
  13. return path
  14. }
  15. return filepath.Join(absoluteBase, path)
  16. }
  17. const notRegularFileMode os.FileMode = os.ModeDir | os.ModeSymlink | os.ModeNamedPipe | os.ModeSocket | os.ModeDevice | os.ModeCharDevice | os.ModeIrregular
  18. // GetDirectorySize returns the dumb disk consumption for a given path
  19. func GetDirectorySize(path string) (int64, error) {
  20. var size int64
  21. err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
  22. if info != nil && (info.Mode()&notRegularFileMode) == 0 {
  23. size += info.Size()
  24. }
  25. return err
  26. })
  27. return size, err
  28. }