diff options
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/fs.rs | 4 | ||||
| -rw-r--r-- | src/util/mod.rs | 12 | ||||
| -rw-r--r-- | src/util/sha1.rs | 3 |
3 files changed, 17 insertions, 2 deletions
diff --git a/src/util/fs.rs b/src/util/fs.rs index b86c0d7..8ecd0d0 100644 --- a/src/util/fs.rs +++ b/src/util/fs.rs | |||
| @@ -2,11 +2,13 @@ | |||
| 2 | 2 | ||
| 3 | use std::path::Path; | 3 | use std::path::Path; |
| 4 | 4 | ||
| 5 | use tokio::fs::remove_file; | ||
| 6 | |||
| 5 | use crate::errors::McError; | 7 | use crate::errors::McError; |
| 6 | 8 | ||
| 7 | pub async fn remove_if_exists(path: &Path) -> Result<(), McError> { | 9 | pub async fn remove_if_exists(path: &Path) -> Result<(), McError> { |
| 8 | if path.exists() { | 10 | if path.exists() { |
| 9 | tokio::fs::remove_file(path).await?; | 11 | remove_file(path).await?; |
| 10 | } | 12 | } |
| 11 | Ok(()) | 13 | Ok(()) |
| 12 | } | 14 | } |
diff --git a/src/util/mod.rs b/src/util/mod.rs index 8176b9b..b8531c6 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs | |||
| @@ -1,2 +1,14 @@ | |||
| 1 | //! Utility module for the DML launcher. | ||
| 2 | //! | ||
| 3 | //! This module contains general-purpose helper functions used throughout | ||
| 4 | //! the project. It is designed to provide reusable functionality without | ||
| 5 | //! being specific to Minecraft or configuration. | ||
| 6 | //! | ||
| 7 | //! # Submodules | ||
| 8 | //! - `fs`: File system utilities such as safe file creation, reading, and | ||
| 9 | //! writing. | ||
| 10 | //! - `sha1`: Functions to compute SHA-1 hashes for files and data integrity | ||
| 11 | //! checks. | ||
| 12 | |||
| 1 | pub mod fs; | 13 | pub mod fs; |
| 2 | pub mod sha1; | 14 | pub mod sha1; |
diff --git a/src/util/sha1.rs b/src/util/sha1.rs index c5f1021..6684963 100644 --- a/src/util/sha1.rs +++ b/src/util/sha1.rs | |||
| @@ -3,11 +3,12 @@ | |||
| 3 | use std::path::Path; | 3 | use std::path::Path; |
| 4 | 4 | ||
| 5 | use sha1::{Digest, Sha1}; | 5 | use sha1::{Digest, Sha1}; |
| 6 | use tokio::fs::read; | ||
| 6 | 7 | ||
| 7 | use crate::errors::McError; | 8 | use crate::errors::McError; |
| 8 | 9 | ||
| 9 | pub async fn sha1_hex(path: &Path) -> Result<String, McError> { | 10 | pub async fn sha1_hex(path: &Path) -> Result<String, McError> { |
| 10 | let data = tokio::fs::read(path).await?; | 11 | let data = read(path).await?; |
| 11 | let mut hasher = Sha1::new(); | 12 | let mut hasher = Sha1::new(); |
| 12 | hasher.update(&data); | 13 | hasher.update(&data); |
| 13 | Ok(format!("{:x}", hasher.finalize())) | 14 | Ok(format!("{:x}", hasher.finalize())) |
