From 9887b2d7310e4706e4a6ac23bb9fb4de53a5a408 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 15 Sep 2020 18:26:11 -0700 Subject: [PATCH] healtcheck: add extra build tags+files for netbsd and openbsd Without these changes, the disk check portions won't compile on these platforms. --- healthcheck/diskcheck.go | 2 +- healthcheck/diskcheck_netbsd.go | 17 +++++++++++++++++ healthcheck/diskcheck_openbsd.go | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 healthcheck/diskcheck_netbsd.go create mode 100644 healthcheck/diskcheck_openbsd.go diff --git a/healthcheck/diskcheck.go b/healthcheck/diskcheck.go index c3e2cbb2..ed230d27 100644 --- a/healthcheck/diskcheck.go +++ b/healthcheck/diskcheck.go @@ -1,4 +1,4 @@ -// +build !windows,!solaris +// +build !windows,!solaris,!netbsd,!openbsd package healthcheck diff --git a/healthcheck/diskcheck_netbsd.go b/healthcheck/diskcheck_netbsd.go new file mode 100644 index 00000000..d44330b7 --- /dev/null +++ b/healthcheck/diskcheck_netbsd.go @@ -0,0 +1,17 @@ +package healthcheck + +import "golang.org/x/sys/unix" + +// AvailableDiskSpace returns ratio of available disk space to total capacity +// for solaris. +func AvailableDiskSpace(path string) (float64, error) { + s := unix.Statvfs_t{} + err := unix.Statvfs(path, &s) + if err != nil { + return 0, err + } + + // Calculate our free blocks/total blocks to get our total ratio of + // free blocks. + return float64(s.Bfree) / float64(s.Blocks), nil +} diff --git a/healthcheck/diskcheck_openbsd.go b/healthcheck/diskcheck_openbsd.go new file mode 100644 index 00000000..4738db9a --- /dev/null +++ b/healthcheck/diskcheck_openbsd.go @@ -0,0 +1,17 @@ +package healthcheck + +import "golang.org/x/sys/unix" + +// AvailableDiskSpace returns ratio of available disk space to total capacity +// for solaris. +func AvailableDiskSpace(path string) (float64, error) { + s := unix.Statfs_t{} + err := unix.Statfs(path, &s) + if err != nil { + return 0, err + } + + // Calculate our free blocks/total blocks to get our total ratio of + // free blocks. + return float64(s.F_bfree) / float64(s.F_blocks), nil +}