forked from neri/datatrash
fix: panic when unable to delete files
This commit is contained in:
parent
6e5892a209
commit
aef400ff51
|
@ -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> {
|
async fn delete_content(file_id: &str, files_dir: &Path) -> Result<(), std::io::Error> {
|
||||||
let path = files_dir.join(file_id);
|
let path = files_dir.join(file_id);
|
||||||
if fs::remove_file(&path).await.is_ok() {
|
if fs::try_exists(&path).await? {
|
||||||
log::info!("delete file {}", file_id);
|
fs::remove_file(&path).await?;
|
||||||
|
log::info!("deleted file {}", file_id);
|
||||||
|
} else {
|
||||||
|
log::warn!("expiring file {} was missing from the filesystem", file_id);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -58,7 +61,7 @@ async fn wait_for_file_expiry(receiver: &mut Receiver<()>, db: &PgPool) {
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await
|
.await
|
||||||
.expect("could not fetch expiring files from database");
|
.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(
|
Some(valid_till) => (max(
|
||||||
0,
|
0,
|
||||||
valid_till.unix_timestamp() - OffsetDateTime::now_utc().unix_timestamp(),
|
valid_till.unix_timestamp() - OffsetDateTime::now_utc().unix_timestamp(),
|
||||||
|
|
Loading…
Reference in New Issue