Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Return hinted error for S3 wildcard if-none-match #5506

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions core/src/layers/correctness_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ impl<A: Access> LayeredAccess for CorrectnessAccessor<A> {
"if_not_exists",
));
}
if args.if_none_match().is_some() && !capability.write_with_if_none_match {
return Err(new_unsupported_error(
self.info.as_ref(),
Operation::Write,
"if_none_match",
));
if let Some(if_none_match) = args.if_none_match() {
// AWS S3 supports only wildcard (every resource) matching
let is_s3_wildcard_match = self.info.scheme() == Scheme::S3 && if_none_match == "*";
if !is_s3_wildcard_match || !capability.write_with_if_none_match {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One alternative might be to generalize this to:

Suggested change
let is_s3_wildcard_match = self.info.scheme() == Scheme::S3 && if_none_match == "*";
if !is_s3_wildcard_match || !capability.write_with_if_none_match {
let if_none_match_wildcard =
if_none_match == "*" && !capability.write_with_if_not_exists;
if !if_none_match_wildcard || !capability.write_with_if_none_match {

But then this would need to be reflected in all potential clients as well.

return Err(new_unsupported_error(
self.info.as_ref(),
Operation::Write,
"if_none_match",
));
}
}

self.inner.write(path, args).await
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/s3/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ impl S3Core {
req = req.header(IF_MATCH, if_match);
}

if args.if_not_exists() {
if args.if_not_exists() || args.if_none_match() == Some("*") {
req = req.header(IF_NONE_MATCH, "*");
}

Expand Down
Loading