du_windows.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //go:build windows
  2. // +build windows
  3. /*
  4. Copyright The containerd Authors.
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. */
  15. package fs
  16. import (
  17. "context"
  18. "os"
  19. "path/filepath"
  20. )
  21. func diskUsage(ctx context.Context, roots ...string) (Usage, error) {
  22. var size int64
  23. // TODO(stevvooe): Support inodes (or equivalent) for windows.
  24. for _, root := range roots {
  25. if err := filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
  26. if err != nil {
  27. return err
  28. }
  29. select {
  30. case <-ctx.Done():
  31. return ctx.Err()
  32. default:
  33. }
  34. size += fi.Size()
  35. return nil
  36. }); err != nil {
  37. return Usage{}, err
  38. }
  39. }
  40. return Usage{
  41. Size: size,
  42. }, nil
  43. }
  44. func diffUsage(ctx context.Context, a, b string) (Usage, error) {
  45. var size int64
  46. if err := Changes(ctx, a, b, func(kind ChangeKind, _ string, fi os.FileInfo, err error) error {
  47. if err != nil {
  48. return err
  49. }
  50. if kind == ChangeKindAdd || kind == ChangeKindModify {
  51. size += fi.Size()
  52. return nil
  53. }
  54. return nil
  55. }); err != nil {
  56. return Usage{}, err
  57. }
  58. return Usage{
  59. Size: size,
  60. }, nil
  61. }