objectstorage: return object last modified time

This commit is contained in:
Simone Gotti 2019-04-15 09:37:34 +02:00
parent 9c2ac68a75
commit 57161477ca
3 changed files with 11 additions and 6 deletions

View File

@ -17,6 +17,7 @@ package objectstorage
import ( import (
"errors" "errors"
"io" "io"
"time"
) )
// TODO(sgotti) // TODO(sgotti)
@ -36,6 +37,8 @@ type Storage interface {
type ObjectInfo struct { type ObjectInfo struct {
Path string Path string
LastModified time.Time
Err error Err error
} }

View File

@ -240,14 +240,15 @@ func (s *PosixStorage) Stat(p string) (*ObjectInfo, error) {
return nil, err return nil, err
} }
if _, err := os.Stat(fspath); err != nil { fi, err := os.Stat(fspath)
if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil, ErrNotExist return nil, ErrNotExist
} }
return nil, err return nil, err
} }
return &ObjectInfo{Path: p}, nil return &ObjectInfo{Path: p, LastModified: fi.ModTime()}, nil
} }
func (s *PosixStorage) ReadObject(p string) (io.ReadCloser, error) { func (s *PosixStorage) ReadObject(p string) (io.ReadCloser, error) {
@ -409,7 +410,7 @@ func (s *PosixStorage) List(prefix, startWith, delimiter string, doneCh <-chan s
if p > prevp { if p > prevp {
select { select {
// Send object content. // Send object content.
case objectCh <- ObjectInfo{Path: p}: case objectCh <- ObjectInfo{Path: p, LastModified: info.ModTime()}:
// If receives done from the caller, return here. // If receives done from the caller, return here.
case <-doneCh: case <-doneCh:
return io.EOF return io.EOF

View File

@ -61,7 +61,8 @@ func NewS3Storage(bucket, location, endpoint, accessKeyID, secretAccessKey strin
} }
func (s *S3Storage) Stat(p string) (*ObjectInfo, error) { func (s *S3Storage) Stat(p string) (*ObjectInfo, error) {
if _, err := s.minioClient.StatObject(s.bucket, p, minio.StatObjectOptions{}); err != nil { oi, err := s.minioClient.StatObject(s.bucket, p, minio.StatObjectOptions{})
if err != nil {
merr := minio.ToErrorResponse(err) merr := minio.ToErrorResponse(err)
if merr.StatusCode == http.StatusNotFound { if merr.StatusCode == http.StatusNotFound {
return nil, ErrNotExist return nil, ErrNotExist
@ -69,7 +70,7 @@ func (s *S3Storage) Stat(p string) (*ObjectInfo, error) {
return nil, merr return nil, merr
} }
return &ObjectInfo{Path: p}, nil return &ObjectInfo{Path: p, LastModified: oi.LastModified}, nil
} }
func (s *S3Storage) ReadObject(filepath string) (io.ReadCloser, error) { func (s *S3Storage) ReadObject(filepath string) (io.ReadCloser, error) {
@ -144,7 +145,7 @@ func (s *S3Storage) List(prefix, startWith, delimiter string, doneCh <-chan stru
for _, object := range result.Contents { for _, object := range result.Contents {
select { select {
// Send object content. // Send object content.
case objectCh <- ObjectInfo{Path: object.Key}: case objectCh <- ObjectInfo{Path: object.Key, LastModified: object.LastModified}:
// If receives done from the caller, return here. // If receives done from the caller, return here.
case <-doneCh: case <-doneCh:
return return