Skip to content

Commit c267d46

Browse files
committed
Reworking handlers to avoid returning errors
1 parent dc95b1d commit c267d46

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

rust/src/standard/download.rs renamed to rust/src/download.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Parallel download implementation for standard installer.
1+
//! Parallel download implementation.
22
//!
33
//! Partially inspired by: https://patshaughnessy.net/2020/1/20/downloading-100000-files-using-async-rust
44
@@ -17,9 +17,12 @@ use tokio::task::JoinSet;
1717
use tokio::sync::mpsc;
1818
use tokio::fs::File;
1919

20-
use crate::http;
2120

22-
use super::{serde, Event, Handler, Installer, Result, Error};
21+
/// A list of pending download that can be all downloaded at once.
22+
#[derive(Debug)]
23+
pub struct DownloadList {
24+
inner: Vec<Download>,
25+
}
2326

2427

2528
/// Bulk download blocking entrypoint.
@@ -84,7 +87,7 @@ pub async fn download_many(
8487
})?;
8588

8689
// Initialize the HTTP(S) client.
87-
let client = http::builder()
90+
let client = crate::http::builder()
8891
.build()
8992
.unwrap(); // FIXME:
9093

@@ -253,6 +256,10 @@ async fn download_core(
253256

254257
}
255258

259+
pub trait DownloadWatcher {
260+
261+
}
262+
256263
/// A download entry that can be delayed until a call to [`Handler::flush_download`].
257264
/// This download object borrows the URL and file path.
258265
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -291,17 +298,17 @@ impl DownloadSource {
291298

292299
}
293300

294-
impl<'a> From<&'a serde::Download> for DownloadSource {
301+
// impl<'a> From<&'a serde::Download> for DownloadSource {
295302

296-
fn from(serde: &'a serde::Download) -> Self {
297-
Self {
298-
url: serde.url.clone().into(),
299-
size: serde.size,
300-
sha1: serde.sha1.as_deref().copied(),
301-
}
302-
}
303+
// fn from(serde: &'a serde::Download) -> Self {
304+
// Self {
305+
// url: serde.url.clone().into(),
306+
// size: serde.size,
307+
// sha1: serde.sha1.as_deref().copied(),
308+
// }
309+
// }
303310

304-
}
311+
// }
305312

306313
#[derive(thiserror::Error, Debug)]
307314
pub enum DownloadError {

rust/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
pub mod gav;
55
pub mod path;
66
pub mod http;
7+
pub mod download;
78

89
pub mod standard;
910
pub mod mojang;

rust/src/mojang/manifest.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Optionally cached Mojang manifest.
22
3+
use std::io::{self, BufReader};
34
use std::path::PathBuf;
45
use std::fs::File;
56

6-
use crate::standard::{Result, Error};
77
use super::serde;
88

99

@@ -32,21 +32,29 @@ impl MojangManifest {
3232
}
3333
}
3434

35-
pub fn get(&mut self) -> &serde::MojangManifest {
35+
pub fn get(&mut self) -> io::Result<&serde::MojangManifest> {
3636

3737
if let Some(data) = &self.data {
38-
return data;
38+
return Ok(data);
3939
}
4040

4141
if let Some(cache_file) = self.cache_file.as_deref() {
42+
43+
let cache_reader = match File::open(cache_file) {
44+
Ok(reader) => BufReader::new(reader),
45+
Err(e) if e.kind() == io::ErrorKind::NotFound
46+
}
4247

43-
// let file = File::open(cache_file)
44-
// .map_err(|e| )
48+
self.datamatch serde_json::from_reader(BufReader::new(File::open(cache_file)?)) {
49+
Ok(obj) => obj
50+
}
4551

4652
}
4753

4854
todo!()
4955

5056
}
5157

58+
fn
59+
5260
}

rust/src/standard/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Standard installation procedure.
22
33
pub mod serde;
4-
mod download;
54

65
use std::io::{self, BufReader, Seek, SeekFrom};
76
use std::collections::{HashMap, HashSet};
@@ -14,8 +13,6 @@ use sha1::{Digest, Sha1};
1413
use crate::path::PathExt;
1514
use crate::gav::Gav;
1615

17-
pub use self::download::{Download, DownloadSource, DownloadError};
18-
1916

2017
/// Base URL for downloading game's assets.
2118
const RESOURCES_URL: &str = "https://resources.download.minecraft.net/";

0 commit comments

Comments
 (0)