-
Notifications
You must be signed in to change notification settings - Fork 703
fix(service/fs): handle if_not_exists flag to raise ConditionNotMatch error #6326
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
Conversation
|
This should have been catched at opendal/core/src/services/fs/core.rs Lines 146 to 152 in 577912d
Maybe there are other issues? |
|
@Xuanwo At first, I also thought this part was functional, but there's an extra opendal/core/src/services/fs/core.rs Line 162 in 577912d
|
I see. So the real fix should use the correct open options to open the target path. In this way, we can avoid an extra syscall. |
18a763d to
f952ef4
Compare
Change to check if |
Wow, you're so clever! Could you add some comments to explain it a bit? I spent some time to understand how it works. |
|
In the code, the The core of this change is to check whether In short: |
core/src/services/fs/core.rs
Outdated
| .ensure_write_abs_path(atomic_write_dir, &build_tmp_path_of(path)) | ||
| .await?; | ||
| let path = if op.if_not_exists() { | ||
| target_path.to_string_lossy().to_string() |
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.
Hi, this could be logically incorrect since atomic_write_dir is meant to ensure our write operation is atomic. Even if the target path is empty, we still need to write to the temporary path first.
I think that in the case of atomic_write_dir, it's unavoidable to call try_exists first. The logic here is somewhat complex, so perhaps we should consider a major refactor.
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.
cc @kingsword09, after giving it some thought, I realize the current behavior isn't what I expected.
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.
You're right, it might really need to be refactored here to make more sense.
|
After merging #6327, simply adjusting the before: opendal/core/src/services/fs/core.rs Lines 127 to 130 in 8f277e9
after: let should_append = (op.append() || op.if_not_exists())
&& tokio::fs::try_exists(&target_path)
.await
.map_err(new_std_io_error)?; |
5f006ed to
2fae348
Compare
2fae348 to
13eafd8
Compare
Signed-off-by: Xuanwo <[email protected]>
|
Hi, @kingsword09 I did the refactor on your PR directly. Let's see how it works. |
Xuanwo
left a comment
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.
Thank you @kingsword09 for inspiring me about this work.
Let me take a look. |

Which issue does this PR close?
Closes #.
Rationale for this change
While implementing the
WriteOptions#6322 in Node.js, I found that theif_not_existsproperty test fails without throwing theConditionNotMatchexception.What changes are included in this PR?
When
if_not_existsis true, if the file already exists, aConditionNotMatchexception should be thrown.opendal/core/tests/behavior/async_write.rs
Lines 773 to 778 in 23f01dd
Are there any user-facing changes?