aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/util/fs.rs12
-rw-r--r--src/util/mod.rs2
-rw-r--r--src/util/sha1.rs14
3 files changed, 28 insertions, 0 deletions
diff --git a/src/util/fs.rs b/src/util/fs.rs
new file mode 100644
index 0000000..b86c0d7
--- /dev/null
+++ b/src/util/fs.rs
@@ -0,0 +1,12 @@
1#![allow(dead_code)]
2
3use std::path::Path;
4
5use crate::errors::McError;
6
7pub async fn remove_if_exists(path: &Path) -> Result<(), McError> {
8 if path.exists() {
9 tokio::fs::remove_file(path).await?;
10 }
11 Ok(())
12}
diff --git a/src/util/mod.rs b/src/util/mod.rs
new file mode 100644
index 0000000..8176b9b
--- /dev/null
+++ b/src/util/mod.rs
@@ -0,0 +1,2 @@
1pub mod fs;
2pub mod sha1;
diff --git a/src/util/sha1.rs b/src/util/sha1.rs
new file mode 100644
index 0000000..c5f1021
--- /dev/null
+++ b/src/util/sha1.rs
@@ -0,0 +1,14 @@
1#![allow(dead_code)]
2
3use std::path::Path;
4
5use sha1::{Digest, Sha1};
6
7use crate::errors::McError;
8
9pub async fn sha1_hex(path: &Path) -> Result<String, McError> {
10 let data = tokio::fs::read(path).await?;
11 let mut hasher = Sha1::new();
12 hasher.update(&data);
13 Ok(format!("{:x}", hasher.finalize()))
14}