mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-03 15:47:35 -04:00
unix: use ParseDirent in testGetdirentries
Use ParseDirent to get the directory entries instead of manually parsing them. This fixes the test on dragonfly where type Dirent doesn't have a Reclen member. Manually tested on darwin, dragonfly and freebsd. Change-Id: I234c6aff78243fec8bba8784c1d4948fbbb4d027 Reviewed-on: https://go-review.googlesource.com/c/sys/+/183226 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Benny Siegert <bsiegert@gmail.com>
This commit is contained in:
committed by
Tobias Klauser
parent
d432491b91
commit
e93b963712
@@ -14,7 +14,6 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
@@ -49,7 +48,6 @@ func testGetdirentries(t *testing.T, count int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read files using Getdirentries
|
// Read files using Getdirentries
|
||||||
var names2 []string
|
|
||||||
fd, err := unix.Open(d, unix.O_RDONLY, 0)
|
fd, err := unix.Open(d, unix.O_RDONLY, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Open: %v", err)
|
t.Fatalf("Open: %v", err)
|
||||||
@@ -57,6 +55,7 @@ func testGetdirentries(t *testing.T, count int) {
|
|||||||
defer unix.Close(fd)
|
defer unix.Close(fd)
|
||||||
var base uintptr
|
var base uintptr
|
||||||
var buf [2048]byte
|
var buf [2048]byte
|
||||||
|
names2 := make([]string, 0, count)
|
||||||
for {
|
for {
|
||||||
n, err := unix.Getdirentries(fd, buf[:], &base)
|
n, err := unix.Getdirentries(fd, buf[:], &base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -67,17 +66,15 @@ func testGetdirentries(t *testing.T, count int) {
|
|||||||
}
|
}
|
||||||
data := buf[:n]
|
data := buf[:n]
|
||||||
for len(data) > 0 {
|
for len(data) > 0 {
|
||||||
dirent := (*unix.Dirent)(unsafe.Pointer(&data[0]))
|
var bc int
|
||||||
data = data[dirent.Reclen:]
|
bc, _, names2 = unix.ParseDirent(data, -1, names2)
|
||||||
name := make([]byte, dirent.Namlen)
|
if bc == 0 && len(data) > 0 {
|
||||||
for i := 0; i < int(dirent.Namlen); i++ {
|
t.Fatal("no progress")
|
||||||
name[i] = byte(dirent.Name[i])
|
|
||||||
}
|
}
|
||||||
names2 = append(names2, string(name))
|
data = data[bc:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
names = append(names, ".", "..") // Getdirentries returns these also
|
|
||||||
sort.Strings(names)
|
sort.Strings(names)
|
||||||
sort.Strings(names2)
|
sort.Strings(names2)
|
||||||
if strings.Join(names, ":") != strings.Join(names2, ":") {
|
if strings.Join(names, ":") != strings.Join(names2, ":") {
|
||||||
|
|||||||
Reference in New Issue
Block a user