diff --git a/Cargo.toml b/Cargo.toml index 3c09ade..0a8498c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ md-5 = "0.10.5" # bitflags = "1.3.2" hex = "0.4.3" indexmap = "2.0.0" -pyo3 = { version = "0.18.1", features = ["extension-module"], optional = true } +pyo3 = { version = "0.20.0", features = ["extension-module"], optional = true } [lib] name = "rpmrepo_metadata" diff --git a/src/common.rs b/src/common.rs index a79f975..8f39c65 100644 --- a/src/common.rs +++ b/src/common.rs @@ -21,7 +21,7 @@ use std::fmt; /// without a caret, e.g. 0.5.0 vs 0.5.0~rc1. Including ^ in a version is used for denoting snapshots /// not directly associated with an upstream release and will force it to sort higher, e.g. /// 0.5.0 vs 0.5.0^deadbeef -#[derive(Debug, Eq, Default, Clone)] +#[derive(Clone, Debug, Default, Eq, Hash)] pub struct EVR { pub epoch: String, pub version: String, diff --git a/src/metadata.rs b/src/metadata.rs index acaa5fc..23bf839 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -6,6 +6,7 @@ use std::convert::TryInto; use std::io::{BufRead, Write}; +use std::hash::{Hash, Hasher}; use std::os::unix::prelude::MetadataExt; use std::path::{Path, PathBuf}; @@ -155,7 +156,7 @@ impl TryInto for &str { // } // } -#[derive(Debug, PartialEq, Default)] +#[derive(Clone, Default, Debug, PartialEq, Hash)] pub struct Package { // pub(crate) parse_state: ParseState, pub name: String, @@ -576,7 +577,7 @@ impl Package { } } -#[derive(Debug, PartialEq, Clone, Copy)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum ChecksumType { Md5, Sha1, @@ -593,7 +594,7 @@ impl Default for ChecksumType { } } -#[derive(Debug, PartialEq, Clone)] +#[derive(Clone, Debug, PartialEq)] pub enum Checksum { Md5(String), Sha1(String), @@ -611,6 +612,23 @@ impl Default for Checksum { } } +impl Hash for Checksum { + fn hash(&self, state: &mut H) { + match self { + Self::Md5(hash) => format!("md5:{}", hash).hash(state), + Self::Sha1(hash) => format!("sha1:{}", hash).hash(state), + Self::Sha224(hash) => format!("sha224:{}", hash).hash(state), + Self::Sha256(hash) => format!("sha256:{}", hash).hash(state), + Self::Sha384(hash) => format!("sha384:{}", hash).hash(state), + Self::Sha512(hash) => format!("sha512:{}", hash).hash(state), + // TODO: adjust this representation. Currently these exist because of reuse of these enums + // to represent intermediate parsing states, but those probably ought to be pulled out somehow + Self::Unknown(hash) => unimplemented!(), + Self::Empty => unimplemented!(), + } + } +} + impl Checksum { pub fn try_create + Sized>( checksum_type: N, @@ -719,21 +737,21 @@ impl Checksum { } } -#[derive(Clone, Debug, PartialEq, Default)] +#[derive(Clone, Debug, Default, Hash, PartialEq)] pub struct Changelog { pub author: String, pub timestamp: u64, pub description: String, } -#[derive(Debug, PartialEq, Default)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialEq)] pub struct HeaderRange { pub start: u64, pub end: u64, } // Requirement (Provides, Conflicts, Obsoletes, Requires). -#[derive(Clone, Debug, PartialEq, Default)] +#[derive(Clone, Debug, Default, Hash, PartialEq)] pub struct Requirement { pub name: String, pub flags: Option, @@ -743,6 +761,7 @@ pub struct Requirement { pub preinstall: bool, } +#[derive(Copy, Clone, Debug, Hash, PartialEq)] pub enum RequirementType { LT, GT, @@ -780,7 +799,7 @@ impl TryFrom<&str> for RequirementType { } } -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Hash)] pub enum FileType { File, Dir, @@ -814,7 +833,7 @@ impl Default for FileType { } } -#[derive(Clone, Debug, PartialEq, Default)] +#[derive(Clone, Debug, Default, Hash, PartialEq)] pub struct PackageFile { pub filetype: FileType, pub path: String, diff --git a/src/repository.rs b/src/repository.rs index 8da6e00..3d708fe 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -188,7 +188,7 @@ impl Repository { /// - `metadata_compression_type` - The type of compression to use for repository metadata. /// - `metadata_checksum_type` - The type of checksums to use for metadata. /// - `package_checksum_type` - The type of checksums to use for packages. -#[derive(Debug, Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub struct RepositoryOptions { pub simple_metadata_filenames: bool, pub metadata_compression_type: CompressionType,