From 94375b185fa4d920a1f76dc6cd9aefdab49a555e Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Tue, 13 Jul 2021 23:12:29 -0400 Subject: [PATCH] More debugging --- Cargo.toml | 6 +++--- src/cache/fs.rs | 35 +++++++++++++---------------------- src/config.rs | 23 ++++++++++++----------- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 71f9616..e8dbe44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,9 @@ description = "A MangaDex@Home implementation in Rust." repository = "https://github.com/edward-shen/mangadex-home-rs" [profile.release] -lto = true -codegen-units = 1 -# debug = 1 +# lto = true +# codegen-units = 1 +debug = 1 [dependencies] actix-web = { version = "4.0.0-beta.4", features = [ "rustls" ] } diff --git a/src/cache/fs.rs b/src/cache/fs.rs index a9dfabc..dcf51ed 100644 --- a/src/cache/fs.rs +++ b/src/cache/fs.rs @@ -106,21 +106,18 @@ async fn read_file( maybe_header = Some(*XNonce::from_slice(&nonce_bytes)); reader = Some(Box::pin(BufReader::new(EncryptedDiskReader::new( file, - XNonce::from_slice(&XNonce::from_slice(&nonce_bytes)), + XNonce::from_slice(XNonce::from_slice(&nonce_bytes)), key, )))); } parsed_metadata = if let Some(reader) = reader.as_mut() { - match reader.as_mut().metadata().await { - Ok(metadata) => { - debug!("Successfully parsed encrypted metadata"); - Some(metadata) - } - Err(_) => { - debug!("Failed to parse encrypted metadata"); - None - } + if let Ok(metadata) = reader.as_mut().metadata().await { + debug!("Successfully parsed encrypted metadata"); + Some(metadata) + } else { + debug!("Failed to parse encrypted metadata"); + None } } else { debug!("Failed to read encrypted data"); @@ -194,32 +191,26 @@ impl<'a, R: AsyncBufRead> Future for MetadataFuture<'a, R> { loop { let buf = match self.0.as_mut().poll_fill_buf(cx) { Poll::Ready(Ok(buffer)) => buffer, - Poll::Ready(Err(e)) => { - return Poll::Ready(Err(())); - } + Poll::Ready(Err(_)) => return Poll::Ready(Err(())), Poll::Pending => return Poll::Pending, }; if filled == buf.len() { return Poll::Ready(Err(())); - } else { - filled = buf.len(); } + filled = buf.len(); + let mut reader = serde_json::Deserializer::from_slice(buf).into_iter(); let (res, bytes_consumed) = match reader.next() { Some(Ok(metadata)) => (Poll::Ready(Ok(metadata)), reader.byte_offset()), - Some(Err(e)) if e.is_eof() => { - continue; - } - Some(Err(_)) | None => { - return Poll::Ready(Err(())); - } + Some(Err(e)) if e.is_eof() => continue, + Some(Err(_)) | None => return Poll::Ready(Err(())), }; // This needs to be outside the loop because we need to drop the // reader ref, since that depends on a mut self. - self.0.as_mut().consume(dbg!(bytes_consumed)); + self.0.as_mut().consume(bytes_consumed); return res; } } diff --git a/src/config.rs b/src/config.rs index 49320fe..de3510e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -102,17 +102,18 @@ impl Config { (2, _) => TracingLevelFilter::ERROR, (1, _) => TracingLevelFilter::WARN, // Use log level from file if no flags were provided to CLI - (0, 0) => file_extended_options - .logging_level - .map(|filter| match filter { - LevelFilter::Off => TracingLevelFilter::OFF, - LevelFilter::Error => TracingLevelFilter::ERROR, - LevelFilter::Warn => TracingLevelFilter::WARN, - LevelFilter::Info => TracingLevelFilter::INFO, - LevelFilter::Debug => TracingLevelFilter::DEBUG, - LevelFilter::Trace => TracingLevelFilter::TRACE, - }) - .unwrap_or(TracingLevelFilter::INFO), + (0, 0) => { + file_extended_options + .logging_level + .map_or(TracingLevelFilter::INFO, |filter| match filter { + LevelFilter::Off => TracingLevelFilter::OFF, + LevelFilter::Error => TracingLevelFilter::ERROR, + LevelFilter::Warn => TracingLevelFilter::WARN, + LevelFilter::Info => TracingLevelFilter::INFO, + LevelFilter::Debug => TracingLevelFilter::DEBUG, + LevelFilter::Trace => TracingLevelFilter::TRACE, + }) + } (_, 1) => TracingLevelFilter::DEBUG, (_, n) if n > 1 => TracingLevelFilter::TRACE, // compiler can't figure it out