Skip to content

Commit

Permalink
Merge pull request #9 from knights-analytics/fix-delete
Browse files Browse the repository at this point in the history
Fix leading slashes in keys
  • Loading branch information
adranwit authored Oct 29, 2024
2 parents ce2238c + 569eb2f commit b40d6ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion s3/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ import (

// Delete removes an resource
func (s *Storager) Delete(ctx context.Context, location string, options ...storage.Option) error {

// In SDK v2, DeleteObject does not handle leading slashes, so remove them here
deleteLocation := location
if len(deleteLocation) > 0 && deleteLocation[0] == '/' {
deleteLocation = deleteLocation[1:]
}
_, err := s.Client.DeleteObject(ctx, &s3.DeleteObjectInput{
Bucket: &s.bucket,
Key: &location,
Key: &deleteLocation,
})
if isNotFound(err) {
objectKind := &option.ObjectKind{}
Expand Down
9 changes: 8 additions & 1 deletion s3/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import (

// Open return content reader and hash values if md5 or crc option is supplied or error
func (s *Storager) Open(ctx context.Context, location string, options ...storage.Option) (io.ReadCloser, error) {

// In SDK v2, multiple functions do not handle leading slashes, so remove them here
parsedLocation := location
if len(parsedLocation) > 0 && parsedLocation[0] == '/' {
parsedLocation = parsedLocation[1:]
}

started := time.Now()
defer func() {
s.logF("s3:Open %v %s\n", location, time.Since(started))
Expand All @@ -30,7 +37,7 @@ func (s *Storager) Open(ctx context.Context, location string, options ...storage
option.Assign(options, &key, &stream)
input := &s3.GetObjectInput{
Bucket: &s.bucket,
Key: &location,
Key: &parsedLocation,
}

if len(key.Key) > 0 {
Expand Down

0 comments on commit b40d6ac

Please sign in to comment.