File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ type Usage struct {
1010
1111// DiskUsage counts the number of inodes and disk usage for the resources under
1212// path.
13- func DiskUsage (roots ... string ) (Usage , error ) {
14- return diskUsage (roots ... )
13+ func DiskUsage (ctx context. Context , roots ... string ) (Usage , error ) {
14+ return diskUsage (ctx , roots ... )
1515}
1616
1717// DiffUsage counts the numbers of inodes and disk usage in the
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ func newInode(stat *syscall.Stat_t) inode {
2424 }
2525}
2626
27- func diskUsage (roots ... string ) (Usage , error ) {
27+ func diskUsage (ctx context. Context , roots ... string ) (Usage , error ) {
2828
2929 var (
3030 size int64
@@ -37,6 +37,12 @@ func diskUsage(roots ...string) (Usage, error) {
3737 return err
3838 }
3939
40+ select {
41+ case <- ctx .Done ():
42+ return ctx .Err ()
43+ default :
44+ }
45+
4046 inoKey := newInode (fi .Sys ().(* syscall.Stat_t ))
4147 if _ , ok := inodes [inoKey ]; ! ok {
4248 inodes [inoKey ] = struct {}{}
Original file line number Diff line number Diff line change 88 "path/filepath"
99)
1010
11- func diskUsage (roots ... string ) (Usage , error ) {
11+ func diskUsage (ctx context. Context , roots ... string ) (Usage , error ) {
1212 var (
1313 size int64
1414 )
@@ -21,6 +21,12 @@ func diskUsage(roots ...string) (Usage, error) {
2121 return err
2222 }
2323
24+ select {
25+ case <- ctx .Done ():
26+ return ctx .Err ()
27+ default :
28+ }
29+
2430 size += fi .Size ()
2531 return nil
2632 }); err != nil {
You can’t perform that action at this time.
0 commit comments