This commit is contained in:
parent
47ec307f7b
commit
b51ba8deaf
2 changed files with 33 additions and 19 deletions
|
@ -60,7 +60,7 @@ impl Package {
|
|||
|
||||
pub fn install_script(&self) -> Option<String> {
|
||||
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<String> {
|
||||
|
@ -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<String> {
|
||||
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<String> {
|
||||
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<String> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read_file_tar_raw(tar_data: &[u8], file_path: &str) -> Option<String> {
|
||||
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<String> {
|
||||
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)
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue