MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / resolve_path

Method resolve_path

atomic-core/src/output/filesystem/mod.rs:70–89  ·  view source on GitHub ↗

Resolve a relative path to an absolute path within the root. This method sanitizes the path to prevent directory traversal attacks. # Errors Returns an error if the path would escape the root.

(&self, relative: &str)

Source from the content-addressed store, hash-verified

68 ///
69 /// Returns an error if the path would escape the root.
70 pub fn resolve_path(&self, relative: &str) -> io::Result<PathBuf> {
71 let path = self.root.join(relative);
72
73 // Normalize the path to resolve .. and .
74 let normalized = normalize_path(&path);
75
76 // Ensure the normalized path is still under root
77 if !normalized.starts_with(&self.root) {
78 return Err(io::Error::new(
79 io::ErrorKind::InvalidInput,
80 format!(
81 "Path '{}' escapes root directory '{}'",
82 relative,
83 self.root.display()
84 ),
85 ));
86 }
87
88 Ok(normalized)
89 }
90
91 /// Check if a path exists.
92 pub fn exists(&self, path: &str) -> bool {

Callers 15

existsMethod · 0.45
is_writableMethod · 0.45
create_dir_allMethod · 0.45
remove_pathMethod · 0.45
renameMethod · 0.45
set_permissionsMethod · 0.45
write_fileMethod · 0.45
list_dirMethod · 0.45
walk_filesMethod · 0.45
file_metadataMethod · 0.45
read_fileMethod · 0.45
modified_timeMethod · 0.45

Calls 1

normalize_pathFunction · 0.70