vendor: Update github.com/calmh/du (ref #4079)
This commit is contained in:
parent
da35820fd5
commit
49c1527724
|
@ -1,14 +0,0 @@
|
||||||
du
|
|
||||||
==
|
|
||||||
|
|
||||||
Get total and available disk space on a given volume.
|
|
||||||
|
|
||||||
Documentation
|
|
||||||
-------------
|
|
||||||
|
|
||||||
http://godoc.org/github.com/calmh/du
|
|
||||||
|
|
||||||
License
|
|
||||||
-------
|
|
||||||
|
|
||||||
Public Domain
|
|
|
@ -1,6 +1,7 @@
|
||||||
package du
|
package du
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
@ -13,14 +14,20 @@ func Get(path string) (Usage, error) {
|
||||||
|
|
||||||
var u Usage
|
var u Usage
|
||||||
|
|
||||||
|
pathw, err := syscall.UTF16PtrFromString(path)
|
||||||
|
if err != nil {
|
||||||
|
return Usage{}, err
|
||||||
|
}
|
||||||
|
|
||||||
ret, _, err := c.Call(
|
ret, _, err := c.Call(
|
||||||
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))),
|
uintptr(unsafe.Pointer(pathw)),
|
||||||
uintptr(unsafe.Pointer(&u.FreeBytes)),
|
uintptr(unsafe.Pointer(&u.FreeBytes)),
|
||||||
uintptr(unsafe.Pointer(&u.TotalBytes)),
|
uintptr(unsafe.Pointer(&u.TotalBytes)),
|
||||||
uintptr(unsafe.Pointer(&u.AvailBytes)))
|
uintptr(unsafe.Pointer(&u.AvailBytes)))
|
||||||
|
runtime.KeepAlive(pathw)
|
||||||
|
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
return u, err
|
return Usage{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return u, nil
|
return u, nil
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package du
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestDiskUsage(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
path string
|
||||||
|
ok bool
|
||||||
|
}{
|
||||||
|
{"c:\\", true},
|
||||||
|
{"c:\\windows", true},
|
||||||
|
{"c:\\aux", false},
|
||||||
|
{"c:\\does-not-exist-09sadkjhdsa98234bj23hgasd98", false},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
res, err := Get(tc.path)
|
||||||
|
if tc.ok {
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error Get(%q) => %v", tc.path, err)
|
||||||
|
} else if res.TotalBytes == 0 || res.AvailBytes == 0 || res.FreeBytes == 0 {
|
||||||
|
t.Errorf("Suspicious result Get(%q) => %v", tc.path, res)
|
||||||
|
}
|
||||||
|
} else if err == nil {
|
||||||
|
t.Errorf("Unexpected nil error in Get(%q)", tc.path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,8 +34,8 @@
|
||||||
{
|
{
|
||||||
"importpath": "github.com/calmh/du",
|
"importpath": "github.com/calmh/du",
|
||||||
"repository": "https://github.com/calmh/du",
|
"repository": "https://github.com/calmh/du",
|
||||||
"vcs": "",
|
"vcs": "git",
|
||||||
"revision": "3c0690cca16228b97741327b1b6781397afbdb24",
|
"revision": "dd9dc2043353249b2910b29dcfd6f6d4e64f39be",
|
||||||
"branch": "master"
|
"branch": "master"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue