Skip to content

Commit

Permalink
fix: get disk size for macOS and other arch
Browse files Browse the repository at this point in the history
  • Loading branch information
huskar-t committed Sep 2, 2024
1 parent 81b15b4 commit 6454018
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions space.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !windows
// +build !windows
//go:build linux && !s390x && !netbsd
// +build linux,!s390x,!netbsd

package rotatelogs

Expand Down
19 changes: 19 additions & 0 deletions space_bsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build darwin || dragonfly || s390x
// +build darwin dragonfly s390x

package rotatelogs

import (
"golang.org/x/sys/unix"
)

func GetDiskSize(dir string) (total uint64, avail uint64, err error) {
fs := unix.Statfs_t{}
err = unix.Statfs(dir, &fs)
if err != nil {
return 0, 0, err
}
avail = fs.Bavail * uint64(fs.Bsize)
total = fs.Blocks * uint64(fs.Bsize)
return total, avail, nil
}
17 changes: 17 additions & 0 deletions space_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build netbsd
// +build netbsd

package rotatelogs

import "golang.org/x/sys/unix"

func GetDiskSize(dir string) (total uint64, avail uint64, err error) {
fs := unix.Statvfs_t{}
err = unix.Statvfs(dir, &fs)
if err != nil {
return 0, 0, err
}
avail = fs.Bavail * fs.Frsize
total = fs.Blocks * fs.Frsize
return total, avail, nil
}
17 changes: 17 additions & 0 deletions space_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build openbsd
// +build openbsd

package rotatelogs

import "golang.org/x/sys/unix"

func GetDiskSize(dir string) (total uint64, avail uint64, err error) {
fs := unix.Statfs_t{}
err = unix.Statfs(dir, &fs)
if err != nil {
return 0, 0, err
}
avail = fs.F_blocks * uint64(fs.F_bsize)
total = uint64(fs.F_bavail) * uint64(fs.F_bsize)
return total, avail, nil
}

0 comments on commit 6454018

Please sign in to comment.