Mola-maker opened a new pull request, #9032:
URL: https://github.com/apache/opendal/pull/9032
# Which issue does this PR close?
Closes #9031.
# Rationale for this change
On Windows, the fs service reports a directory target as
`ERROR_ACCESS_DENIED`, and a regular file in a parent component as
`ERROR_PATH_NOT_FOUND` or `ERROR_ALREADY_EXISTS`. These errors pass through
`new_std_io_error` unchanged. As a result, rename, copy and write return
`PermissionDenied`, `NotFound` or `AlreadyExists` where Unix returns
`IsADirectory` or `NotADirectory`. `test_directory_errors_are_permanent` from
#8984 fails on Windows for this reason. CI does not catch it, because the
`unit` job runs only on Ubuntu.
# What changes are included in this PR?
- `refine_path_error` in `core/services/fs/src/core.rs` runs only on Windows
and only after a failure. If the error is `PermissionDenied` and the path is a
directory, it reports `IsADirectory`. If the error is `NotFound` or
`AlreadyExists` and the nearest existing ancestor is not a directory, it
reports `NotADirectory`. The original OS error is kept as the source. On other
platforms the function returns the error unchanged.
- The helper is applied to the parent `create_dir_all`, the source stat in
copy and rename, the rename itself, the writer's open and the staged commit
rename.
- On Unix, `O_CREAT | O_EXCL` on a directory fails with `EEXIST`. To match,
an `if_not_exists` write onto a directory now reports `ConditionNotMatch` on
Windows, the same as on Unix.
- `#[cfg(unix)]` is removed from the kind assertions in
`test_staged_write_cleans_up_on_is_a_directory` and
`test_staged_write_cleans_up_on_not_a_directory`, so these assertions now also
run on Windows. `test_directory_errors_are_permanent` gains an `if_not_exists`
case.
Verified on Windows 11 (NTFS), rustc 1.99.1:
- `cargo test -p opendal-service-fs --lib`: 17 passed. Before this change,
`test_directory_errors_are_permanent` failed. The new `if_not_exists` assertion
also fails without the writer change.
- `OPENDAL_TEST=fs cargo test --test behavior --features tests,services-fs`:
138 passed.
- `cargo clippy -p opendal-service-fs --all-targets -- -D warnings`: clean
for the Windows host and for `--target x86_64-unknown-linux-gnu`. I did not run
the Linux tests locally.
Not covered here: `create_dir("file/x/")` still returns `AlreadyExists` on
Windows. Separately, the conditional staged publish (`hard_link`) returns os
error 87 as a temporary `Unexpected` when the parent has been replaced by a
file. That problem existed before this change.
# Are there any user-facing changes?
On Windows only, the fs service now returns the same error kinds as Unix for
these cases.
# Breaking changes
# AI Usage Statement
- Harness: Claude Code
- Model: Anthropic Claude
- Effort: default
- Role: Found the failing test by running the fs unit and behavior tests on
Windows, wrote the fix and the test changes, and ran the checks above. A
separate review pass found the `if_not_exists` case, which is now fixed.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]