bytecodealliance / bytecodealliance/cap-std

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

Đang mở
#318 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Rust
Star
821
Fork
57
Merge trung bình
1 giờ 16 phút
Pull request đã merge (30 ngày)
4

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu trong cap-primitives/src/windows/fs/get_path.rs tại get_path và lần theo chuỗi read_dir qua concatenate. Tái hiện trường hợp đường dẫn UNC đã được báo cáo trên Windows, sau đó thêm kiểm thử hồi quy cho Dir::from_std_file(dir).entries(). Công việc được hoàn thành khi các đường dẫn UNC bắt đầu bằng \\?\UNC\ được phân giải chính xác mà không làm hỏng các đường dẫn Windows thông thường.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
rust
Lĩnh vực
operating-systems
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.