mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-13 00:02:41 +10:00
copy direct to disk
This commit is contained in:
@ -37,7 +37,9 @@ pub fn download_game_chunk(ctx: DropDownloadContext) {
|
||||
.expect("Failed to seek to file offset");
|
||||
}
|
||||
|
||||
let mut stream = BufWriter::with_capacity(1024 * 1024, file);
|
||||
// let mut stream = BufWriter::with_capacity(1024, file);
|
||||
|
||||
response.copy_to(&mut stream).unwrap();
|
||||
response.copy_to(&mut file).unwrap();
|
||||
|
||||
// stream.flush().unwrap();
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ use std::fs::{create_dir_all, File};
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@ -138,6 +139,7 @@ pub fn generate_job_contexts(
|
||||
let mut contexts = Vec::new();
|
||||
let base_path = DATA_ROOT_DIR.join("games").join(game_id.clone()).clone();
|
||||
create_dir_all(base_path.clone()).unwrap();
|
||||
info!("Generating contexts");
|
||||
for (raw_path, chunk) in manifest {
|
||||
let path = base_path.join(Path::new(raw_path));
|
||||
|
||||
@ -147,7 +149,7 @@ pub fn generate_job_contexts(
|
||||
let file = File::create(path.clone()).unwrap();
|
||||
let mut running_offset = 0;
|
||||
|
||||
for i in 0..chunk.ids.len() {
|
||||
for (i, length) in chunk.lengths.iter().enumerate() {
|
||||
contexts.push(DropDownloadContext {
|
||||
file_name: raw_path.to_string(),
|
||||
version: version.to_string(),
|
||||
@ -156,11 +158,12 @@ pub fn generate_job_contexts(
|
||||
game_id: game_id.to_string(),
|
||||
path: path.clone(),
|
||||
});
|
||||
running_offset += chunk.lengths[i] as u64;
|
||||
running_offset += *length as u64;
|
||||
}
|
||||
|
||||
fallocate(file, FallocateFlags::empty(), 0, running_offset);
|
||||
fallocate(file, FallocateFlags::empty(), 0, running_offset).unwrap();
|
||||
}
|
||||
info!("Finished generating");
|
||||
contexts
|
||||
}
|
||||
|
||||
@ -188,8 +191,7 @@ pub async fn start_game_download(
|
||||
let contexts = generate_job_contexts(&local_manifest, game_version.clone(), game_id);
|
||||
|
||||
download_manager
|
||||
.begin_download(max_threads, contexts)
|
||||
.unwrap();
|
||||
.begin_download(max_threads, contexts)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ where T: Send + Sync
|
||||
}
|
||||
pub fn run_contexts_parallel(&self, contexts: Vec<T>, max_threads: usize) {
|
||||
let threads = ThreadPoolBuilder::new()
|
||||
// If max_threads == 0, then the limit will be determined
|
||||
// If max_threads == 0, then the limit will be determined
|
||||
// by Rayon's internal RAYON_NUM_THREADS
|
||||
.num_threads(max_threads)
|
||||
.build()
|
||||
|
||||
Reference in New Issue
Block a user