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:add if_none_match for write #5129

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ForestLH
Copy link

@ForestLH ForestLH commented Sep 19, 2024

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 optionif_none_match for write_with.

Signed-off-by: LeeHao <HaozzaLi@gmail.com>
Copy link
Member

@Xuanwo Xuanwo left a 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
Copy link
Member

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?;
Copy link
Member

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.
Copy link
Member

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.

core/src/types/operator/operator.rs Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

new feature: Add docs about conditional write for s3
2 participants