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)
| 147 | /// validate_target_path(Path::new("/")).unwrap_err(); |
| 148 | /// ``` |
| 149 | pub 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 | /// |