cargo clippy and fmt

This commit is contained in:
xenofem 2022-04-28 05:18:35 -04:00
parent 127d7e9c67
commit bda6da33e8
6 changed files with 129 additions and 68 deletions

View file

@ -1,4 +1,12 @@
use std::{cmp, fs::File, future::Future, io::{self, Write}, path::PathBuf, pin::Pin, task::{Context, Poll, Waker}};
use std::{
cmp,
fs::File,
future::Future,
io::{self, Write},
path::PathBuf,
pin::Pin,
task::{Context, Poll, Waker},
};
use actix::Addr;
use actix_web::error::{Error, ErrorInternalServerError};
@ -53,7 +61,6 @@ impl Write for LiveFileWriter {
}
}
// This implementation of a file responder is copied pretty directly
// from actix-files with some tweaks
@ -104,13 +111,19 @@ async fn live_file_reader_callback(
use io::{Read as _, Seek as _};
let res = actix_web::web::block(move || {
trace!("reading up to {} bytes of file starting at {}", max_bytes, offset);
trace!(
"reading up to {} bytes of file starting at {}",
max_bytes,
offset
);
let mut buf = Vec::with_capacity(max_bytes);
file.seek(io::SeekFrom::Start(offset))?;
let n_bytes = std::io::Read::by_ref(&mut file).take(max_bytes as u64).read_to_end(&mut buf)?;
let n_bytes = std::io::Read::by_ref(&mut file)
.take(max_bytes as u64)
.read_to_end(&mut buf)?;
trace!("got {} bytes from file", n_bytes);
if n_bytes == 0 {
Err(io::Error::from(io::ErrorKind::UnexpectedEof))
@ -141,12 +154,14 @@ where
if size == counter {
Poll::Ready(None)
} else {
let inner_file = file
.take()
.expect("LiveFileReader polled after completion");
let inner_file = file.take().expect("LiveFileReader polled after completion");
if offset >= *this.available_file_size {
trace!("offset {} has reached available file size {}, updating metadata", offset, this.available_file_size);
trace!(
"offset {} has reached available file size {}, updating metadata",
offset,
this.available_file_size
);
// If we've hit the end of what was available
// last time we checked, check again
*this.available_file_size = match inner_file.metadata() {
@ -165,15 +180,25 @@ where
if let Ok(()) = addr.try_send(WakerMessage(cx.waker().clone())) {
return Poll::Pending;
} else {
return Poll::Ready(Some(Err(ErrorInternalServerError("Failed to contact file upload actor"))));
return Poll::Ready(Some(Err(ErrorInternalServerError(
"Failed to contact file upload actor",
))));
}
} else {
return Poll::Ready(Some(Err(ErrorInternalServerError("File upload was not completed"))));
return Poll::Ready(Some(Err(ErrorInternalServerError(
"File upload was not completed",
))));
}
}
}
let max_bytes = cmp::min(65_536, cmp::min(size.saturating_sub(counter), this.available_file_size.saturating_sub(offset))) as usize;
let max_bytes = cmp::min(
65_536,
cmp::min(
size.saturating_sub(counter),
this.available_file_size.saturating_sub(offset),
),
) as usize;
let fut = (this.callback)(inner_file, offset, max_bytes);