From b51ba8deaf81d2d9c59328d6b2b17d0b7d763f5f Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sat, 29 Mar 2025 18:13:01 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pkg/package.rs | 44 +++++++++++++++++++++++++++++--------------- src/routes/push.rs | 8 ++++---- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/pkg/package.rs b/src/pkg/package.rs index 4ec1037..b838a6f 100644 --- a/src/pkg/package.rs +++ b/src/pkg/package.rs @@ -60,7 +60,7 @@ impl Package { pub fn install_script(&self) -> Option { let pkg = self.base_path().join(self.file_name()); - read_file_tar(&pkg, ".INSTALL") + read_file_tar(&pkg, ".INSTALL", self.compression.clone()) } pub fn file_list(&self) -> Vec { @@ -112,7 +112,12 @@ impl Package { } pub fn pkginfo(&self) -> Vec<(String, String)> { - let content = read_file_tar(&self.base_path().join(self.file_name()), ".PKGINFO").unwrap(); + let content = read_file_tar( + &self.base_path().join(self.file_name()), + ".PKGINFO", + self.compression.clone(), + ) + .unwrap(); Package::pkginfo_from_str(&content) } @@ -346,7 +351,7 @@ impl Package { cleaned == "README" }) .map(|x| { - let content = read_file_tar(&pkg_file, &x).unwrap(); + let content = read_file_tar(&pkg_file, &x, self.compression.clone()).unwrap(); (x, content) }) .collect() @@ -361,7 +366,7 @@ impl Package { x.starts_with("etc/pacman.d/hooks/") || x.starts_with("usr/share/libalpm/hooks/") }) .map(|x| { - let content = read_file_tar(&pkg_file, &x).unwrap(); + let content = read_file_tar(&pkg_file, &x, self.compression.clone()).unwrap(); (x, content) }) .collect() @@ -525,14 +530,14 @@ pub fn repo_add(db_file: &str, pkg_file: &str) { run_command(vec!["repo-add", db_file, pkg_file]); } -pub fn read_file_tar(tar: &Path, file_path: &str) -> Option { - let output = Command::new("tar") - .arg("-xOJ") // Extract to stdout (-O) - .arg("-f") - .arg(tar) - .arg(file_path) - .output() - .ok()?; +pub fn read_file_tar(tar: &Path, file_path: &str, compression: Compression) -> Option { + let mut output = Command::new("tar"); + let output = match compression { + Compression::Zstd => output.arg("-xO").arg("--zstd"), + Compression::Xz => output.arg("-xOJ"), + }; + + let output = output.arg("-f").arg(tar).arg(file_path).output().ok()?; if output.status.success() { Some(String::from_utf8(output.stdout).ok()?.to_string()) @@ -541,9 +546,18 @@ pub fn read_file_tar(tar: &Path, file_path: &str) -> Option { } } -pub fn read_file_tar_raw(tar_data: &[u8], file_path: &str) -> Option { - let mut output = Command::new("tar") - .arg("-xOJ") // Extract to stdout (-O) +pub fn read_file_tar_raw( + tar_data: &[u8], + file_path: &str, + compression: Compression, +) -> Option { + let mut output = Command::new("tar"); + let output = match compression { + Compression::Zstd => output.arg("-xO").arg("--zstd"), + Compression::Xz => output.arg("xOJ"), + }; + + let mut output = output .arg("-f") .arg("-") // Indicate that the file input comes from stdin .arg(file_path) diff --git a/src/routes/push.rs b/src/routes/push.rs index 42df102..6161380 100644 --- a/src/routes/push.rs +++ b/src/routes/push.rs @@ -48,8 +48,11 @@ pub async fn upload_pkg( return Err(api_error("This repository is a mirror.")); } + let (_, _, _, _, compression) = Package::extract_pkg_name(upload.pkg.name().unwrap()) + .ok_or_else(|| api_error("Package has weird filename"))?; + let pkg_file = tmp_file_to_vec(&upload.pkg).await; - let content = read_file_tar_raw(&pkg_file, ".PKGINFO") + let content = read_file_tar_raw(&pkg_file, ".PKGINFO", compression.clone()) .ok_or_else(|| api_error("Unable to read package file"))?; let pkg_info = Package::pkginfo_from_str(&content); @@ -77,9 +80,6 @@ pub async fn upload_pkg( let arch = Architecture::parse(&arch).ok_or_else(|| api_error("Invalid architecture"))?; - let (_, _, _, _, compression) = Package::extract_pkg_name(upload.pkg.name().unwrap()) - .ok_or_else(|| api_error("Package has weird filename"))?; - let pkg = Package::new(repo, arch, pkg_name, &version, rel, compression); pkg.save(