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

Function validate_target_path

atomic-cli/src/commands/clone/helpers.rs:149–168  ·  view source on GitHub ↗

Validate that the target path is suitable for cloning. Checks that: 1. The path doesn't already exist as a directory 2. The path doesn't already exist as a file 3. The parent directory exists (or can be created) # Arguments `path` - The target path to validate # Returns `Ok(())` if the path is valid, `Err` with appropriate error otherwise. # Errors - `CliError::RepositoryExists` if a direct

(path: &Path)

Source from the content-addressed store, hash-verified

147/// validate_target_path(Path::new("/")).unwrap_err();
148/// ```
149pub fn validate_target_path(path: &Path) -> CliResult<()> {
150 if path.exists() {
151 return Err(CliError::RepositoryExists {
152 path: path.to_path_buf(),
153 });
154 }
155
156 // Check that the parent directory exists or can be created
157 if let Some(parent) = path.parent() {
158 if !parent.as_os_str().is_empty() && !parent.exists() {
159 // Try to create parent directories
160 std::fs::create_dir_all(parent).map_err(|e| CliError::InvalidPath {
161 path: parent.to_path_buf(),
162 source: Some(e),
163 })?;
164 }
165 }
166
167 Ok(())
168}
169
170/// Resolve the target path for cloning.
171///

Callers 2

run_asyncMethod · 0.85

Calls 3

parentMethod · 0.80
existsMethod · 0.45
is_emptyMethod · 0.45

Tested by 1