mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 02:16:29 +03:00
fix: do not delete files if cannot read their metadata
This commit is contained in:
21
src/sql.rs
21
src/sql.rs
@@ -914,7 +914,15 @@ pub async fn remove_unused_files(context: &Context) -> Result<()> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(stats) = tokio::fs::metadata(entry.path()).await {
|
let Ok(stats) = tokio::fs::metadata(entry.path()).await else {
|
||||||
|
warn!(
|
||||||
|
context,
|
||||||
|
"Cannot get metadata for {}.",
|
||||||
|
entry.path().display()
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
if stats.is_dir() {
|
if stats.is_dir() {
|
||||||
if let Err(e) = tokio::fs::remove_dir(entry.path()).await {
|
if let Err(e) = tokio::fs::remove_dir(entry.path()).await {
|
||||||
// The dir could be created not by a user, but by a desktop
|
// The dir could be created not by a user, but by a desktop
|
||||||
@@ -928,16 +936,15 @@ pub async fn remove_unused_files(context: &Context) -> Result<()> {
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
unreferenced_count += 1;
|
unreferenced_count += 1;
|
||||||
let recently_created =
|
let recently_created = stats.created().is_ok_and(|t| t > keep_files_newer_than);
|
||||||
stats.created().is_ok_and(|t| t > keep_files_newer_than);
|
|
||||||
let recently_modified =
|
let recently_modified =
|
||||||
stats.modified().is_ok_and(|t| t > keep_files_newer_than);
|
stats.modified().is_ok_and(|t| t > keep_files_newer_than);
|
||||||
let recently_accessed =
|
let recently_accessed =
|
||||||
stats.accessed().is_ok_and(|t| t > keep_files_newer_than);
|
stats.accessed().is_ok_and(|t| t > keep_files_newer_than);
|
||||||
|
|
||||||
if p == blobdir
|
if p == blobdir && (recently_created || recently_modified || recently_accessed)
|
||||||
&& (recently_created || recently_modified || recently_accessed)
|
|
||||||
{
|
{
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
@@ -947,9 +954,7 @@ pub async fn remove_unused_files(context: &Context) -> Result<()> {
|
|||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
unreferenced_count += 1;
|
|
||||||
}
|
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
"Housekeeping: Deleting unreferenced file #{}: {:?}.",
|
"Housekeeping: Deleting unreferenced file #{}: {:?}.",
|
||||||
|
|||||||
Reference in New Issue
Block a user