Browse Source

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

Make geth build on FreeBSD, fixes #22309.
Guillaume Ballet 4 years ago
parent
commit
08c878acd2
1 changed files with 8 additions and 1 deletions
  1. 8 1
      cmd/utils/diskusage.go

+ 8 - 1
cmd/utils/diskusage.go

@@ -31,5 +31,12 @@ func getFreeDiskSpace(path string) (uint64, error) {
 	}
 
 	// 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
 }