fix: harden media cleanup retries

Retry best-effort yt-dlp media artifact cleanup before giving up so Windows file-handle release timing does not leave stale partials behind.

Also adjusts the app sidebar panel contrast and border tokens.
This commit is contained in:
NimBold
2026-07-08 02:52:23 +03:30
parent 6b5384f261
commit 800b94f9c0
2 changed files with 45 additions and 7 deletions
+41 -3
View File
@@ -927,6 +927,44 @@ async fn cleanup_media_processing_artifacts(out_path: &std::path::Path) {
cleanup_media_artifacts(out_path, true).await; cleanup_media_artifacts(out_path, true).await;
} }
async fn remove_file_best_effort_with_retry(path: &std::path::Path) {
for attempt in 0..=5 {
match tokio::fs::remove_file(path).await {
Ok(()) => return,
Err(error) if error.kind() == std::io::ErrorKind::NotFound => return,
Err(error) if attempt == 5 => {
log::warn!(
"failed to remove media artifact '{}' after retries: {}",
path.display(),
error
);
}
Err(_) => {
tokio::time::sleep(std::time::Duration::from_millis(200)).await;
}
}
}
}
fn remove_file_best_effort_with_retry_blocking(path: &std::path::Path) {
for attempt in 0..=5 {
match std::fs::remove_file(path) {
Ok(()) => return,
Err(error) if error.kind() == std::io::ErrorKind::NotFound => return,
Err(error) if attempt == 5 => {
log::warn!(
"failed to remove temporary media metadata '{}' after retries: {}",
path.display(),
error
);
}
Err(_) => {
std::thread::sleep(std::time::Duration::from_millis(200));
}
}
}
}
async fn cleanup_media_artifacts(out_path: &std::path::Path, remove_primary: bool) { async fn cleanup_media_artifacts(out_path: &std::path::Path, remove_primary: bool) {
let Some(parent) = out_path.parent() else { let Some(parent) = out_path.parent() else {
return; return;
@@ -940,7 +978,7 @@ async fn cleanup_media_artifacts(out_path: &std::path::Path, remove_primary: boo
.unwrap_or(base_name); .unwrap_or(base_name);
if remove_primary { if remove_primary {
let _ = tokio::fs::remove_file(out_path).await; remove_file_best_effort_with_retry(out_path).await;
} }
let Ok(mut entries) = tokio::fs::read_dir(parent).await else { let Ok(mut entries) = tokio::fs::read_dir(parent).await else {
@@ -968,7 +1006,7 @@ async fn cleanup_media_artifacts(out_path: &std::path::Path, remove_primary: boo
|| name.contains(".tmp") || name.contains(".tmp")
|| yt_dlp_format_fragment; || yt_dlp_format_fragment;
if looks_like_media_temp { if looks_like_media_temp {
let _ = tokio::fs::remove_file(path).await; remove_file_best_effort_with_retry(&path).await;
} }
} }
} }
@@ -2856,7 +2894,7 @@ pub(crate) async fn start_media_download_internal(
impl Drop for CleanupPath { impl Drop for CleanupPath {
fn drop(&mut self) { fn drop(&mut self) {
if let Some(path) = self.0.take() { if let Some(path) = self.0.take() {
let _ = std::fs::remove_file(path); remove_file_best_effort_with_retry_blocking(&path);
} }
} }
} }
+4 -4
View File
@@ -21,7 +21,7 @@
--surface-overlay: 0 0% 100% / 0.95; --surface-overlay: 0 0% 100% / 0.95;
--shadow-color: 220 10% 20% / 0.1; --shadow-color: 220 10% 20% / 0.1;
--sidebar-shell-bg: 0 0% 92%; --sidebar-shell-bg: 0 0% 92%;
--sidebar-panel-bg: 0 0% 95%; --sidebar-panel-bg: 0 0% 93%;
--workspace-bg: 0 0% 98%; --workspace-bg: 0 0% 98%;
--statusbar-bg: 0 0% 96%; --statusbar-bg: 0 0% 96%;
--status-completed: 136 62% 48%; --status-completed: 136 62% 48%;
@@ -30,7 +30,7 @@
--status-failed: 0 62% 58%; --status-failed: 0 62% 58%;
--status-queued: 38 92% 50%; --status-queued: 38 92% 50%;
--status-retrying: 50 100% 50%; --status-retrying: 50 100% 50%;
--sidebar-border: 0 0% 0% / 0.12; --sidebar-border: 0 0% 0% / 0.18;
--sidebar-hover: 0 0% 0% / 0.06; --sidebar-hover: 0 0% 0% / 0.06;
--download-header-height: 32px; --download-header-height: 32px;
--download-row-height: 32px; --download-row-height: 32px;
@@ -63,10 +63,10 @@
--surface-overlay: 0 0% 100% / 0.95; --surface-overlay: 0 0% 100% / 0.95;
--shadow-color: 220 10% 20% / 0.1; --shadow-color: 220 10% 20% / 0.1;
--sidebar-shell-bg: 0 0% 92%; --sidebar-shell-bg: 0 0% 92%;
--sidebar-panel-bg: 0 0% 95%; --sidebar-panel-bg: 0 0% 93%;
--workspace-bg: 0 0% 98%; --workspace-bg: 0 0% 98%;
--statusbar-bg: 0 0% 96%; --statusbar-bg: 0 0% 96%;
--sidebar-border: 0 0% 0% / 0.12; --sidebar-border: 0 0% 0% / 0.18;
--sidebar-hover: 0 0% 0% / 0.06; --sidebar-hover: 0 0% 0% / 0.06;
} }