Mola-maker opened a new issue, #9041:
URL: https://github.com/apache/opendal/issues/9041
### OpenDAL version or commit
main (57f8b75)
### Affected service or component
services/fs: `FsConfig::from_uri` (`core/services/fs/src/config.rs`)
### Describe the bug
`FsConfig::from_uri` builds the root by adding `/` in front of the URI path
and ignores the URI host. That causes two problems:
1. **Windows drive URIs fail.** The standard Windows file URI
`file:///C:/data` (and `fs:///C:/data`) gives the root `/C:/data`, which is not
a valid Windows path, so building the operator fails.
2. **A host is dropped silently, and the data goes to a different
directory.** `fs://tmp/data` uses `/data`. On Windows, `fs://C:/Users/me/data`
uses `\Users\me\data` on the *current* drive. When I ran it from E:, the
operator created and wrote to `E:\Users\me\data`. Neither case reports an error.
### Steps to Reproduce
Windows 11, main 57f8b75:
```rust
for uri in [
"file:///C:/Users/me/AppData/Local/Temp/opendal-uri",
"fs:///C:/Users/me/AppData/Local/Temp/opendal-uri",
"fs://C:/Users/me/AppData/Local/Temp/opendal-uri",
"fs://tmp/opendal-uri-rel",
] {
let op = Operator::from_uri(uri)?; // then op.write("probe.txt", "x")
}
```
```
file:///C:/Users/me/AppData/Local/Temp/opendal-uri
from_uri Err(Unexpected) => canonicalize of root directory failed,
source: (os error 123)
fs:///C:/Users/me/AppData/Local/Temp/opendal-uri
from_uri Err(Unexpected) => canonicalize of root directory failed,
source: (os error 123)
fs://C:/Users/me/AppData/Local/Temp/opendal-uri
root="\?\E:\Users\me\AppData\Local\Temp\opendal-uri" write=Ok(())
fs://tmp/opendal-uri-rel
root="\?\E:\opendal-uri-rel" write=Ok(())
```
### Actual Behavior
Drive-letter file URIs cannot be used on Windows. URIs with a host succeed,
but they read and write in a directory the user never named.
### Expected Behavior
- `file:///C:/data` uses the root `C:/data` on Windows. `file:///C:/` uses
`C:/`, not the drive-relative `C:`.
- A host other than `localhost` is rejected with `ConfigInvalid` instead of
being ignored. `file://localhost/tmp/data` keeps working.
### Additional Context
Rejecting the host changes behavior for anyone who currently relies on
`fs://name/path` meaning `/path`. Mapping UNC URIs (`file://server/share`) to
`\server\share` could be added later as a feature. `compfs` and `monoiofs`
parse URIs in a similar way and may need the same check.
### 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]