diff options
Diffstat (limited to 's3/file.go')
-rw-r--r-- | s3/file.go | 53 |
1 files changed, 34 insertions, 19 deletions
@@ -73,6 +73,7 @@ func (f *S3File) loadObject() error { } func (f *S3File) Read(p []byte) (n int, err error) { + log.Printf("s3 Read\n") //if f.Stat() & OBJECT == 0 { /* @FIXME Ideally we would check against OBJECT but we need a non OPAQUE_KEY */ // return 0, os.ErrInvalid //} @@ -84,6 +85,7 @@ func (f *S3File) Read(p []byte) (n int, err error) { } func (f *S3File) ReadAt(p []byte, off int64) (n int, err error) { + log.Printf("s3 ReadAt %v\n", off) if err := f.loadObject(); err != nil { return 0, err } @@ -194,30 +196,43 @@ func (f *S3File) readDirRoot(count int) ([]fs.FileInfo, error) { } func (f *S3File) readDirChild(count int) ([]fs.FileInfo, error) { - prefix := f.Path.Key - if len(prefix) > 0 && prefix[len(prefix)-1:] != "/" { - prefix = prefix + "/" - } + var err error + if f.entries == nil { + prefix := f.Path.Key + if len(prefix) > 0 && prefix[len(prefix)-1:] != "/" { + prefix = prefix + "/" + } - objs_info := f.fs.mc.ListObjects(f.fs.ctx, f.Path.Bucket, minio.ListObjectsOptions{ - Prefix: prefix, - Recursive: false, - }) + objs_info := f.fs.mc.ListObjects(f.fs.ctx, f.Path.Bucket, minio.ListObjectsOptions{ + Prefix: prefix, + Recursive: false, + }) - entries := make([]fs.FileInfo, 0) - for object := range objs_info { - if object.Err != nil { - return nil, object.Err - } - //log.Println("Stat from GarageFile.readDirChild()", path.Join("/", f.path.bucket, object.Key)) - nf, err := NewS3StatFromObjectInfo(f.fs, f.Path.Bucket, object) - if err != nil { - return nil, err + f.entries = make([]fs.FileInfo, 0) + for object := range objs_info { + if object.Err != nil { + return nil, object.Err + } + //log.Println("Stat from GarageFile.readDirChild()", path.Join("/", f.path.bucket, object.Key)) + nf, err := NewS3StatFromObjectInfo(f.fs, f.Path.Bucket, object) + if err != nil { + return nil, err + } + f.entries = append(f.entries, nf) } - entries = append(entries, nf) } + beg := f.pos + end := int64(len(f.entries)) + if count > 0 { + end = min(beg + int64(count), end) + } + f.pos = end - return entries, nil + if end - beg == 0 { + err = io.EOF + } + + return f.entries[beg:end], err } func (f *S3File) Stat() (fs.FileInfo, error) { |