mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
lib/ur: Use sysctl syscall to get RAM size on Mac (#6468)
This commit is contained in:
parent
79a758be3c
commit
1c47fae206
1
go.mod
1
go.mod
@ -42,6 +42,7 @@ require (
|
|||||||
github.com/willf/bloom v2.0.3+incompatible
|
github.com/willf/bloom v2.0.3+incompatible
|
||||||
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d
|
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d
|
||||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297
|
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297
|
||||||
|
golang.org/x/sys v0.0.0-20191224085550-c709ea063b76
|
||||||
golang.org/x/text v0.3.2
|
golang.org/x/text v0.3.2
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
|
||||||
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
|
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
|
||||||
|
@ -6,26 +6,9 @@
|
|||||||
|
|
||||||
package ur
|
package ur
|
||||||
|
|
||||||
import (
|
import "golang.org/x/sys/unix"
|
||||||
"errors"
|
|
||||||
"os/exec"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func memorySize() (int64, error) {
|
func memorySize() (int64, error) {
|
||||||
cmd := exec.Command("sysctl", "hw.memsize")
|
mem, err := unix.SysctlUint64("hw.memsize")
|
||||||
out, err := cmd.Output()
|
return int64(mem), err
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
fs := strings.Fields(string(out))
|
|
||||||
if len(fs) != 2 {
|
|
||||||
return 0, errors.New("sysctl parse error")
|
|
||||||
}
|
|
||||||
bytes, err := strconv.ParseInt(fs[1], 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return bytes, nil
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user