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

Function validate_target_path

atomic-cli/src/commands/clone/helpers.rs:147–166  ·  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

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

Callers 3

run_git_bootstrapMethod · 0.85
run_asyncMethod · 0.85

Calls 3

parentMethod · 0.80
existsMethod · 0.45
is_emptyMethod · 0.45

Tested by 1