diff options
Diffstat (limited to '')
| -rw-r--r-- | src/util/fs.rs | 26 |
1 files changed, 25 insertions, 1 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 | ||
| 5 | use tokio::fs::remove_file; | 5 | use tokio::fs::remove_file; |
| 6 | 6 | ||
| 7 | use crate::errors::McError; | 7 | use crate::{ |
| 8 | errors::McError, | ||
| 9 | minecraft::manifests::{Library, Rule}, | ||
| 10 | }; | ||
| 8 | 11 | ||
| 9 | pub async fn remove_if_exists(path: &Path) -> Result<(), McError> { | 12 | pub 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 | |||
| 19 | pub 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 | } | ||
