aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/fs.rs4
-rw-r--r--src/util/mod.rs12
-rw-r--r--src/util/sha1.rs3
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
3use std::path::Path; 3use std::path::Path;
4 4
5use tokio::fs::remove_file;
6
5use crate::errors::McError; 7use crate::errors::McError;
6 8
7pub async fn remove_if_exists(path: &Path) -> Result<(), McError> { 9pub 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
1pub mod fs; 13pub mod fs;
2pub mod sha1; 14pub 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 @@
3use std::path::Path; 3use std::path::Path;
4 4
5use sha1::{Digest, Sha1}; 5use sha1::{Digest, Sha1};
6use tokio::fs::read;
6 7
7use crate::errors::McError; 8use crate::errors::McError;
8 9
9pub async fn sha1_hex(path: &Path) -> Result<String, McError> { 10pub 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()))