bytecodealliance / bytecodealliance/cap-std

get entries of a windows unc path failed when call `cap_std::fs::Dir::from_std_file(dir).entries()`

オープン
#318 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Rust
スター
821
フォーク
57
平均マージ
1時間 16分
マージ済み PR(30日)
4

説明

## 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"
```

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

cap-primitives/src/windows/fs/get_path.rs の get_path から開始し、read_dir チェーンを concatenate まで追ってください。Windows で報告された UNC パスのケースを再現し、その後 Dir::from_std_file(dir).entries() のリグレッションカバレッジを追加してください。\\?\UNC\ で始まる UNC パスが通常の Windows パスを壊すことなく正しく解決されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust
領域
operating-systems
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。