| 223 | /// if it exists, otherwise returns the original path. |
| 224 | #[tracing::instrument(target = "cargo_lambda")] |
| 225 | fn adjust_remote_zip_base(url: &str, path: &Path) -> Option<PathBuf> { |
| 226 | let archive_regex = regex::Regex::new( |
| 227 | r"https://(?P<host>[a-zA-Z0-9.-]+)/[a-zA-Z0-9][a-zA-Z0-9_-]+/(?P<repo>[a-zA-Z0-9][a-zA-Z0-9_-]+)(/-)?/archive/(refs/heads|[a-zA-Z0-9]+)/(?P<ref>[^/]+)\.zip$" |
| 228 | ).into_diagnostic() |
| 229 | .expect("invalid zip url regex"); |
| 230 | |
| 231 | if let Some(caps) = archive_regex.captures(url) { |
| 232 | let repo = caps.name("repo")?.as_str(); |
| 233 | let reference = caps.name("ref")?.as_str(); |
| 234 | let reference = reference.replace(&format!("{repo}-"), ""); |
| 235 | let base_dir = format!("{repo}-{reference}"); |
| 236 | |
| 237 | let base_path = path.join(&base_dir); |
| 238 | tracing::trace!( |
| 239 | ?base_path, |
| 240 | exists = base_path.exists(), |
| 241 | "looking for base directory" |
| 242 | ); |
| 243 | |
| 244 | if base_path.exists() && base_path.is_dir() { |
| 245 | return Some(base_path); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | None |
| 250 | } |
| 251 | |
| 252 | fn find_local_directory(value: &str) -> Result<PathBuf> { |
| 253 | let path = dunce::realpath(value) |