-
Notifications
You must be signed in to change notification settings - Fork 102
Conversation
@@ -279,8 +279,10 @@ func newS3Storage(backend *backup.S3, opts *ExternalStorageOptions) (*S3Storage, | |||
return nil, errors.Annotatef(berrors.ErrStorageInvalidConfig, "Bucket %s is not accessible: %v", qs.Bucket, err) | |||
} | |||
} | |||
if len(qs.Prefix) > 0 { | |||
qs.Prefix += "/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there is a '/' already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we just path.Clean
it 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Prefix
is parsed from url it can't contains the "/" suffix. See:
Lines 69 to 70 in 578be7f
prefix := strings.Trim(u.Path, "/") | |
s3 := &backup.S3{Bucket: u.Host, Prefix: prefix} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just not want the bare "/" prefix. for other non-empty prefixes, the suffix "/" is needed.
BTW, maybe we shouldn't depend on the Prefix
filed to contain the "/" suffix, but in this way, we need to change more code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the user wants to load all data from one bucket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original pr is try to resolve this issue then. If the input path is the bucket name, we should leave the prefix parameter empty in the ListObject
request, otherwise, s3 will return empty result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(prefix) > 0 && !strings.HasSuffix(prefix, "/") {
What about checking suffix too? In case the API is called from other projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/storage/s3.go
Outdated
if len(prefix) > 0 && !strings.HasSuffix(prefix, "/") { | ||
prefix += "/" | ||
} | ||
prefix := rs.options.Prefix + opt.SubDir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about path.Join
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.Join cannot work on windows since it separator is not "/". And options.Prefix
already contains the suffix "/"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glorv path.Join
always use /
. you're thinking of filepath.Join
😛
😥 |
/run-integration-test |
#690 fix this test, we can merge it first |
pkg/storage/s3_test.go
Outdated
@@ -881,6 +881,31 @@ func (s *s3Suite) TestWalkDir(c *C) { | |||
}, nil | |||
}). | |||
After(secondCall) | |||
forthCall := s.s3.EXPECT(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo?
forthCall := s.s3.EXPECT(). | |
fourthCall := s.s3.EXPECT(). |
pkg/storage/s3_test.go
Outdated
Contents: contents[4:], | ||
}, nil | ||
}). | ||
After(forthCall) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After(forthCall) | |
After(fourthCall) |
@@ -279,8 +279,10 @@ func newS3Storage(backend *backup.S3, opts *ExternalStorageOptions) (*S3Storage, | |||
return nil, errors.Annotatef(berrors.ErrStorageInvalidConfig, "Bucket %s is not accessible: %v", qs.Bucket, err) | |||
} | |||
} | |||
if len(qs.Prefix) > 0 { | |||
qs.Prefix += "/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the user wants to load all data from one bucket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
@@ -279,8 +279,10 @@ func newS3Storage(backend *backup.S3, opts *ExternalStorageOptions) (*S3Storage, | |||
return nil, errors.Annotatef(berrors.ErrStorageInvalidConfig, "Bucket %s is not accessible: %v", qs.Bucket, err) | |||
} | |||
} | |||
if len(qs.Prefix) > 0 { | |||
qs.Prefix += "/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(prefix) > 0 && !strings.HasSuffix(prefix, "/") {
What about checking suffix too? In case the API is called from other projects.
LGTM |
/merge |
/run-all-tests |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-4.0 in PR #756 |
Signed-off-by: ti-srebot <[email protected]>
What problem does this PR solve?
close #749
What is changed and how it works?
#713 tried to fix the s3 WalkDir prefix issue in the wrong way and introduced another bug.
The original issue is that if prefix and subDir are both empty, the prefix parameter in the
ListObject
request then is "/", which causes s3 to return empty results.The PR avoids adding the "/" postfix for the s3Storage object if the original prefix is an empty string.
Check List
Tests
Code changes
Side effects
Related changes
Release Note