diff --git a/src/index.rs b/src/index.rs index d681555f4..57c7f6616 100644 --- a/src/index.rs +++ b/src/index.rs @@ -55,12 +55,10 @@ fn package_record_from_index_json( fn package_record_from_tar_bz2(file: &Path) -> Result { let reader = std::fs::File::open(file)?; let mut archive = read::stream_tar_bz2(reader); - - for entry in archive.entries()? { - let mut entry = entry?; + for entry in archive.entries()?.flatten() { + let mut entry = entry; let path = entry.path()?; - let path = path.to_string_lossy(); - if path == "info/index.json" { + if path.as_os_str().eq("info/index.json") { return package_record_from_index_json(file, &mut entry); } } @@ -74,11 +72,10 @@ fn package_record_from_conda(file: &Path) -> Result { - if let Ok(record) = package_record_from_tar_bz2(p) { - repodata - .packages - .insert(p.file_name().unwrap().to_string_lossy().into(), record); - } else { - tracing::info!("Could not read package record from {:?}", p); - } - } - ArchiveType::Conda => { - if let Ok(record) = package_record_from_conda(p) { - repodata - .conda_packages - .insert(p.file_name().unwrap().to_string_lossy().to_string(), record); - } else { - tracing::info!("Could not read package record from {:?}", p); - } - } + let record = match t { + ArchiveType::TarBz2 => package_record_from_tar_bz2(p), + ArchiveType::Conda => package_record_from_conda(p), + }; + let (Ok(record), Some(file_name)) = (record, p.file_name()) else { + tracing::info!("Could not read package record from {:?}", p); + continue; }; + repodata + .conda_packages + .insert(file_name.to_string_lossy().to_string(), record); } let out_file = output_folder.join(platform).join("repodata.json"); File::create(&out_file)?.write_all(serde_json::to_string_pretty(&repodata)?.as_bytes())?; @@ -203,13 +191,4 @@ pub fn index( Ok(()) } -#[cfg(test)] -mod test { - - #[test] - fn test_index() { - // let output_folder = PathBuf::from("/Users/wolfv/Programs/roar/output"); - // let target_platform = "osx-64"; - // index(&output_folder, Some(target_platform)).unwrap(); - } -} +// TODO: write proper unit tests for above functions diff --git a/src/metadata.rs b/src/metadata.rs index ff144741a..80c902bad 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -321,9 +321,9 @@ mod tests { // with build_id (aka timestamp) let timestamp = &Utc::now(); let p2 = setup_build_dir(dir.path(), "name", false, timestamp).unwrap(); - let f2 = p2.file_name().unwrap().to_string_lossy(); + let f2 = p2.file_name().unwrap(); let epoch = timestamp.timestamp(); - assert!(f2.eq(&format!("rattler-build_name_{epoch}"))); + assert!(f2.eq(format!("rattler-build_name_{epoch}").as_str())); _ = std::fs::remove_dir_all(p2); } } diff --git a/src/source/mod.rs b/src/source/mod.rs index 995c284a4..e00bb019e 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -158,11 +158,11 @@ fn extract( ) -> Result { let output = Command::new("tar") .arg("-xf") - .arg(String::from(archive.to_string_lossy())) + .arg(archive.as_os_str()) .arg("--preserve-permissions") .arg("--strip-components=1") .arg("-C") - .arg(String::from(target_directory.to_string_lossy())) + .arg(target_directory.as_os_str()) .output(); output