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

Function validate_target_path

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

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

Callers 2

run_asyncMethod · 0.85

Calls 3

parentMethod · 0.80
existsMethod · 0.45
is_emptyMethod · 0.45

Tested by 1