From 514731cf4b5dd97dc871b9fd84c4d9938900ef79 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 19 Nov 2021 20:35:38 +0100 Subject: WIP DEBUG --- s3/file.go | 53 ++++++++++++++++++++++++++++++++++------------------- s3/stat.go | 2 ++ 2 files changed, 36 insertions(+), 19 deletions(-) (limited to 's3') diff --git a/s3/file.go b/s3/file.go index aa4f227..40b40a1 100644 --- a/s3/file.go +++ b/s3/file.go @@ -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) { diff --git a/s3/stat.go b/s3/stat.go index 96b0c24..c91a757 100644 --- a/s3/stat.go +++ b/s3/stat.go @@ -1,6 +1,7 @@ package s3 import ( + "log" "errors" "io/fs" "path" @@ -104,6 +105,7 @@ func (s *S3Stat) Name() string { } func (s *S3Stat) Size() int64 { + log.Println("stat size: ", s.obj.Size) return s.obj.Size } -- cgit v1.2.3