1
0
Fork 0
mirror of https://codeberg.org/icewind/shelve.git synced 2026-06-03 12:04:09 +02:00

clippy fixes

This commit is contained in:
Robin Appelman 2024-01-06 23:02:29 +01:00
commit 7cb6ab9d61
2 changed files with 23 additions and 15 deletions

View file

@ -61,7 +61,7 @@ impl UploadId {
} }
pub fn is_expired(&self, time: u64) -> bool { pub fn is_expired(&self, time: u64) -> bool {
return time >= self.get_expire(); time >= self.get_expire()
} }
pub fn as_string(&self) -> String { pub fn as_string(&self) -> String {
@ -87,7 +87,7 @@ pub struct Expiration(u64);
impl PartialOrd for Expiration { impl PartialOrd for Expiration {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
// reverse the order so sort nearest expiration time first // reverse the order so sort nearest expiration time first
other.0.partial_cmp(&self.0) Some(other.0.cmp(&self.0))
} }
} }

View file

@ -103,7 +103,7 @@ async fn put_upload(
#[derive(Debug, Responder)] #[derive(Debug, Responder)]
enum UploadResponse { enum UploadResponse {
Data(String), Data(String),
Redirect(Redirect), Redirect(Box<Redirect>),
} }
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
@ -144,7 +144,7 @@ async fn post_upload(
.unwrap_or_default(), .unwrap_or_default(),
) )
} else { } else {
UploadResponse::Redirect(Redirect::to("/?error=invalid%20token")) UploadResponse::Redirect(Box::new(Redirect::to("/?error=invalid%20token")))
} }
} else { } else {
match try_join_all(data.files.into_iter().filter(|file| file.len() > 0).map( match try_join_all(data.files.into_iter().filter(|file| file.len() > 0).map(
@ -177,7 +177,7 @@ async fn post_upload(
.unwrap_or_default(), .unwrap_or_default(),
) )
} else { } else {
UploadResponse::Redirect(Redirect::to("")) UploadResponse::Redirect(Box::new(Redirect::to("")))
} }
} }
Err(e) => UploadResponse::Data( Err(e) => UploadResponse::Data(
@ -241,15 +241,21 @@ fn rocket() -> _ {
fn expire_job(expire_basedir: PathBuf, expire_queue: ExpireQueue) -> JoinHandle<()> { fn expire_job(expire_basedir: PathBuf, expire_queue: ExpireQueue) -> JoinHandle<()> {
spawn(move || { spawn(move || {
for dir_entry in read_dir(&expire_basedir).expect("Failed to list base directory") { let entries = match read_dir(&expire_basedir) {
if let Ok(entry) = dir_entry { Ok(entries) => entries,
if let Some(upload_id) = entry Err(e) => {
.file_name() eprintln!("Failed to list base directory: {e:#}");
.to_str() return;
.and_then(|s| UploadId::new(s).ok()) }
{ };
expire_queue.push(upload_id);
} for entry in entries.flatten() {
if let Some(upload_id) = entry
.file_name()
.to_str()
.and_then(|s| UploadId::new(s).ok())
{
expire_queue.push(upload_id);
} }
} }
@ -266,7 +272,9 @@ fn expire_job(expire_basedir: PathBuf, expire_queue: ExpireQueue) -> JoinHandle<
fn filename_ext(name: &FileName) -> Option<&str> { fn filename_ext(name: &FileName) -> Option<&str> {
let raw = name.dangerous_unsafe_unsanitized_raw().as_str(); let raw = name.dangerous_unsafe_unsanitized_raw().as_str();
let (name, ext) = raw.split_once('.')?; let (name, ext) = raw.split_once('.')?;
if name.len() > 0 && ext.len() < 8 && ext.chars().all(|c| c.is_ascii_alphanumeric() || c == '.') if !name.is_empty()
&& ext.len() < 8
&& ext.chars().all(|c| c.is_ascii_alphanumeric() || c == '.')
{ {
Some(ext) Some(ext)
} else { } else {