pull: move orig tarball content to the right place on archive download
All checks were successful
CI / build (push) Successful in 9m13s
All checks were successful
CI / build (push) Successful in 9m13s
This commit is contained in:
57
src/pull.rs
57
src/pull.rs
@@ -90,6 +90,26 @@ use futures_util::StreamExt;
|
|||||||
use tar::Archive;
|
use tar::Archive;
|
||||||
use xz2::read::XzDecoder;
|
use xz2::read::XzDecoder;
|
||||||
|
|
||||||
|
fn copy_dir_all(src: &Path, dst: &Path) -> Result<(), Box<dyn Error>> {
|
||||||
|
if !dst.exists() {
|
||||||
|
std::fs::create_dir_all(dst)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
for entry in std::fs::read_dir(src)? {
|
||||||
|
let entry = entry?;
|
||||||
|
let src_path = entry.path();
|
||||||
|
let dst_path = dst.join(entry.file_name());
|
||||||
|
|
||||||
|
if src_path.is_dir() {
|
||||||
|
copy_dir_all(&src_path, &dst_path)?;
|
||||||
|
} else {
|
||||||
|
std::fs::copy(&src_path, &dst_path)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn extract_archive(path: &Path, dest: &Path) -> Result<(), Box<dyn Error>> {
|
fn extract_archive(path: &Path, dest: &Path) -> Result<(), Box<dyn Error>> {
|
||||||
let file = File::open(path)?;
|
let file = File::open(path)?;
|
||||||
let filename = path.file_name().unwrap().to_string_lossy();
|
let filename = path.file_name().unwrap().to_string_lossy();
|
||||||
@@ -338,13 +358,46 @@ async fn fetch_archive_sources(
|
|||||||
.find(|f| f.name.contains(".orig.tar."))
|
.find(|f| f.name.contains(".orig.tar."))
|
||||||
{
|
{
|
||||||
let path = package_dir.join(&orig_file.name);
|
let path = package_dir.join(&orig_file.name);
|
||||||
let extract_dir = package_dir.join(&info.stanza.package);
|
let extract_dir = package_dir;
|
||||||
|
|
||||||
if (orig_file.name.ends_with(".tar.xz") || orig_file.name.ends_with(".tar.gz"))
|
if (orig_file.name.ends_with(".tar.xz") || orig_file.name.ends_with(".tar.gz"))
|
||||||
&& let Err(e) = extract_archive(&path, &extract_dir)
|
&& let Err(e) = extract_archive(&path, extract_dir)
|
||||||
{
|
{
|
||||||
return Err(format!("Failed to extract {}: {}", orig_file.name, e).into());
|
return Err(format!("Failed to extract {}: {}", orig_file.name, e).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rename from 'package-origversion' to 'package', merging with existing directory
|
||||||
|
let target_dir = package_dir.join(&info.stanza.package);
|
||||||
|
let entries = std::fs::read_dir(package_dir)?;
|
||||||
|
for entry in entries {
|
||||||
|
let entry = entry?;
|
||||||
|
let entry_path = entry.path();
|
||||||
|
if entry_path.is_dir() {
|
||||||
|
let dir_name = entry.file_name().to_string_lossy().to_string();
|
||||||
|
if dir_name.starts_with(&format!("{}-", info.stanza.package)) {
|
||||||
|
// Found a directory like 'package-version', rename it to 'package'
|
||||||
|
if target_dir.exists() {
|
||||||
|
// Target exists, we need to merge contents
|
||||||
|
for sub_entry in std::fs::read_dir(&entry_path)? {
|
||||||
|
let sub_entry = sub_entry?;
|
||||||
|
let sub_path = sub_entry.path();
|
||||||
|
let target_path = target_dir.join(sub_entry.file_name());
|
||||||
|
if sub_path.is_dir() {
|
||||||
|
std::fs::create_dir_all(&target_path)?;
|
||||||
|
// Recursively copy directory contents
|
||||||
|
copy_dir_all(&sub_path, &target_path)?;
|
||||||
|
} else {
|
||||||
|
std::fs::copy(&sub_path, &target_path)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::fs::remove_dir_all(&entry_path)?;
|
||||||
|
} else {
|
||||||
|
std::fs::rename(&entry_path, &target_dir)?;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user