From 3080fee86be46148567612ecfdae27c8341b71e6 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Fri, 27 Dec 2024 05:35:27 +0100 Subject: [PATCH] fix --- src/pkg.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/pkg.rs b/src/pkg.rs index b775656..57649e4 100644 --- a/src/pkg.rs +++ b/src/pkg.rs @@ -55,19 +55,33 @@ impl Repository { .ok() } + pub fn extract_pkg_name(name: &str) -> (String, String, String, String) { + // "{}-{}-{}-{}.pkg.tar.zst" + let splitted: Vec<&str> = name.split('-').collect(); + let name = splitted.get(0).unwrap(); + let version = splitted.get(1).unwrap(); + let rel = splitted.get(2).unwrap(); + let arch = splitted.get(3).unwrap().trim_end_matches(".pkg.tar.zst"); + + ( + name.to_string(), + version.to_string(), + rel.to_string(), + arch.to_string(), + ) + } + pub fn get_pkg(&self, arch: &str, pkg_name: &str) -> Option { - let pkg = if pkg_name.ends_with(".pkg.tar.zst") { - Package::find(&self.name, arch, pkg_name.trim_end_matches(".pkg.tar.zst")) - } else if pkg_name.ends_with(".pkg.tar.zst.sig") { - Package::find( - &self.name, - arch, - pkg_name.trim_end_matches(".pkg.tar.zst.sig"), - ) + let pkg_name = if pkg_name.ends_with(".sig") { + pkg_name.trim_end_matches(".sig").to_string() } else { - Package::find(&self.name, arch, pkg_name) + pkg_name.to_string() }; + let (name, version, _, _) = Repository::extract_pkg_name(&pkg_name); + + let pkg = Package::new(&self.name, &arch, &name, &version); + if pkg.exists() { return Some(pkg); } else {