services/uss: Fix object not iterated fully
@@ -63,6 +63,16 @@ func (s *Storage) ListDir(path string, pairs ...*types.Pair) (err error) {
ch := make(chan *upyun.FileInfo, 200)
go func() {
+ errlock.Lock()
+ defer errlock.Unlock()
+
+ err = s.bucket.List(&upyun.GetObjectsConfig{
+ Path: rp,
+ ObjectsChan: ch,
+ MaxListLevel: maxListLevel,
+ })
+ }()
+
for v := range ch {
if v.IsDir {
if !opt.HasDirFunc {
@@ -82,21 +92,11 @@ func (s *Storage) ListDir(path string, pairs ...*types.Pair) (err error) {
o, err := s.formatFileObject(v)
if err != nil {
- return
+ return err
}
opt.FileFunc(o)
}
- }()
-
- err = s.bucket.List(&upyun.GetObjectsConfig{
- Path: rp,
- ObjectsChan: ch,
- MaxListLevel: maxListLevel,
- })
- if err != nil {
- return err
- }
return
}
@@ -128,23 +128,25 @@ func (s *Storage) ListPrefix(prefix string, pairs ...*types.Pair) (err error) {
errlock.Lock()
defer errlock.Unlock()
- o, err := s.formatFileObject(v)
- if err != nil {
- return
- }
-
- opt.ObjectFunc(o)
- }
- }()
-
err = s.bucket.List(&upyun.GetObjectsConfig{
Path: rp,
ObjectsChan: ch,
MaxListLevel: maxListLevel,
})
+ }()
+
+ for v := range ch {
+ if v.IsDir {
+ continue
+ }
+
+ o, err := s.formatFileObject(v)
if err != nil {
return err
}
+
+ opt.ObjectFunc(o)
+ }
return
}
