cmd/utils: add workaround for FreeBSD statfs quirk (#22310)

Make geth build on FreeBSD, fixes #22309.
This commit is contained in:
Guillaume Ballet 2021-02-15 19:37:09 +01:00 committed by GitHub
parent 7d1b711c7d
commit 08c878acd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -31,5 +31,12 @@ func getFreeDiskSpace(path string) (uint64, error) {
} }
// Available blocks * size per block = available space in bytes // Available blocks * size per block = available space in bytes
return stat.Bavail * uint64(stat.Bsize), nil var bavail = stat.Bavail
if stat.Bavail < 0 {
// FreeBSD can have a negative number of blocks available
// because of the grace limit.
bavail = 0
}
//nolint:unconvert
return uint64(bavail) * uint64(stat.Bsize), nil
} }