diff --git a/rust-tests/src/lib.rs b/rust-tests/src/lib.rs index 3c6841c4..e786bde5 100644 --- a/rust-tests/src/lib.rs +++ b/rust-tests/src/lib.rs @@ -447,4 +447,13 @@ mod tests { assert!(rattler_build.is_ok()); assert!(rattler_build.unwrap().status.success()); } + + #[test] + fn test_tar_source() { + let tmp = tmp("test_tar_source"); + let rattler_build = + rattler().build::<_, _, &str>(recipes().join("tar-source"), tmp.as_dir(), None); + assert!(rattler_build.is_ok()); + assert!(rattler_build.unwrap().status.success()); + } } diff --git a/src/source/mod.rs b/src/source/mod.rs index 8121e7f2..e8cc5ce9 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -22,6 +22,9 @@ pub enum SourceError { #[error("Failed to download source from url: {0}")] Url(#[from] reqwest::Error), + #[error("Url does not point to a file: {0}")] + UrlNotFile(url::Url), + #[error("WalkDir Error: {0}")] WalkDir(#[from] walkdir::Error), @@ -100,6 +103,13 @@ pub async fn fetch_sources( } Source::Url(src) => { tracing::info!("Fetching source from URL: {}", src.url()); + + let file_name_from_url = src + .url() + .path_segments() + .and_then(|segments| segments.last().map(|last| last.to_string())) + .ok_or_else(|| SourceError::UrlNotFile(src.url().clone()))?; + let res = url_source::url_src(src, &cache_src).await?; let mut dest_dir = if let Some(folder) = src.folder() { work_dir.join(folder) @@ -126,12 +136,7 @@ pub async fn fetch_sources( if let Some(file_name) = src.file_name() { dest_dir = dest_dir.join(file_name); } else { - dest_dir = dest_dir.join(res.file_name().ok_or_else(|| { - SourceError::UnknownError(format!( - "Failed to get filename for `{}`", - res.display() - )) - })?); + dest_dir = dest_dir.join(file_name_from_url); } fs::copy(&res, &dest_dir)?; tracing::info!("Downloaded to {:?}", dest_dir); @@ -192,7 +197,7 @@ pub async fn fetch_sources( fn extract(archive: &Path, target_directory: &Path) -> Result { let tar_exe = which::which("tar").map_err(|_| SourceError::TarNotFound)?; - let output = Command::new(tar_exe) + let output = Command::new(&tar_exe) .arg("-xf") .arg(archive.as_os_str()) .arg("--preserve-permissions") @@ -203,7 +208,8 @@ fn extract(archive: &Path, target_directory: &Path) -> Result