diff options
| author | 2025-01-22 03:59:51 -0600 | |
|---|---|---|
| committer | 2025-01-22 03:59:51 -0600 | |
| commit | 31207679094b378a2d4b35eb310f679960d6205f (patch) | |
| tree | 2f750cf006ad1e5ff1bdaed908d7b6f621d018a9 /src/util.rs | |
| parent | get started on downloading JREs (diff) | |
wip: jre download stuff
Diffstat (limited to 'src/util.rs')
| -rw-r--r-- | src/util.rs | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/util.rs b/src/util.rs index 1184a83..b7b7c6d 100644 --- a/src/util.rs +++ b/src/util.rs @@ -7,7 +7,6 @@ use sha1_smol::{Digest, Sha1}; use tokio::fs::File; use tokio::{fs, io}; use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use crate::launcher::LaunchError; #[derive(Debug)] pub enum IntegrityError { @@ -69,8 +68,15 @@ pub async fn verify_file(path: impl AsRef<Path>, expect_size: Option<usize>, exp let path = path.as_ref(); if expect_size.is_none() && expect_sha1.is_none() { - debug!("No size or sha1 for {}, have to assume it's good.", path.display()); - return Ok(()); + return match path.metadata() { + Ok(_) => { + debug!("No size or sha1 for {}, have to assume it's good.", path.display()); + Ok(()) + }, + Err(e) => { + Err(FileVerifyError::Open(path.to_path_buf(), e)) + } + } } let mut file = File::open(path).await.map_err(|e| FileVerifyError::Open(path.to_owned(), e))?; @@ -145,19 +151,21 @@ impl Error for EnsureFileError { } } -pub async fn ensure_file(path: impl AsRef<Path>, url: Option<&str>, expect_size: Option<usize>, expect_sha1: Option<Digest>, online: bool) -> Result<bool, EnsureFileError> { +pub async fn ensure_file(path: impl AsRef<Path>, url: Option<&str>, expect_size: Option<usize>, expect_sha1: Option<Digest>, online: bool, force_download: bool) -> Result<bool, EnsureFileError> { let path = path.as_ref(); - match verify_file(path, expect_size, expect_sha1).await { - Ok(_) => { - info!("File {} exists and integrity matches. Skipping.", path.display()); - return Ok(false); - }, - Err(FileVerifyError::Open(_, e)) if e.kind() == ErrorKind::NotFound => (), - Err(FileVerifyError::Integrity(_, e)) => - info!("File {} on disk failed integrity check: {}", path.display(), e), - Err(FileVerifyError::Open(_, e)) | Err(FileVerifyError::Read(_, e)) => - return Err(EnsureFileError::IO { what: "verifying fileon disk", error: e }) + if !force_download { + match verify_file(path, expect_size, expect_sha1).await { + Ok(_) => { + info!("File {} exists and integrity matches. Skipping.", path.display()); + return Ok(false); + }, + Err(FileVerifyError::Open(_, e)) if e.kind() == ErrorKind::NotFound => (), + Err(FileVerifyError::Integrity(_, e)) => + info!("File {} on disk failed integrity check: {}", path.display(), e), + Err(FileVerifyError::Open(_, e)) | Err(FileVerifyError::Read(_, e)) => + return Err(EnsureFileError::IO { what: "verifying fileon disk", error: e }) + } } if !online { @@ -273,6 +281,7 @@ impl AsJavaPath for Path { #[cfg(test)] mod tests { + #[allow(unused_imports)] use super::*; #[test] |
