exp: cross #6

This commit is contained in:
2025-12-22 23:08:44 +01:00
parent 63389f0bad
commit 3ecfe6dda2
6 changed files with 101 additions and 16 deletions

View File

@@ -262,6 +262,35 @@ async fn fetch_orig_tarball(
Ok(())
}
async fn fetch_dsc_file(
info: &PackageInfo,
cwd: Option<&Path>,
progress: ProgressCallback<'_>,
) -> Result<(), Box<dyn Error>> {
let target_dir = cwd.unwrap_or_else(|| Path::new("."));
// Find the dsc file in the file list
let dsc_file = info
.stanza
.files
.iter()
.find(|f| f.name.ends_with(".dsc"))
.ok_or("Could not find .dsc file in package info")?;
let filename = &dsc_file.name;
debug!("Fetching dsc file: {}", filename);
download_file_checksum(
format!("{}/{}", &info.archive_url, filename).as_str(),
&dsc_file.sha256,
target_dir,
progress,
)
.await?;
Ok(())
}
async fn fetch_archive_sources(
info: &PackageInfo,
cwd: Option<&Path>,
@@ -399,6 +428,7 @@ pub async fn pull(
0,
);
}
clone_repo(
url.as_str(),
package,
@@ -406,6 +436,7 @@ pub async fn pull(
Some(&package_dir),
progress,
)?;
if !package_info.is_native() {
if let Some(cb) = progress {
cb("Fetching orig tarball...", "", 0, 0);
@@ -414,12 +445,17 @@ pub async fn pull(
} else {
debug!("Native package, skipping orig tarball fetch.");
}
if let Some(cb) = progress {
cb("Fetching dsc file...", "", 0, 0);
}
fetch_dsc_file(&package_info, Some(&package_dir), progress).await?;
} else {
// Fallback to archive fetching
if let Some(cb) = progress {
cb("Downloading from archive...", "", 0, 0);
}
fetch_archive_sources(&package_info, Some(cwd.unwrap_or(Path::new("."))), progress).await?;
fetch_archive_sources(&package_info, Some(&package_dir), progress).await?;
}
Ok(package_info)
@@ -482,16 +518,20 @@ mod tests {
// Check for orig tarball in package dir
let mut found_tarball = false;
let mut found_dsc = false;
for entry in std::fs::read_dir(package_dir).unwrap() {
let entry = entry.unwrap();
let name = entry.file_name().to_string_lossy().to_string();
if name.contains(".orig.tar.") {
found_tarball = true;
break;
}
if name.ends_with(".dsc") {
found_dsc = true;
}
}
assert!(found_tarball, "Orig tarball not found in package dir");
assert!(found_dsc, "DSC file not found in package dir");
}
#[tokio::test]