Skip to content

Commit

Permalink
Request name for GCS
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
  • Loading branch information
fpetkovski committed Oct 30, 2024
1 parent 3b23d35 commit 94d26ca
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
11 changes: 1 addition & 10 deletions objstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,7 @@ type ObjectAttributes struct {

type IterObjectAttributes struct {
Name string
lastModified time.Time
}

func (i *IterObjectAttributes) SetLastModified(t time.Time) {
i.lastModified = t
}

// LastModified returns the timestamp the object was last modified. Returns false if the timestamp is not available.
func (i *IterObjectAttributes) LastModified() (time.Time, bool) {
return i.lastModified, !i.lastModified.IsZero()
LastModified time.Time
}

// TryToGetSize tries to get upfront size from reader.
Expand Down
4 changes: 2 additions & 2 deletions providers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (b *Bucket) IterWithAttributes(ctx context.Context, dir string, f func(attr
Name: *blob.Name,
}
if params.LastModified {
attrs.SetLastModified(*blob.Properties.LastModified)
attrs.LastModified = *blob.Properties.LastModified
}
if err := f(attrs); err != nil {
return err
Expand All @@ -243,7 +243,7 @@ func (b *Bucket) IterWithAttributes(ctx context.Context, dir string, f func(attr
Name: *blobItem.Name,
}
if params.LastModified {
attrs.SetLastModified(*blobItem.Properties.LastModified)
attrs.LastModified = *blobItem.Properties.LastModified
}
if err := f(attrs); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion providers/bos/bos.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (b *Bucket) IterWithAttributes(ctx context.Context, dir string, f func(attr
if err != nil {
return fmt.Errorf("iter: get last modified: %w", err)
}
attrs.SetLastModified(lastModified)
attrs.LastModified = lastModified
}

if err := f(attrs); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion providers/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (b *Bucket) IterWithAttributes(ctx context.Context, dir string, f func(attr
if err != nil {
return errors.Wrapf(err, "stat %s", name)
}
attrs.SetLastModified(stat.ModTime())
attrs.LastModified = stat.ModTime()
}
if err := f(attrs); err != nil {
return err
Expand Down
21 changes: 16 additions & 5 deletions providers/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,21 @@ func (b *Bucket) IterWithAttributes(ctx context.Context, dir string, f func(attr
delimiter = ""
}

it := b.bkt.Objects(ctx, &storage.Query{
query := &storage.Query{
Prefix: dir,
Delimiter: delimiter,
})
}

if appliedOpts.LastModified {
if err := query.SetAttrSelection([]string{"Name", "Updated"}); err != nil {
return err
}
} else {
if err := query.SetAttrSelection([]string{"Name"}); err != nil {
return err
}
}
it := b.bkt.Objects(ctx, query)
for {
select {
case <-ctx.Done():
Expand All @@ -222,9 +233,9 @@ func (b *Bucket) IterWithAttributes(ctx context.Context, dir string, f func(attr
return err
}

objAttrs := objstore.IterObjectAttributes{Name: attrs.Prefix + attrs.Name}
if appliedOpts.LastModified {
objAttrs.SetLastModified(attrs.Updated)
objAttrs := objstore.IterObjectAttributes{
Name: attrs.Prefix + attrs.Name,
LastModified: attrs.Updated,
}
if err := f(objAttrs); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion providers/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func (b *Bucket) IterWithAttributes(ctx context.Context, dir string, f func(attr
Name: object.Key,
}
if appliedOpts.LastModified {
attr.SetLastModified(object.LastModified)
attr.LastModified = object.LastModified
}

if err := f(attr); err != nil {
Expand Down

0 comments on commit 94d26ca

Please sign in to comment.