Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fs/du.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ type Usage struct {

// DiskUsage counts the number of inodes and disk usage for the resources under
// path.
func DiskUsage(roots ...string) (Usage, error) {
return diskUsage(roots...)
func DiskUsage(ctx context.Context, roots ...string) (Usage, error) {
return diskUsage(ctx, roots...)
}

// DiffUsage counts the numbers of inodes and disk usage in the
Expand Down
8 changes: 7 additions & 1 deletion fs/du_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func newInode(stat *syscall.Stat_t) inode {
}
}

func diskUsage(roots ...string) (Usage, error) {
func diskUsage(ctx context.Context, roots ...string) (Usage, error) {

var (
size int64
Expand All @@ -37,6 +37,12 @@ func diskUsage(roots ...string) (Usage, error) {
return err
}

select {
case <-ctx.Done():
return ctx.Err()
default:
}

inoKey := newInode(fi.Sys().(*syscall.Stat_t))
if _, ok := inodes[inoKey]; !ok {
inodes[inoKey] = struct{}{}
Expand Down
8 changes: 7 additions & 1 deletion fs/du_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
)

func diskUsage(roots ...string) (Usage, error) {
func diskUsage(ctx context.Context, roots ...string) (Usage, error) {
var (
size int64
)
Expand All @@ -21,6 +21,12 @@ func diskUsage(roots ...string) (Usage, error) {
return err
}

select {
case <-ctx.Done():
return ctx.Err()
default:
}

size += fi.Size()
return nil
}); err != nil {
Expand Down