From f3d18741999a523d1eddacb4146a3d01eb1d1ef9 Mon Sep 17 00:00:00 2001 From: Daniel Alley Date: Thu, 16 Jan 2025 22:44:05 -0500 Subject: [PATCH] Apply cargo clippy fixes --- src/rpm/builder.rs | 1 - src/rpm/compressor.rs | 2 +- src/rpm/package.rs | 45 ++++++++++++++++++++++++++++++++++++++++--- src/version.rs | 14 +++++++------- 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/rpm/builder.rs b/src/rpm/builder.rs index 915a50c..d007a55 100644 --- a/src/rpm/builder.rs +++ b/src/rpm/builder.rs @@ -286,7 +286,6 @@ impl PackageBuilder { /// /// The a changelog entry consists of an entry name (which includes author, email followed by /// a dash followed by a version number), description, and the date and time of the change. - /// ``` /// # #[cfg(feature = "chrono")] /// # || -> Result<(), Box> { diff --git a/src/rpm/compressor.rs b/src/rpm/compressor.rs index befebbe..aa546d4 100644 --- a/src/rpm/compressor.rs +++ b/src/rpm/compressor.rs @@ -218,7 +218,7 @@ pub(crate) fn decompress_stream( #[cfg(feature = "xz-compression")] CompressionType::Xz => Ok(Box::new(xz2::bufread::XzDecoder::new(reader))), #[cfg(feature = "bzip2-compression")] - CompressionType::Bzip2 => Ok(Box::new(bzip2::read::BzipDecoder::new(reader))), + CompressionType::Bzip2 => Ok(Box::new(bzip2::bufread::BzDecoder::new(reader))), // This is an issue when building with all compression types enabled #[allow(unreachable_patterns)] _ => Err(Error::UnsupportedCompressorType(value.to_string())), diff --git a/src/rpm/package.rs b/src/rpm/package.rs index e361c54..e28f82c 100644 --- a/src/rpm/package.rs +++ b/src/rpm/package.rs @@ -64,6 +64,18 @@ impl Package { } /// Iterate over the file contents of the package payload + /// + /// # Examples + /// ``` + /// # fn main() -> Result<(), Box> { + /// let package = rpm::Package::open("test_assets/freesrp-udev-0.3.0-1.25.x86_64.rpm")?; + /// for entry in package.files()? { + /// let file = entry?; + /// // do something with file.content + /// println!("{} is {} bytes", file.metadata.path.display(), file.content.len()); + /// } + /// # Ok(()) } + /// ``` pub fn files(&self) -> Result { let file_entries = self.metadata.get_file_entries()?; let archive = decompress_stream( @@ -79,6 +91,14 @@ impl Package { } /// Extract all contents of the package payload to a given directory + /// + /// # Examples + /// ``` + /// # fn main() -> Result<(), Box> { + /// let package = rpm::Package::open("test_assets/ima_signed.rpm")?; + /// package.extract(&package.metadata.get_name()?)?; + /// # Ok(()) } + /// ``` pub fn extract(&self, dest: impl AsRef) -> Result<(), Error> { fs::create_dir_all(&dest)?; @@ -87,7 +107,7 @@ impl Package { .header .get_entry_data_as_string_array(IndexTag::RPMTAG_DIRNAMES)?; - // pull every base directory name in the package and create the directory in advancec + // pull every base directory name in the package and create the directory in advance for dir in dirs { let dir_path = dest .as_ref() @@ -270,7 +290,6 @@ impl Package { "signature_header(header and content)", signature_header_and_content, ); - use io::Read; let header_and_content_cursor = io::Cursor::new(&header_bytes).chain(io::Cursor::new(&self.content)); verifier.verify(header_and_content_cursor, signature_header_and_content)?; @@ -813,6 +832,16 @@ impl PackageMetadata { } /// Extract a the set of contained file names. + /// + /// # Examples + /// ``` + /// # fn main() -> Result<(), Box> { + /// let package = rpm::Package::open("test_assets/ima_signed.rpm")?; + /// for path in package.metadata.get_file_paths()? { + /// println!("{}", path.display()); + /// } + /// # Ok(()) } + /// ``` pub fn get_file_paths(&self) -> Result, Error> { // reconstruct the messy de-constructed paths let basenames = self @@ -880,7 +909,17 @@ impl PackageMetadata { }) } - /// Extract a the set of contained file names including the additional metadata. + /// Get a list of metadata about the files in the RPM, without the file contents. + /// + /// # Examples + /// ``` + /// # fn main() -> Result<(), Box> { + /// let package = rpm::Package::open("test_assets/ima_signed.rpm")?; + /// for entry in package.metadata.get_file_entries()? { + /// println!("{} is {} bytes", entry.path.display(), entry.size); + /// } + /// # Ok(()) } + /// ``` pub fn get_file_entries(&self) -> Result, Error> { // rpm does not encode it, if it is the default md5 let algorithm = self diff --git a/src/version.rs b/src/version.rs index ffd762f..cd5ae1c 100644 --- a/src/version.rs +++ b/src/version.rs @@ -127,19 +127,19 @@ impl<'a> Nevra<'a> { } } -impl<'a> fmt::Display for Nevra<'a> { +impl fmt::Display for Nevra<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}-{}.{}", self.name, self.evr, self.arch) } } -impl<'a> PartialOrd for Nevra<'a> { +impl PartialOrd for Nevra<'_> { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -impl<'a> Ord for Nevra<'a> { +impl Ord for Nevra<'_> { fn cmp(&self, other: &Self) -> Ordering { let name_cmp = compare_version_string(&self.name, &other.name); if name_cmp != Ordering::Equal { @@ -248,7 +248,7 @@ impl<'a> From<(&'a str, &'a str, &'a str)> for Evr<'a> { } } -impl<'a> PartialEq for Evr<'a> { +impl PartialEq for Evr<'_> { fn eq(&self, other: &Self) -> bool { ((self.epoch == other.epoch) || (self.epoch == "" && other.epoch == "0") @@ -258,7 +258,7 @@ impl<'a> PartialEq for Evr<'a> { } } -impl<'a> fmt::Display for Evr<'a> { +impl fmt::Display for Evr<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if !self.epoch.is_empty() { write!(f, "{}:", self.epoch)?; @@ -268,13 +268,13 @@ impl<'a> fmt::Display for Evr<'a> { } } -impl<'a> PartialOrd for Evr<'a> { +impl PartialOrd for Evr<'_> { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -impl<'a> Ord for Evr<'a> { +impl Ord for Evr<'_> { fn cmp(&self, other: &Self) -> Ordering { let epoch_1 = if self.epoch.is_empty() { "0"