aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/util/fs.rs26
-rw-r--r--src/util/sha1.rs7
2 files changed, 29 insertions, 4 deletions
diff --git a/src/util/fs.rs b/src/util/fs.rs
index 8ecd0d0..b1e9152 100644
--- a/src/util/fs.rs
+++ b/src/util/fs.rs
@@ -4,7 +4,10 @@ use std::path::Path;
4 4
5use tokio::fs::remove_file; 5use tokio::fs::remove_file;
6 6
7use crate::errors::McError; 7use crate::{
8 errors::McError,
9 minecraft::manifests::{Library, Rule},
10};
8 11
9pub async fn remove_if_exists(path: &Path) -> Result<(), McError> { 12pub async fn remove_if_exists(path: &Path) -> Result<(), McError> {
10 if path.exists() { 13 if path.exists() {
@@ -12,3 +15,24 @@ pub async fn remove_if_exists(path: &Path) -> Result<(), McError> {
12 } 15 }
13 Ok(()) 16 Ok(())
14} 17}
18
19pub fn library_allowed(lib: &Library) -> bool {
20 let rules: &Vec<Rule> = match &lib.rules {
21 | Some(r) => r,
22 | None => return true,
23 };
24
25 let mut allowed: bool = false;
26
27 for rule in rules {
28 let os_match: bool = match &rule.os {
29 | Some(os) => os.name == "linux",
30 | None => true,
31 };
32 if os_match {
33 allowed = rule.action == "allow";
34 }
35 }
36
37 allowed
38}
diff --git a/src/util/sha1.rs b/src/util/sha1.rs
index 6684963..6fed18d 100644
--- a/src/util/sha1.rs
+++ b/src/util/sha1.rs
@@ -2,14 +2,15 @@
2 2
3use std::path::Path; 3use std::path::Path;
4 4
5use sha1::{Digest, Sha1}; 5use sha1::{Digest, Sha1, Sha1Core};
6use sha1::digest::core_api::CoreWrapper;
6use tokio::fs::read; 7use tokio::fs::read;
7 8
8use crate::errors::McError; 9use crate::errors::McError;
9 10
10pub async fn sha1_hex(path: &Path) -> Result<String, McError> { 11pub async fn sha1_hex(path: &Path) -> Result<String, McError> {
11 let data = read(path).await?; 12 let data: Vec<u8> = read(path).await?;
12 let mut hasher = Sha1::new(); 13 let mut hasher: CoreWrapper<Sha1Core> = Sha1::new();
13 hasher.update(&data); 14 hasher.update(&data);
14 Ok(format!("{:x}", hasher.finalize())) 15 Ok(format!("{:x}", hasher.finalize()))
15} 16}