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