Implement btrfs usage

Implements btrfs usage using a double walking diff and
counting the result. Walking gives the most accurate
count and includes inode usage.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2017-12-04 10:48:22 -08:00
parent f6df9f6632
commit 3bc4e69ba1
4 changed files with 120 additions and 17 deletions

View File

@@ -3,6 +3,7 @@
package fs
import (
"context"
"os"
"path/filepath"
)
@@ -31,3 +32,29 @@ func diskUsage(roots ...string) (Usage, error) {
Size: size,
}, nil
}
func diffUsage(ctx context.Context, a, b string) (Usage, error) {
var (
size int64
)
if err := Changes(ctx, a, b, func(kind ChangeKind, _ string, fi os.FileInfo, err error) error {
if err != nil {
return err
}
if kind == ChangeKindAdd || kind == ChangeKindModify {
size += fi.Size()
return nil
}
return nil
}); err != nil {
return Usage{}, err
}
return Usage{
Size: size,
}, nil
}