diff --git a/src/deleter.rs b/src/deleter.rs index f7e6f6a..da738d7 100644 --- a/src/deleter.rs +++ b/src/deleter.rs @@ -46,8 +46,11 @@ pub(crate) async fn delete_by_id( async fn delete_content(file_id: &str, files_dir: &Path) -> Result<(), std::io::Error> { let path = files_dir.join(file_id); - if fs::remove_file(&path).await.is_ok() { - log::info!("delete file {}", file_id); + if fs::try_exists(&path).await? { + fs::remove_file(&path).await?; + log::info!("deleted file {}", file_id); + } else { + log::warn!("expiring file {} was missing from the filesystem", file_id); } Ok(()) } @@ -58,7 +61,7 @@ async fn wait_for_file_expiry(receiver: &mut Receiver<()>, db: &PgPool) { .fetch_one(db) .await .expect("could not fetch expiring files from database"); - let next_timeout: std::time::Duration = match valid_till.0 { + let next_timeout = match valid_till.0 { Some(valid_till) => (max( 0, valid_till.unix_timestamp() - OffsetDateTime::now_utc().unix_timestamp(),