New player
All checks were successful
Publish Server Image / build-and-push-image (push) Successful in 2m7s

This commit is contained in:
2026-03-18 02:44:59 +00:00
parent d5068aaa33
commit ff3ad15b95
11 changed files with 1970 additions and 0 deletions

View File

@@ -53,9 +53,46 @@ async fn scan_inbox(state: &Arc<AppState>) -> anyhow::Result<usize> {
}
}
// Clean up empty directories in inbox
if count > 0 {
cleanup_empty_dirs(&state.config.inbox_dir).await;
}
Ok(count)
}
/// Recursively remove empty directories inside the inbox.
/// Does not remove the inbox root itself.
async fn cleanup_empty_dirs(dir: &std::path::Path) -> bool {
let mut entries = match tokio::fs::read_dir(dir).await {
Ok(e) => e,
Err(_) => return false,
};
let mut is_empty = true;
while let Ok(Some(entry)) = entries.next_entry().await {
let ft = match entry.file_type().await {
Ok(ft) => ft,
Err(_) => { is_empty = false; continue; }
};
if ft.is_dir() {
let child_empty = Box::pin(cleanup_empty_dirs(&entry.path())).await;
if child_empty {
if let Err(e) = tokio::fs::remove_dir(&entry.path()).await {
tracing::warn!(?e, path = ?entry.path(), "Failed to remove empty directory");
} else {
tracing::info!(path = ?entry.path(), "Removed empty inbox directory");
}
} else {
is_empty = false;
}
} else {
is_empty = false;
}
}
is_empty
}
/// Recursively collect all audio files and image files under a directory.
async fn collect_files(dir: &std::path::Path, audio: &mut Vec<std::path::PathBuf>, images: &mut Vec<std::path::PathBuf>) -> anyhow::Result<()> {
let mut entries = tokio::fs::read_dir(dir).await?;