Skip to content

Commit b40d6ac

Browse files
authored
Merge pull request #9 from knights-analytics/fix-delete
Fix leading slashes in keys
2 parents ce2238c + 569eb2f commit b40d6ac

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

s3/delete.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ import (
1111

1212
// Delete removes an resource
1313
func (s *Storager) Delete(ctx context.Context, location string, options ...storage.Option) error {
14+
15+
// In SDK v2, DeleteObject does not handle leading slashes, so remove them here
16+
deleteLocation := location
17+
if len(deleteLocation) > 0 && deleteLocation[0] == '/' {
18+
deleteLocation = deleteLocation[1:]
19+
}
1420
_, err := s.Client.DeleteObject(ctx, &s3.DeleteObjectInput{
1521
Bucket: &s.bucket,
16-
Key: &location,
22+
Key: &deleteLocation,
1723
})
1824
if isNotFound(err) {
1925
objectKind := &option.ObjectKind{}

s3/open.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ import (
1919

2020
// Open return content reader and hash values if md5 or crc option is supplied or error
2121
func (s *Storager) Open(ctx context.Context, location string, options ...storage.Option) (io.ReadCloser, error) {
22+
23+
// In SDK v2, multiple functions do not handle leading slashes, so remove them here
24+
parsedLocation := location
25+
if len(parsedLocation) > 0 && parsedLocation[0] == '/' {
26+
parsedLocation = parsedLocation[1:]
27+
}
28+
2229
started := time.Now()
2330
defer func() {
2431
s.logF("s3:Open %v %s\n", location, time.Since(started))
@@ -30,7 +37,7 @@ func (s *Storager) Open(ctx context.Context, location string, options ...storage
3037
option.Assign(options, &key, &stream)
3138
input := &s3.GetObjectInput{
3239
Bucket: &s.bucket,
33-
Key: &location,
40+
Key: &parsedLocation,
3441
}
3542

3643
if len(key.Key) > 0 {

0 commit comments

Comments
 (0)