From 3ff2944f77fd4e2676231c71b9e7b2a910d1239f Mon Sep 17 00:00:00 2001 From: DecDuck Date: Sat, 20 Dec 2025 18:35:24 +1100 Subject: [PATCH] fix: manifest generation no actually this time --- libraries/droplet/Cargo.lock | 2 +- libraries/droplet/Cargo.toml | 2 +- libraries/droplet/src/main.rs | 42 ++++++++++++++++++++++++++----- libraries/droplet/src/manifest.rs | 8 +++--- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/libraries/droplet/Cargo.lock b/libraries/droplet/Cargo.lock index 803b4f4c..e6dcc97a 100644 --- a/libraries/droplet/Cargo.lock +++ b/libraries/droplet/Cargo.lock @@ -219,7 +219,7 @@ dependencies = [ [[package]] name = "droplet-rs" -version = "0.13.0" +version = "0.14.0" dependencies = [ "anyhow", "async-trait", diff --git a/libraries/droplet/Cargo.toml b/libraries/droplet/Cargo.toml index 18ef4aab..4e609c44 100644 --- a/libraries/droplet/Cargo.toml +++ b/libraries/droplet/Cargo.toml @@ -2,7 +2,7 @@ edition = "2021" authors = ["Drop-OSS"] name = "droplet-rs" -version = "0.13.0" +version = "0.14.0" license = "AGPL-3.0-only" description = "Droplet is a `napi.rs` Rust/Node.js package full of high-performance and low-level utils for Drop" diff --git a/libraries/droplet/src/main.rs b/libraries/droplet/src/main.rs index d098a419..76036a45 100644 --- a/libraries/droplet/src/main.rs +++ b/libraries/droplet/src/main.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::{os::unix::fs::MetadataExt, path::PathBuf}; use droplet_rs::manifest::generate_manifest_rusty; use serde_json::json; @@ -6,18 +6,48 @@ use tokio::runtime::Handle; #[tokio::main] pub async fn main() { + let target_dir = + PathBuf::from("/home/decduck/.local/share/Steam/steamapps/common/BloonsTD6"); let metrics = Handle::current().metrics(); println!("using {} workers", metrics.num_workers()); let manifest = generate_manifest_rusty( - &PathBuf::from("/home/decduck/.local/share/Steam/steamapps/common/Savage Resurrection"), - |progress| { - println!("PROGRESS: {}", progress) - }, + &target_dir, + |progress| println!("PROGRESS: {}", progress), |message| { println!("{}", message); }, ) .await .unwrap(); - tokio::fs::write("./manifst.json", json!(manifest).to_string()).await.expect("failed to write manifest"); + + // Sanity checks + for (_, chunk_data) in manifest.chunks { + for file in chunk_data.files { + let path = target_dir.join(file.filename); + if !path.exists() { + panic!("{} doesn't exist", path.display()); + } + + let metadata = path.metadata().expect("failed to fetch metadata"); + let file_size = metadata.size(); + if file.start > file_size as usize { + panic!( + "start for {} doesn't make sense: start: {}, size: {}", + path.display(), + file.start, + file_size + ); + } + + let end_position = file.start + file.length; + if end_position > file_size as usize { + panic!( + "end for {} doesn't make sense: end: {}, size: {}", + path.display(), + end_position, + file_size + ); + } + } + } } diff --git a/libraries/droplet/src/manifest.rs b/libraries/droplet/src/manifest.rs index 29c56dd1..7b66f306 100644 --- a/libraries/droplet/src/manifest.rs +++ b/libraries/droplet/src/manifest.rs @@ -56,7 +56,7 @@ pub async fn generate_manifest_rusty( let required_single_file = backend.require_whole_files(); let mut files = backend.list_files().await?; - files.sort_by(|a, b| a.size.cmp(&b.size)); + files.sort_by(|a, b| b.size.cmp(&a.size)); // Filepath to chunk data let mut chunks: Vec> = Vec::new(); let mut current_chunk: Vec<(VersionFile, u64, u64)> = Vec::new(); @@ -91,7 +91,7 @@ pub async fn generate_manifest_rusty( for version_file in files { let current_size = current_chunk.iter().map(|v| v.2).sum::(); - if version_file.size + current_size < CHUNK_SIZE + WIGGLE { + if version_file.size + current_size < CHUNK_SIZE { let size = version_file.size; current_chunk.push((version_file, 0, size)); @@ -101,18 +101,18 @@ pub async fn generate_manifest_rusty( // Fill up current chunk let remaining = CHUNK_SIZE - current_size; current_chunk.push((version_file.clone(), 0, remaining)); - chunks.push(std::mem::take(&mut current_chunk)); + chunks.push(std::mem::replace(&mut current_chunk, Vec::new())); // This is our offset in our current file let mut offset = remaining; while offset < version_file.size { let length = CHUNK_SIZE.min(version_file.size - offset); - offset += length; if length == CHUNK_SIZE { chunks.push(vec![(version_file.clone(), offset, length)]); } else { current_chunk.push((version_file.clone(), offset, length)); } + offset += length; } } }