Skip to content

Commit bdd40b1

Browse files
committed
kodoutil.FileInfo
1 parent 9a08b57 commit bdd40b1

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.dll
88
*.so
99
*.dylib
10+
*.go~
1011

1112
# Test binary, built with `go test -c`
1213
*.test
@@ -18,4 +19,4 @@
1819
# vendor/
1920

2021
# Go workspace file
21-
go.work
22+
go.work*

kodofs.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

kodoutil/kodoutil.go

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ type WalkFunc = func(path string, info fs.FileInfo, err error) error
3636

3737
func (mac *Credentials) Walk(ctx context.Context, bucket, dir string, fn WalkFunc) (err error) {
3838
m := kodo.NewBucketManager((*auth.Credentials)(mac), nil)
39-
if !strings.HasSuffix(dir, "/") {
40-
dir += "/"
41-
}
42-
marker := ""
39+
dir = strings.TrimPrefix(dir, "/")
4340
prefix := kodo.ListInputOptionsPrefix(dir)
41+
limit := kodo.ListInputOptionsLimit(1000)
42+
marker := ""
4443
for {
45-
ret, hasNext, e := m.ListFilesWithContext(ctx, bucket, prefix, kodo.ListInputOptionsMarker(marker))
44+
ret, hasNext, e := m.ListFilesWithContext(ctx, bucket, prefix, limit, kodo.ListInputOptionsMarker(marker))
4645
if e != nil {
4746
return e
4847
}
@@ -51,7 +50,7 @@ func (mac *Credentials) Walk(ctx context.Context, bucket, dir string, fn WalkFun
5150
if !strings.HasPrefix(key, "/") {
5251
key = "/" + key
5352
}
54-
fn(key, &dataFileInfo{key, item.Fsize}, nil)
53+
fn(key, NewFileInfo(key, item.Fsize), nil)
5554
}
5655
if !hasNext {
5756
break
@@ -63,32 +62,47 @@ func (mac *Credentials) Walk(ctx context.Context, bucket, dir string, fn WalkFun
6362

6463
// -----------------------------------------------------------------------------------------
6564

66-
type dataFileInfo struct {
67-
name string
68-
size int64
65+
// FileInfo describes a single file in an file system.
66+
// It implements fs.FileInfo and fs.DirEntry.
67+
type FileInfo struct {
68+
name string
69+
size int64
70+
Mtime time.Time // default use zero time
71+
}
72+
73+
func NewFileInfo(name string, size int64) *FileInfo {
74+
return &FileInfo{name: name, size: size}
6975
}
7076

71-
func (p *dataFileInfo) Name() string {
77+
func (p *FileInfo) Name() string {
7278
return path.Base(p.name)
7379
}
7480

75-
func (p *dataFileInfo) Size() int64 {
81+
func (p *FileInfo) Size() int64 {
7682
return p.size
7783
}
7884

79-
func (p *dataFileInfo) Mode() fs.FileMode {
80-
return 0
85+
func (p *FileInfo) Mode() fs.FileMode {
86+
return fs.ModeIrregular
8187
}
8288

83-
func (p *dataFileInfo) ModTime() time.Time {
84-
return time.Time{} // zero time
89+
func (p *FileInfo) Type() fs.FileMode {
90+
return fs.ModeIrregular
8591
}
8692

87-
func (p *dataFileInfo) IsDir() bool {
93+
func (p *FileInfo) ModTime() time.Time {
94+
return p.Mtime
95+
}
96+
97+
func (p *FileInfo) IsDir() bool {
8898
return false
8999
}
90100

91-
func (p *dataFileInfo) Sys() interface{} {
101+
func (p *FileInfo) Info() (fs.FileInfo, error) {
102+
return p, nil
103+
}
104+
105+
func (p *FileInfo) Sys() interface{} {
92106
return nil
93107
}
94108

0 commit comments

Comments
 (0)