Skip to content

Commit

Permalink
add prefix not found for prefix move
Browse files Browse the repository at this point in the history
  • Loading branch information
Akopti8 committed Jan 30, 2024
1 parent c987ad8 commit 36d1be2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions blobstore/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func (bh *BlobHandler) HandleMovePrefix(c echo.Context) error {
log.Error(errMsg.Error())
return c.JSON(http.StatusUnprocessableEntity, errMsg.Error())
}

err = s3Ctrl.CopyPrefix(bucket, srcPrefix, destPrefix)
if err != nil {
if strings.Contains(err.Error(), "does not exist") {
return c.JSON(http.StatusNotFound, err.Error())
if strings.Contains(err.Error(), "source prefix not found") {
log.Infof("No objects found with source prefix: %s", srcPrefix)
return c.JSON(http.StatusNotFound, "Source prefix not found")
}
return c.JSON(http.StatusInternalServerError, err.Error())
}
Expand All @@ -47,7 +47,14 @@ func (bh *BlobHandler) HandleMovePrefix(c echo.Context) error {
}

func (s3Ctrl *S3Controller) CopyPrefix(bucket, srcPrefix, destPrefix string) error {
var objectsFound bool

processPage := func(page *s3.ListObjectsV2Output) error {
if len(page.Contents) == 0 {
return nil
}
objectsFound = true // Objects found, set the flag

for _, object := range page.Contents {
srcObjectKey := aws.StringValue(object.Key)
destObjectKey := strings.Replace(srcObjectKey, srcPrefix, destPrefix, 1)
Expand All @@ -69,6 +76,10 @@ func (s3Ctrl *S3Controller) CopyPrefix(bucket, srcPrefix, destPrefix string) err
errMsg := fmt.Errorf("error deleting from source prefix %s: %v", srcPrefix, err)
return errMsg
}
if !objectsFound {
return fmt.Errorf("source prefix not found")
}

return nil
}

Expand Down

0 comments on commit 36d1be2

Please sign in to comment.