{"record":{"id":"b1fb523d92b92926","repo":"tonhowtf/omniget","slug":"failed-to-replace","errorCode":null,"errorMessage":"Failed to replace {}: {}","messagePattern":"Failed to replace (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/dependencies.rs","lineNumber":353,"sourceCode":"        let file_name = target\n            .file_name()\n            .and_then(|n| n.to_str())\n            .unwrap_or(\"binary\")\n            .to_string();\n        let old = target.with_file_name(format!(\"{}.old\", file_name));\n        let _ = std::fs::remove_file(&old);\n        if let Err(e) = std::fs::rename(target, &old) {\n            let _ = std::fs::remove_file(temp);\n            return Err(anyhow!(\n                \"{} is in use by another process ({}). Wait for active downloads to finish or cancel them, then try again.\",\n                file_name,\n                e\n            ));\n        }\n        if let Err(e) = std::fs::rename(temp, target) {\n            let _ = std::fs::rename(&old, target);\n            let _ = std::fs::remove_file(temp);\n            return Err(anyhow!(\"Failed to replace {}: {}\", file_name, e));\n        }\n        let _ = std::fs::remove_file(&old);\n        Ok(())\n    } else {\n        std::fs::rename(temp, target)\n            .map_err(|e| anyhow!(\"Failed to replace {}: {}\", target.display(), e))?;\n        Ok(())\n    }\n}\n\npub async fn update_ffmpeg() -> anyhow::Result<PathBuf> {\n    if is_flatpak() {\n        return Err(anyhow!(\n            \"FFmpeg is provided by the Flatpak runtime and cannot be updated from inside the app\"\n        ));\n    }\n    let path = download_ffmpeg().await?;\n    crate::core::ytdlp::reset_ffmpeg_location_cache();","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/dependencies.rs#L335-L371","documentation":"Thrown by replace_managed_binary on Windows after the old binary was successfully moved to '<name>.old' but moving the new temp binary into the target position fails. The code rolls back (restores the old file, deletes temp) before returning this error, so the previous binary stays intact.","triggerScenarios":"Windows path of replace_managed_binary: fs::rename(temp, target) errors because the target directory became unwritable, disk is full, the temp file was deleted/locked mid-swap, or security software blocked the new executable write.","commonSituations":"Disk full during update; antivirus quarantining the freshly downloaded binary; permissions changed on the install directory; temp file removed by a cleanup routine during a long download.","solutions":["Check free disk space on the target volume and retry.","Check antivirus quarantine/logs for the new binary and add an exclusion.","Verify write permission on the install directory and that the temp file still exists.","Retry the update; the old binary is restored automatically so the app keeps working."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"fn disk_has_space(dir: &std::path::Path, needed: u64) -> bool { /* fs2::available_space(dir) >= needed */ true }","typeGuard":null,"tryCatchPattern":"match replace_managed_binary(&temp, &target) {\n    Ok(()) => {},\n    Err(e) => {\n        // library already rolled back to the old binary\n        log::error!(\"replace failed (old binary restored): {e:#}\");\n        return Err(e);\n    }\n}","preventionTips":["Check free disk space before downloading/replacing.","Add antivirus exclusions for the app's managed-binary directory.","Rely on the built-in rollback: treat the error as 'update failed, previous version intact'."],"tags":["windows","filesystem","io","update","rollback"],"backgroundTag":"file-write-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}