-
Notifications
You must be signed in to change notification settings - Fork 453
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:add if_none_match for write #5129
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: LeeHao <HaozzaLi@gmail.com>
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.
It mostly looks good to me. To make this feature work, we should also add a flag in Capability
called write_with_if_none_match
. Additionally, we can add a behavior test based on this.
/// | ||
/// This feature can be used to check if the file already exists. | ||
/// This prevents overwriting of existing objects with identical key names. | ||
/// And must use the * (asterisk) value with this parameter |
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.
S3 only supports *
, but other services may support different options. We can revise the statement to say users can use *
to verify if a file already exists by matching with any ETag.
/// use opendal::Operator; | ||
/// # async fn test(op: Operator, etag: &str) -> Result<()> { | ||
/// let bs = b"hello, world!".to_vec(); | ||
/// let mut metadata = op.write_with("path/to/file", bs).if_none_match("*").await?; |
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.
write
didn't return metadata
for now.
/// This prevents overwriting of existing objects with identical key names. | ||
/// And must use the * (asterisk) value with this parameter | ||
/// | ||
/// If file exists, an error with kind [`ErrorKind::ConditionNotMatch`] will be returned. |
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.
Perhaps we can also provide an example to demonstrate how to handle this error.
Which issue does this PR close?
Closes #5097
Rationale for this change
What changes are included in this PR?
Are there any user-facing changes?
Yes, add an option
if_none_match
forwrite_with
.