| 1 | use std::path::{Path, PathBuf}; |
| 2 | |
| 3 | pub fn windows_path(text: &str) -> String { |
| 4 | let Some(path) = text.strip_prefix(r"\\?\") else { |
| 5 | return text.to_owned(); |
| 6 | }; |
| 7 | let bytes = path.as_bytes(); |
| 8 | // 일반 드라이브의 의미가 바뀌지 않는 경로만 변환함. |
| 9 | if bytes.len() < 3 |
| 10 | || !bytes[0].is_ascii_alphabetic() |
| 11 | || &bytes[1..3] != b":\\" |
| 12 | || (path.len() > 3 |
| 13 | && path[3..].split('\\').any(|part| { |
| 14 | part.is_empty() |
| 15 | || worker_protocol::archive::valid_name(part, false).is_err() |
| 16 | || part.contains('/') |
| 17 | })) |
| 18 | { |
| 19 | return text.to_owned(); |
| 20 | } |
| 21 | path.to_owned() |
| 22 | } |
| 23 | |
| 24 | pub fn worker_path(path: &Path) -> PathBuf { |
| 25 | #[cfg(windows)] |
| 26 | if let Some(text) = path.to_str() { |
| 27 | return PathBuf::from(windows_path(text)); |
| 28 | } |
| 29 | path.to_path_buf() |
| 30 | } |