Skip to content

Commit

Permalink
Apply cargo clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed Jan 17, 2025
1 parent 9d8418e commit 8ffcf4d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/rpm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
Expand Down
2 changes: 1 addition & 1 deletion src/rpm/compressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down
45 changes: 42 additions & 3 deletions src/rpm/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ impl Package {
}

/// Iterate over the file contents of the package payload
///
/// # Examples
/// ```ignore
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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<FileIterator, Error> {
let file_entries = self.metadata.get_file_entries()?;
let archive = decompress_stream(
Expand All @@ -79,6 +91,14 @@ impl Package {
}

/// Extract all contents of the package payload to a given directory
///
/// # Examples
/// ```ignore
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let package = rpm::Package::open("test_assets/ima_signed.rpm")?;
/// package.extract(&package.metadata.get_name()?)?;
/// # Ok(()) }
/// ```
pub fn extract(&self, dest: impl AsRef<Path>) -> Result<(), Error> {
fs::create_dir_all(&dest)?;

Expand All @@ -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()
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -813,6 +832,16 @@ impl PackageMetadata {
}

/// Extract a the set of contained file names.
///
/// # Examples
/// ```
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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<Vec<PathBuf>, Error> {
// reconstruct the messy de-constructed paths
let basenames = self
Expand Down Expand Up @@ -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<dyn std::error::Error>> {
/// 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<Vec<FileEntry>, Error> {
// rpm does not encode it, if it is the default md5
let algorithm = self
Expand Down
14 changes: 7 additions & 7 deletions src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ordering> {
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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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)?;
Expand All @@ -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<Ordering> {
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"
Expand Down

0 comments on commit 8ffcf4d

Please sign in to comment.