chitralverma opened a new issue, #8965:
URL: https://github.com/apache/opendal/issues/8965
### OpenDAL version or commit
`main` at 37b4cf956 (also reproduced at d3a9351 and d21fd39). GlobLayer
landed in #7629.
### Affected service or component
core: `GlobLayer` (`list_with(..).glob(..)`), observed with services-fs.
### Describe the bug
If a directory under the listed path cannot be read,
`list_with(..).glob(..)` fails the whole listing with `PermissionDenied`, even
when the pattern also matches readable directories. A recursive listing of the
same tree skips that directory and returns everything else: the fs lister and
`SimulateLayer`'s flat lister both skip `PermissionDenied` on directories they
discover, with a warning.
The guided glob walk lists each discovered directory itself, so it does not
get that behavior, and a single unreadable subdirectory, for example one owned
by another user, makes every spanning pattern under it unusable.
### Steps to Reproduce
Unix, run as a non-root user:
```toml
[dependencies]
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
opendal = { git = "https://github.com/apache/opendal", default-features =
false, features = ["executors-tokio", "services-fs"] }
```
```rust
use std::os::unix::fs::PermissionsExt;
use opendal::*;
#[tokio::main]
async fn main() -> std::io::Result<()> {
opendal::init_default_registry();
let dir = std::env::temp_dir().join(format!("glob-perm-{}",
std::process::id()));
std::fs::create_dir_all(dir.join("data/ok"))?;
std::fs::create_dir_all(dir.join("data/private"))?;
std::fs::write(dir.join("data/ok/a.parquet"), "x")?;
std::fs::write(dir.join("data/private/b.parquet"), "x")?;
std::fs::set_permissions(dir.join("data/private"),
std::fs::Permissions::from_mode(0o000))?;
let op = Operator::via_iter("fs", [("root".to_string(),
dir.display().to_string())]).unwrap();
let names = |r: Result<Vec<Entry>>| r.map(|v| v.iter().map(|e|
e.path().to_string()).collect::<Vec<_>>());
println!("recursive: {:?}",
names(op.list_with("data/").recursive(true).await));
println!("glob **: {:?}",
names(op.list_with("").glob("data/**/*.parquet").await).map_err(|e| e.kind()));
println!("glob */*: {:?}",
names(op.list_with("").glob("data/*/*.parquet").await).map_err(|e| e.kind()));
std::fs::set_permissions(dir.join("data/private"),
std::fs::Permissions::from_mode(0o755))?;
std::fs::remove_dir_all(&dir)
}
```
### Actual Behavior
```text
recursive: Ok(["data/ok/a.parquet", "data/ok/", "data/"])
glob **: Err(PermissionDenied)
glob */*: Err(PermissionDenied)
```
The error context points at the discovered directory: `service: fs, path:
data/private/`.
### Expected Behavior
```text
recursive: Ok(["data/ok/a.parquet", "data/ok/", "data/"])
glob **: Ok(["data/ok/a.parquet"])
glob */*: Ok(["data/ok/a.parquet"])
```
Glob should skip unreadable directories it discovers while walking,
consistent with recursive listing. Listing a directory the caller named
directly (for example `list_with("data/private/").glob("*.parquet")`) should
still return `PermissionDenied`, again matching recursive listing.
### Additional Context
The fix is small: remember whether a `Directory` in the guided walk was
discovered or was the starting directory, and treat `PermissionDenied` on a
discovered one like the existing `NotFound`/`NotADirectory` arms, with a
`log::warn!` like the fs lister. PR to follow.
### 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]