* fix!: use `int64` for file sizes Unfortunately Go templates cannot unconditionally dereference pointers, so we use a magic value of -1 instead of a nil pointer to indicate a file size that doesn't exist. This also means having to change surrounding code, for example the `humanize` function. * Update `CHANGELOG.md`
20 lines
351 B
Go
20 lines
351 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func diskFree(wd string) string {
|
|
var stat unix.Statfs_t
|
|
|
|
if err := unix.Statfs(wd, &stat); err != nil {
|
|
log.Printf("diskfree: %s", err)
|
|
return ""
|
|
}
|
|
|
|
// Available blocks * size per block = available space in bytes
|
|
return "df: " + humanize(int64(stat.F_bavail)*int64(stat.F_bsize))
|
|
}
|