(path: &Path, subject: &str)
| 557 | } |
| 558 | |
| 559 | fn reject_symlink_components(path: &Path, subject: &str) -> io::Result<()> { |
| 560 | let mut current = PathBuf::new(); |
| 561 | let mut has_normal_component = false; |
| 562 | for component in path.components() { |
| 563 | match component { |
| 564 | Component::Normal(_) => { |
| 565 | current.push(component.as_os_str()); |
| 566 | has_normal_component = true; |
| 567 | } |
| 568 | Component::RootDir | Component::Prefix(_) => { |
| 569 | current.push(component.as_os_str()); |
| 570 | } |
| 571 | Component::CurDir | Component::ParentDir => { |
| 572 | return Err(invalid_input(format!("{subject} path must be normalized"))); |
| 573 | } |
| 574 | } |
| 575 | if !has_normal_component { |
| 576 | continue; |
| 577 | } |
| 578 | match fs::symlink_metadata(¤t) { |
| 579 | Ok(meta) if meta.file_type().is_symlink() => { |
| 580 | return Err(invalid_input(format!( |
| 581 | "{subject} path must not contain symlinks" |
| 582 | ))); |
| 583 | } |
| 584 | Ok(_) => {} |
| 585 | Err(err) if err.kind() == io::ErrorKind::NotFound => break, |
| 586 | Err(err) => return Err(err), |
| 587 | } |
| 588 | } |
| 589 | Ok(()) |
| 590 | } |
| 591 | |
| 592 | fn invalid_input(message: impl Into<String>) -> io::Error { |
| 593 | io::Error::new(io::ErrorKind::InvalidInput, message.into()) |
no test coverage detected