Skip to content

Commit

Permalink
rename accessor to reduce confusion
Browse files Browse the repository at this point in the history
as Free() makes me think of the statfs Free field which is
the space available to a privileged user. I am reporting the
space available to a non-privileged user, which is known as the field
Avail...
  • Loading branch information
teleivo committed Sep 9, 2021
1 parent 59d1e55 commit 7b33566
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions fstat/fstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func (fs FilesystemStat) Used() uint64 {
return (fs.Blocks - fs.Bavail) * uint64(fs.Bsize)
}

// Free returns the number of bytes available to a non-privileged user.
func (fs FilesystemStat) Free() uint64 {
// Available returns the number of bytes available to a non-privileged user.
func (fs FilesystemStat) Available() uint64 {
return fs.Bavail * uint64(fs.Bsize)
}

Expand Down
10 changes: 5 additions & 5 deletions fstat/fstat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import (
)

func TestFilesystemStat(t *testing.T) {
t.Run("FreeTotalUsed", func(t *testing.T) {
t.Run("AvailableTotalUsed", func(t *testing.T) {
fs := FilesystemStat(unix.Statfs_t{
Ffree: 200, // total free disk space
Bavail: 100, // free disk space accessible by a non-privileged user
Blocks: 400,
Bsize: 1024,
})

if want := uint64(100 * 1024); fs.Free() != want {
t.Errorf("FilesystemStat.Free() got %d, want %d", fs.Free(), want)
if want := uint64(100 * 1024); fs.Available() != want {
t.Errorf("FilesystemStat.Available() got %d, want %d", fs.Available(), want)
}
if want := uint64(400 * 1024); fs.Total() != want {
t.Errorf("FilesystemStat.Total() got %d, want %d", fs.Free(), want)
t.Errorf("FilesystemStat.Total() got %d, want %d", fs.Total(), want)
}
if want := uint64((400 - 100) * 1024); fs.Used() != want {
t.Errorf("FilesystemStat.Used() got %d, want %d", fs.Free(), want)
t.Errorf("FilesystemStat.Used() got %d, want %d", fs.Used(), want)
}
})
t.Run("HasReachedLimit", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func checkDiskUsage(basedir string, limit uint64) (Report, error) {
if fstat.HasReachedLimit(limit) {
r.Limits = append(r.Limits, Stats{
Path: file.Name(),
Free: fstat.Free(),
Free: fstat.Available(),
Used: fstat.Used(),
Total: fstat.Total(),
})
Expand Down

0 comments on commit 7b33566

Please sign in to comment.