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 {
return time >= self.get_expire();
time >= self.get_expire()
}
pub fn as_string(&self) -> String {
@ -87,7 +87,7 @@ pub struct Expiration(u64);
impl PartialOrd for Expiration {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
// 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)]
enum UploadResponse {
Data(String),
Redirect(Redirect),
Redirect(Box<Redirect>),
}
#[derive(Debug, Serialize)]
@ -144,7 +144,7 @@ async fn post_upload(
.unwrap_or_default(),
)
} else {
UploadResponse::Redirect(Redirect::to("/?error=invalid%20token"))
UploadResponse::Redirect(Box::new(Redirect::to("/?error=invalid%20token")))
}
} else {
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(),
)
} else {
UploadResponse::Redirect(Redirect::to(""))
UploadResponse::Redirect(Box::new(Redirect::to("")))
}
}
Err(e) => UploadResponse::Data(
@ -241,8 +241,15 @@ fn rocket() -> _ {
fn expire_job(expire_basedir: PathBuf, expire_queue: ExpireQueue) -> JoinHandle<()> {
spawn(move || {
for dir_entry in read_dir(&expire_basedir).expect("Failed to list base directory") {
if let Ok(entry) = dir_entry {
let entries = match read_dir(&expire_basedir) {
Ok(entries) => entries,
Err(e) => {
eprintln!("Failed to list base directory: {e:#}");
return;
}
};
for entry in entries.flatten() {
if let Some(upload_id) = entry
.file_name()
.to_str()
@ -251,7 +258,6 @@ fn expire_job(expire_basedir: PathBuf, expire_queue: ExpireQueue) -> JoinHandle<
expire_queue.push(upload_id);
}
}
}
loop {
for expired in expire_queue.get_expired(now()) {
@ -266,7 +272,9 @@ fn expire_job(expire_basedir: PathBuf, expire_queue: ExpireQueue) -> JoinHandle<
fn filename_ext(name: &FileName) -> Option<&str> {
let raw = name.dangerous_unsafe_unsanitized_raw().as_str();
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)
} else {