From fd902a9c14f9ddad9929ac584b56373dbd196ade Mon Sep 17 00:00:00 2001 From: ozyurt19 Date: Thu, 11 Jul 2024 18:58:12 +0300 Subject: [PATCH] fix remove need for dummy storage object --- command/cat.go | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/command/cat.go b/command/cat.go index dbf2d352a..ccb1ef25b 100644 --- a/command/cat.go +++ b/command/cat.go @@ -125,35 +125,33 @@ func (c Cat) Run(ctx context.Context) error { printError(c.fullCommand, c.op, err) return err } - return c.processSingleObject(ctx, client, &storage.Object{URL: c.src}) + return c.processSingleObject(ctx, client, c.src) } func (c Cat) processObjects(ctx context.Context, client *storage.S3, objectChan <-chan *storage.Object) error { for obj := range objectChan { - if err := c.processSingleObject(ctx, client, obj); err != nil { + if obj.Err != nil { + printError(c.fullCommand, c.op, obj.Err) + return obj.Err + } + + if obj.Type.IsDir() { + continue + } + + err := c.processSingleObject(ctx, client, obj.URL) + if err != nil { + printError(c.fullCommand, c.op, err) return err } } return nil } -func (c Cat) processSingleObject(ctx context.Context, client *storage.S3, obj *storage.Object) error { - if obj.Err != nil { - printError(c.fullCommand, c.op, obj.Err) - return obj.Err - } - if obj.Type.IsDir() { - return nil - } +func (c Cat) processSingleObject(ctx context.Context, client *storage.S3, url *url.URL) error { buf := orderedwriter.New(os.Stdout) - - _, err := client.Get(ctx, obj.URL, buf, c.concurrency, c.partSize) - if err != nil { - printError(c.fullCommand, c.op, err) - return err - } - - return nil + _, err := client.Get(ctx, url, buf, c.concurrency, c.partSize) + return err } func validateCatCommand(c *cli.Context) error {