diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2021-11-19 20:35:38 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2021-11-19 20:35:38 +0100 |
commit | 514731cf4b5dd97dc871b9fd84c4d9938900ef79 (patch) | |
tree | a15575ef430fe3ada0c8c79ce740770bce737c74 /s3 | |
parent | 0ee29e31ddcc81f541de7459b0a5e40dfa552672 (diff) | |
download | bagage-514731cf4b5dd97dc871b9fd84c4d9938900ef79.tar.gz bagage-514731cf4b5dd97dc871b9fd84c4d9938900ef79.zip |
WIP DEBUG
Diffstat (limited to 's3')
-rw-r--r-- | s3/file.go | 53 | ||||
-rw-r--r-- | s3/stat.go | 2 |
2 files changed, 36 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) { @@ -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 } |