mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 06:56:29 +03:00
fix: do not delete files if cannot read their metadata
This commit is contained in:
65
src/sql.rs
65
src/sql.rs
@@ -914,42 +914,47 @@ 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 {
|
||||||
if stats.is_dir() {
|
warn!(
|
||||||
if let Err(e) = tokio::fs::remove_dir(entry.path()).await {
|
context,
|
||||||
// The dir could be created not by a user, but by a desktop
|
"Cannot get metadata for {}.",
|
||||||
// environment f.e. So, no warning.
|
entry.path().display()
|
||||||
info!(
|
);
|
||||||
context,
|
continue;
|
||||||
"Housekeeping: Cannot rmdir {}: {:#}.",
|
};
|
||||||
entry.path().display(),
|
|
||||||
e
|
|
||||||
);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
unreferenced_count += 1;
|
|
||||||
let recently_created =
|
|
||||||
stats.created().is_ok_and(|t| t > keep_files_newer_than);
|
|
||||||
let recently_modified =
|
|
||||||
stats.modified().is_ok_and(|t| t > keep_files_newer_than);
|
|
||||||
let recently_accessed =
|
|
||||||
stats.accessed().is_ok_and(|t| t > keep_files_newer_than);
|
|
||||||
|
|
||||||
if p == blobdir
|
if stats.is_dir() {
|
||||||
&& (recently_created || recently_modified || recently_accessed)
|
if let Err(e) = tokio::fs::remove_dir(entry.path()).await {
|
||||||
{
|
// The dir could be created not by a user, but by a desktop
|
||||||
|
// environment f.e. So, no warning.
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
"Housekeeping: Keeping new unreferenced file #{}: {:?}.",
|
"Housekeeping: Cannot rmdir {}: {:#}.",
|
||||||
unreferenced_count,
|
entry.path().display(),
|
||||||
entry.file_name(),
|
e
|
||||||
);
|
);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
} else {
|
continue;
|
||||||
unreferenced_count += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unreferenced_count += 1;
|
||||||
|
let recently_created = stats.created().is_ok_and(|t| t > keep_files_newer_than);
|
||||||
|
let recently_modified =
|
||||||
|
stats.modified().is_ok_and(|t| t > keep_files_newer_than);
|
||||||
|
let recently_accessed =
|
||||||
|
stats.accessed().is_ok_and(|t| t > keep_files_newer_than);
|
||||||
|
|
||||||
|
if p == blobdir && (recently_created || recently_modified || recently_accessed)
|
||||||
|
{
|
||||||
|
info!(
|
||||||
|
context,
|
||||||
|
"Housekeeping: Keeping new unreferenced file #{}: {:?}.",
|
||||||
|
unreferenced_count,
|
||||||
|
entry.file_name(),
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
"Housekeeping: Deleting unreferenced file #{}: {:?}.",
|
"Housekeeping: Deleting unreferenced file #{}: {:?}.",
|
||||||
|
|||||||
Reference in New Issue
Block a user