From 78ccf306035740ed3dc536f35d74921340d883f7 Mon Sep 17 00:00:00 2001 From: Anthony Riley Date: Mon, 27 Feb 2023 21:25:23 -0800 Subject: [PATCH 1/3] Fixed issue with retrieving collection contents --- collections/collections.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/collections/collections.go b/collections/collections.go index 0d128964..eb77c0cf 100644 --- a/collections/collections.go +++ b/collections/collections.go @@ -155,12 +155,13 @@ func GetDirectoryContents(refs []util.ContentWithPath, queryDir, coluuid string) if directoryContent != nil { // if there was content if directoryContent.Type == CidTypeDir { // if the content was a directory - subDir := directoryContent.Dir + subDir := filepath.Join(directoryContent.Dir, directoryContent.Name) if dirs[subDir] { // if the directory had already been added to response, continue continue } dirs[subDir] = true } + result = append(result, directoryContent) } } From 8fe97b56b54bf5ba9b41097259b5df7596cadb23 Mon Sep 17 00:00:00 2001 From: alvin-reyes Date: Thu, 30 Mar 2023 14:24:42 -0400 Subject: [PATCH 2/3] fixed (gosec): defer the entire error function --- api/v1/handlers.go | 6 +++++- cmd/estuary-shuttle/main.go | 6 +++++- util/misc.go | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/api/v1/handlers.go b/api/v1/handlers.go index 5e1d43b4..bd3cea81 100644 --- a/api/v1/handlers.go +++ b/api/v1/handlers.go @@ -415,7 +415,11 @@ func (s *apiV1) handleAddCar(c echo.Context, u *util.User) error { }() }() - defer c.Request().Body.Close() + defer func() { + if err := c.Request().Body.Close(); err != nil { + s.log.Warnf("failed to close request body: %s", err) + } + }() header, err := s.loadCar(ctx, sbs, c.Request().Body) if err != nil { return err diff --git a/cmd/estuary-shuttle/main.go b/cmd/estuary-shuttle/main.go index 7fe04890..be2ed8c9 100644 --- a/cmd/estuary-shuttle/main.go +++ b/cmd/estuary-shuttle/main.go @@ -1439,7 +1439,11 @@ func (s *Shuttle) handleAddCarToShuttle(c echo.Context, u *User) error { }() }() - defer c.Request().Body.Close() + defer func() { + if err := c.Request().Body.Close(); err != nil { + log.Warnf("failed to close request body: %s", err) + } + }() header, err := s.loadCar(ctx, bs, c.Request().Body) if err != nil { return err diff --git a/util/misc.go b/util/misc.go index d54b80ed..a1ef37ec 100644 --- a/util/misc.go +++ b/util/misc.go @@ -99,7 +99,11 @@ func WithContentLengthCheck(f func(echo.Context) error) func(echo.Context) error type Binder struct{} func (b Binder) Bind(i interface{}, c echo.Context) error { - defer c.Request().Body.Close() + defer func() { + if err := c.Request().Body.Close(); err != nil { + log.Warnf("failed to close request body: %s", err) + } + }() if err := json.NewDecoder(c.Request().Body).Decode(i); err != nil { return &HttpError{ Code: http.StatusBadRequest, From 027325511a7dae24f96778ba237d94140a9e0dbd Mon Sep 17 00:00:00 2001 From: alvin-reyes Date: Thu, 30 Mar 2023 14:32:27 -0400 Subject: [PATCH 3/3] fixed (gosec): defer the entire error function --- util/misc.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/util/misc.go b/util/misc.go index 2e90e418..e1af71b1 100644 --- a/util/misc.go +++ b/util/misc.go @@ -106,14 +106,6 @@ func NewBinder(log *zap.SugaredLogger) binder { } func (b binder) Bind(i interface{}, c echo.Context) error { - defer func() { - if err := c.Request().Body.Close(); err != nil { - b.log.Warnf("failed to close request body: %s", err) - } - }() - - -func (b Binder) Bind(i interface{}, c echo.Context) error { defer func() { if err := c.Request().Body.Close(); err != nil { log.Warnf("failed to close request body: %s", err)