fix: panic when unable to delete files

This commit is contained in:
neri 2023-05-24 10:14:16 +02:00
parent 6e5892a209
commit aef400ff51
1 changed files with 6 additions and 3 deletions

View File

@ -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(),