impl TryFrom<&Path> for Plist

This commit is contained in:
Nathan Fisher 2023-03-22 00:01:57 -04:00
parent 634c19be51
commit 953c3abbc9
5 changed files with 158 additions and 9 deletions

136
Cargo.lock generated
View File

@ -2,6 +2,12 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "base64"
version = "0.13.1"
@ -72,6 +78,49 @@ dependencies = [
"libc",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
dependencies = [
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b"
dependencies = [
"cfg-if",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
@ -92,6 +141,12 @@ dependencies = [
"crypto-common",
]
[[package]]
name = "either"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
[[package]]
name = "errno"
version = "0.2.8"
@ -123,6 +178,15 @@ dependencies = [
"version_check",
]
[[package]]
name = "hermit-abi"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.3.1"
@ -134,9 +198,11 @@ name = "hpk"
version = "0.1.0"
dependencies = [
"clap",
"rayon",
"ron",
"serde",
"sha2",
"walkdir",
]
[[package]]
@ -145,7 +211,7 @@ version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb"
dependencies = [
"hermit-abi",
"hermit-abi 0.3.1",
"libc",
"windows-sys",
]
@ -156,7 +222,7 @@ version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e"
dependencies = [
"hermit-abi",
"hermit-abi 0.3.1",
"io-lifetimes",
"rustix",
"windows-sys",
@ -174,6 +240,25 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
[[package]]
name = "memoffset"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [
"hermit-abi 0.2.6",
"libc",
]
[[package]]
name = "os_str_bytes"
version = "6.5.0"
@ -198,6 +283,28 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rayon"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-utils",
"num_cpus",
]
[[package]]
name = "ron"
version = "0.8.0"
@ -223,6 +330,21 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.158"
@ -298,6 +420,16 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "walkdir"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "winapi"
version = "0.3.9"

View File

@ -7,8 +7,10 @@ edition = "2021"
[dependencies]
clap = "4.1"
rayon = "1.7"
ron = "0.8"
sha2 = "0.10"
walkdir = "2.3"
[dependencies.serde]
version = "1.0"

View File

@ -1,7 +1,7 @@
use {
crate::Version,
serde::{Serialize, Deserialize},
super::Package,
crate::Version,
serde::{Deserialize, Serialize},
};
#[derive(Debug, Serialize, Deserialize, PartialEq)]
@ -15,9 +15,7 @@ impl Dependency {
pub fn satisfied(&self, package: &Package) -> bool {
if self.name.as_str() == package.name.as_str() {
match &self.version {
(Some(low), Some(high)) => {
&package.version >= low && &package.version < high
},
(Some(low), Some(high)) => &package.version >= low && &package.version < high,
(Some(low), None) => &package.version >= low,
(None, Some(high)) => &package.version < high,
// no version requirements

View File

@ -1,9 +1,9 @@
mod dependency;
pub use dependency::Dependency;
use {
crate::{Plist, Version},
serde::{Serialize, Deserialize},
serde::{Deserialize, Serialize},
};
pub use dependency::Dependency;
#[derive(Serialize, Deserialize)]
pub struct Package {

View File

@ -1,4 +1,5 @@
use {
rayon::prelude::*,
serde::{Deserialize, Serialize},
sha2::{digest::Digest, Sha256},
std::{
@ -9,6 +10,7 @@ use {
os::unix::fs::MetadataExt,
path::{Path, PathBuf},
},
walkdir::WalkDir,
};
#[derive(Deserialize, Serialize)]
@ -16,6 +18,21 @@ pub struct Plist {
pub entries: Vec<Entry>,
}
impl TryFrom<&Path> for Plist {
type Error = Box<dyn Error>;
fn try_from(value: &Path) -> Result<Self, Self::Error> {
let entries = WalkDir::new(value)
.into_iter()
.collect::<Vec<_>>()
.par_iter()
.filter(|x| x.is_ok())
.filter_map(|x| Entry::try_from(x.as_ref().unwrap().path().to_path_buf().as_path()).ok())
.collect();
Ok(Self { entries })
}
}
#[derive(Deserialize, Serialize, PartialEq)]
pub enum Entry {
File {