-
Notifications
You must be signed in to change notification settings - Fork 53
/
readdir.go
63 lines (47 loc) · 1.04 KB
/
readdir.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package hdfs
import (
"context"
"errors"
"io"
"github.com/colinmarc/hdfs/v2"
"go.beyondstorage.io/v5/types"
)
const defaultListObjectLimit = 100
type listDirInput struct {
rp string
dir *hdfs.FileReader
continuationToken string
}
func (i *listDirInput) ContinuationToken() string {
return i.continuationToken
}
func (s *Storage) listDirNext(ctx context.Context, page *types.ObjectPage) (err error) {
input := page.Status.(*listDirInput)
if input.dir == nil {
input.dir, err = s.hdfs.Open(input.rp)
if err != nil {
return
}
}
fileList, err := input.dir.Readdir(defaultListObjectLimit)
if err != nil && errors.Is(err, io.EOF) {
_ = input.dir.Close()
input.dir = nil
return types.IterateDone
}
for _, f := range fileList {
o := s.newObject(true)
o.ID = input.rp
o.Path = f.Name()
if f.Mode().IsDir() {
o.Mode |= types.ModeDir
}
if f.Mode().IsRegular() {
o.Mode |= types.ModeRead
}
o.SetContentLength(f.Size())
page.Data = append(page.Data, o)
input.continuationToken = o.Path
}
return
}