bytecodealliance / bytecodealliance/cap-std
get entries of a windows unc path failed when call `cap_std::fs::Dir::from_std_file(dir).entries()`
- Langage dominant
- Rust
- Étoiles
- 821
- Forks
- 57
- Merge moyen
- 1 h 16 min
- PR mergées (30 j)
- 4
Description
## test code
```rust
let path = std::path::Path::new("C:\\Users\\path\\to\\folder"); //works fine
let path = std::path::Path::new("\\\\?\\UNC\\Mac\\path\\to\\folder"); //throw an error
let dir = std::fs::OpenOptions::new()
.read(true)
.custom_flags(33554432u32)
.open(path).unwrap();
let entries = cap_std::fs::Dir::from_std_file(dir).entries();
dbg!(entries);
```
## reason
After debugged, I found cap_primitives/src/windows/fs [get_path](https://github.com/bytecodealliance/cap-std/blob/79ae7ce65e2f45f7a1156737995b293ed99ced15/cap-primitives/src/windows/fs/get_path.rs#L19) cause this problem.
```rust
let wide_final = if wide.starts_with(&['\\' as u16, '\\' as _, '?' as _, '\\' as _]) {
&wide[4..] //throw error
//&wide //change to this and it works
} else {
&wide
};
```
when path start with `\\\\?\\`, `\\\\?\\` will be remove, and `\\\\?\\UNC\\Mac\\path\\to\\folder` changed to `UNC\\Mac\\path\\to\\folder`, so a `path not found` error be throwed.
## dependency chain
the dependency chain is:
- `cap_std::fs::dir::Dir::entries`
- `cap_primitives::fs::read_dir::read_base_dir`
- `cap_primitives::windows::fs::read_dir_inner::ReadDirInner::read_base_dir`
- `cap_primitives::windows::fs::read_dir_inner::ReadDirInner::new_unchecked`
- `cap_primitives::windows::fs::get_path::concatenate`
- `cap_primitives::windows::fs::get_path::get_path`
## cargo.toml
```toml
cap-std = "1.0.14"
```
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez dans cap-primitives/src/windows/fs/get_path.rs au niveau de get_path et suivez la chaîne de read_dir jusqu’à concatenate. Reproduisez le cas de chemin UNC signalé sous Windows, puis ajoutez une couverture de régression pour Dir::from_std_file(dir).entries(). C’est terminé lorsque les chemins UNC commençant par \\?\UNC\ sont résolus correctement sans casser les chemins Windows ordinaires.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- rust
- Domaine
- operating-systems
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 48/100