MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / reject_symlink_components

Function reject_symlink_components

src/storage.rs:559–590  ·  view source on GitHub ↗
(path: &Path, subject: &str)

Source from the content-addressed store, hash-verified

557}
558
559fn 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(&current) {
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
592fn invalid_input(message: impl Into<String>) -> io::Error {
593 io::Error::new(io::ErrorKind::InvalidInput, message.into())

Callers 6

resolveMethod · 0.70
create_dir_allMethod · 0.70
write_fileMethod · 0.70
append_lineMethod · 0.70
write_file_atomicallyMethod · 0.70
copy_artifactMethod · 0.70

Calls 3

invalid_inputFunction · 0.85
pushMethod · 0.80
kindMethod · 0.80

Tested by

no test coverage detected