du_windows.go 1.6 KB

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