Add any arch; Add archive_name method for Package; Ensure

architecture matches when checking if a package is an upgrade;
This commit is contained in:
Nathan Fisher 2023-04-04 22:02:58 -04:00
parent 7d6376d5c4
commit 9cf9d469f6
2 changed files with 11 additions and 2 deletions

View File

@ -22,6 +22,7 @@ pub enum Arch {
i686, i686,
riscv64, riscv64,
x86_64, x86_64,
any,
} }
impl Default for Arch { impl Default for Arch {
@ -40,6 +41,7 @@ impl fmt::Display for Arch {
Self::i686 => "i686", Self::i686 => "i686",
Self::riscv64 => "riscv64", Self::riscv64 => "riscv64",
Self::x86_64 => "x86_64", Self::x86_64 => "x86_64",
Self::any => "any",
}) })
} }
} }
@ -66,6 +68,7 @@ impl FromStr for Arch {
"armv7l" | "arm" => Ok(Self::armv7l), "armv7l" | "arm" => Ok(Self::armv7l),
"arm64" | "aarch64" | "armv8" => Ok(Self::aarch64), "arm64" | "aarch64" | "armv8" => Ok(Self::aarch64),
"riscv" | "riscv64" => Ok(Self::riscv64), "riscv" | "riscv64" => Ok(Self::riscv64),
"any" => Ok(Self::any),
_ => Err(ParseArchError) _ => Err(ParseArchError)
} }
} }

View File

@ -113,12 +113,18 @@ impl Package {
/// Returns the formatted full package name including version and release strings /// Returns the formatted full package name including version and release strings
pub fn fullname(&self) -> String { pub fn fullname(&self) -> String {
format!("{}-{}_{}{}", self.name, self.version, self.arch, self.release) format!("{}-{}_{}_{}", self.name, self.version, self.release, self.arch)
}
/// Returns the name of the package archive
pub fn archive_name(&self) -> String {
format!("{}-{}_{}_{}.tar.zstd", self.name, self.version, self.release, self.arch)
} }
/// Tests whether this package is an update for another /// Tests whether this package is an update for another
pub fn is_upgrade(&self, other: &Self) -> bool { pub fn is_upgrade(&self, other: &Self) -> bool {
self.name == other.name self.arch == other.arch
&& self.name == other.name
&& (self.version > other.version && (self.version > other.version
|| (self.version == other.version && self.release > other.release)) || (self.version == other.version && self.release > other.release))
} }