Mola-maker opened a new issue, #9031:
URL: https://github.com/apache/opendal/issues/9031
### OpenDAL version or commit
main (57f8b75), which includes #8984
### Affected service or component
services/fs on Windows
### Describe the bug
#8984 added `test_directory_errors_are_permanent` to
`core/services/fs/src/core.rs` to pin the `IsADirectory` / `NotADirectory`
error kinds for rename, copy and write. The test fails on Windows, because
Windows reports these conditions with different OS errors, and the fs service
passes them through `new_std_io_error` unchanged:
| operation | Linux (asserted by the test) | Windows (observed) | Windows OS
error |
|---|---|---|---|
| `rename("src", "existing_dir")` | `IsADirectory` | `PermissionDenied` | 5
`ERROR_ACCESS_DENIED` |
| `rename("file/child", "dst")` | `NotADirectory` | `NotFound` | 3
`ERROR_PATH_NOT_FOUND` |
| `rename("src", "file/dir/dst")` | `NotADirectory` | `AlreadyExists` | 183
`ERROR_ALREADY_EXISTS` |
| `copy("src", "existing_dir")` | `IsADirectory` | `IsADirectory` |
(pre-checked by the service) |
| `copy("src", "file/dir/dst")` | `NotADirectory` | `AlreadyExists` | 183
`ERROR_ALREADY_EXISTS` |
| `write("existing_dir", ..)` | `IsADirectory` | `PermissionDenied` | 5
`ERROR_ACCESS_DENIED` |
All errors are permanent and no data is lost; only the error kind differs.
Callers that branch on the error kind get different behavior per platform. For
example, `PermissionDenied` for writing over a directory is misleading, and
`AlreadyExists` for a parent path that is a file reads like a conflict on the
target itself.
CI does not catch this: the `unit` job in `.github/workflows/ci_core.yml`
runs on `ubuntu-latest` only, and the Windows job only runs `cargo build`.
### Steps to Reproduce
On Windows 11 (NTFS), rustc 1.99.1:
```
cd core
cargo test -p opendal-service-fs --lib
core::tests::test_directory_errors_are_permanent
```
```
thread 'core::tests::test_directory_errors_are_permanent' panicked at
services\fs\src\core.rs:922:9:
assertion `left == right` failed: PermissionDenied (permanent) at rename =>
permission denied
Context:
service_operation: Rename
service: fs
from: src
to: existing_dir
Source:
拒绝访问。 (os error 5) <- zh-CN locale; "Access is denied."
left: PermissionDenied
right: IsADirectory
```
The test stops at the first assertion. The table above comes from running
every case on its own:
```rust
use opendal::{Operator, services::Fs};
#[tokio::main]
async fn main() {
let root = std::env::temp_dir().join("opendal-direrr-repro");
let _ = std::fs::remove_dir_all(&root);
std::fs::create_dir_all(&root).unwrap();
std::fs::write(root.join("src"), b"data").unwrap();
std::fs::write(root.join("file"), b"data").unwrap();
std::fs::create_dir(root.join("existing_dir")).unwrap();
let op =
Operator::new(Fs::default().root(root.to_str().unwrap())).unwrap();
let show = |name: &str, r: opendal::Result<()>| match r {
Ok(()) => println!("{name:30} => Ok"),
Err(e) => println!("{name:30} => {:?} source={:?}", e.kind(),
std::error::Error::source(&e).map(|s| s.to_string())),
};
show("rename src -> existing_dir", op.rename("src",
"existing_dir").await);
show("rename file/child -> dst", op.rename("file/child", "dst").await);
show("rename src -> file/dir/dst", op.rename("src",
"file/dir/dst").await);
show("copy src -> existing_dir", op.copy("src",
"existing_dir").await.map(|_| ()));
show("copy src -> file/dir/dst", op.copy("src",
"file/dir/dst").await.map(|_| ()));
show("write existing_dir", op.write("existing_dir", "x").await.map(|_|
()));
}
```
### Actual Behavior
See the Windows column above.
### Expected Behavior
The same error kinds as on Linux and macOS: `IsADirectory` when the target
is an existing directory, and `NotADirectory` when a parent component of the
path is a file.
### Additional Context
- The only case that already works on Windows is `copy` onto a directory,
because `fs_copy` stats the target before copying. The other paths rely on the
OS error mapping.
- `ERROR_ACCESS_DENIED` and `ERROR_ALREADY_EXISTS` are ambiguous on Windows,
so the error code alone cannot be mapped. The fs service would have to check
the target or its parent only when one of these errors occurs, as `fs_copy`
already does up front.
- Adding `windows-latest` to the `unit` job, or a Windows run limited to `-p
opendal-service-fs`, would keep this from regressing.
### Reproduction confirmation
- [x] I reproduced this issue against the affected component. For a
service-specific report, I used the actual service rather than only a mock,
emulator, or source-code analysis.
### Are you willing to submit a PR to fix this bug?
- [x] Yes, I would like to submit a PR.
--
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]