diff options
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/fs.rs | 12 | ||||
| -rw-r--r-- | src/util/mod.rs | 2 | ||||
| -rw-r--r-- | src/util/sha1.rs | 14 |
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 | |||
| 3 | use std::path::Path; | ||
| 4 | |||
| 5 | use crate::errors::McError; | ||
| 6 | |||
| 7 | pub 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 @@ | |||
| 1 | pub mod fs; | ||
| 2 | pub 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 | |||
| 3 | use std::path::Path; | ||
| 4 | |||
| 5 | use sha1::{Digest, Sha1}; | ||
| 6 | |||
| 7 | use crate::errors::McError; | ||
| 8 | |||
| 9 | pub 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 | } | ||
