MCPcopy Create free account
hub / github.com/cargo-lambda/cargo-lambda / adjust_remote_zip_base

Function adjust_remote_zip_base

crates/cargo-lambda-new/src/template.rs:225–250  ·  view source on GitHub ↗
(url: &str, path: &Path)

Source from the content-addressed store, hash-verified

223/// if it exists, otherwise returns the original path.
224#[tracing::instrument(target = "cargo_lambda")]
225fn 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
252fn find_local_directory(value: &str) -> Result<PathBuf> {
253 let path = dunce::realpath(value)

Callers 2

expandMethod · 0.85

Calls 2

newFunction · 0.85
as_strMethod · 0.80

Tested by 1