diff --git a/.changeset/android-media-upload.md b/.changeset/android-media-upload.md index 98ab1cab3..69a316d2b 100644 --- a/.changeset/android-media-upload.md +++ b/.changeset/android-media-upload.md @@ -2,4 +2,4 @@ default: patch --- -stream android media uploads to fix OOM and show progress and diverse input improvement. +stream android media uploads to fix OOM and show progress and diverse input improvement. also purge orphaned upload temp files on startup. diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index ebed3a2a7..9aa3058a2 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -268,6 +268,8 @@ pub fn run() { network::media_protocol::respond, ) .setup(|app| { + network::native_upload::cleanup_uploads(app.handle()); + #[cfg(any(target_os = "linux", all(debug_assertions, windows)))] { use tauri_plugin_deep_link::DeepLinkExt; diff --git a/src-tauri/src/network/native_upload.rs b/src-tauri/src/network/native_upload.rs index 60e5ba785..9e92e7487 100644 --- a/src-tauri/src/network/native_upload.rs +++ b/src-tauri/src/network/native_upload.rs @@ -63,6 +63,17 @@ fn upload_temp_path(app: &AppHandle, request_id: &str) -> Result< Ok(dir.join(request_id)) } +/// Drop leftover upload temp files from a session that ended without running +/// the normal cleanup (crash, OS kill, ...). No upload can be in flight yet at +/// startup, so removing the whole subdir is safe; it is recreated on demand by +/// `upload_write_chunk`. +pub fn cleanup_uploads(app: &AppHandle) { + let Ok(dir) = app.path().app_cache_dir() else { + return; + }; + let _ = std::fs::remove_dir_all(dir.join(UPLOAD_SUBDIR)); +} + fn register_abort_sender(request_id: &str) -> watch::Receiver { let (sender, receiver) = watch::channel(false); UPLOAD_ABORT_SENDERS