{"record":{"id":"d0b0bba487df67cb","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-copy-core-status","errorCode":null,"errorMessage":"failed to copy core: {status}","messagePattern":"failed to copy core: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/client/core_lifecycle/adapters.rs","lineNumber":59,"sourceCode":"                                source,\n                                destination.trim_start_matches(r\"\\\\?\\\"),\n                            ])\n                            .status()?,\n                    )\n                }\n                #[cfg(not(target_os = \"windows\"))]\n                {\n                    Ok::<_, anyhow::Error>(\n                        runas::Command::new(\"cp\")\n                            .arg(\"-f\")\n                            .arg(source)\n                            .arg(destination)\n                            .status()?,\n                    )\n                }\n            })\n            .await??;\n            anyhow::ensure!(status.success(), \"failed to copy core: {status}\");\n        }\n        Ok(())\n    }\n}\n\npub(in crate::client) struct FsRuntimeBuildAdapter {\n    pub profiles_dir: PathBuf,\n    pub paths: runtime::RuntimePaths,\n    pub ports: Arc<SessionPortResolver>,\n}\n\n#[async_trait]\nimpl RuntimeBuildPort for FsRuntimeBuildAdapter {\n    fn core_spec(\n        &self,\n        core: &nyanpasu_config::application::ClashCore,\n    ) -> anyhow::Result<nyanpasu_core_manager::CoreSpec> {\n        super::super::runtime_core_spec(core)","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/client/core_lifecycle/adapters.rs#L41-L77","documentation":"After attempting an elevated (runas) copy of the core binary (cmd /C copy /Y on Windows, cp -f elsewhere), the adapter checks the child process's exit status. If the elevation request was denied or the copy failed (non-zero exit), anyhow::ensure! throws \"failed to copy core: {status}\" including the ExitStatus. This is the generic failure of the privilege-escalation fallback for installing the core executable.","triggerScenarios":"Calling FsBinaryInstaller::install when the direct tokio::fs::copy failed (e.g. permission denied on the destination) and the subsequent elevated copy fails: user cancels the UAC prompt, lacks admin rights, the destination is read-only/locked by a running core process, or cmd/cp exits with an error.","commonSituations":"Updating the mihomo/clash core while the core process is still running and locking the file; UAC elevation declined by the user; installing into Program Files without admin; antivirus blocking the copy.","solutions":["Stop the running core process (or the app) before retrying installation so the destination file is not locked.","Re-run the install and accept the UAC/admin prompt; ensure the account can elevate.","Check destination permissions/locks (open handles, antivirus) and free or unlock the target path.","Check the ExitStatus in the message to identify the OS error code, and manually copy the staged binary to the destination as administrator."],"exampleFix":"// before: retrying install while the core is still running\ninstaller.install(&artifact).await?; // fails: destination locked, elevated copy denied\n// after\ncore_client.restart_core().await?; // or stop the core first\ntokio::time::sleep(Duration::from_millis(500)).await;\ninstaller.install(&artifact).await?;","handlingStrategy":"retry","validationCode":"async fn destination_writable(p: &std::path::Path) -> bool {\n    match p.parent() {\n        Some(dir) => tokio::fs::metadata(dir).map(|m| m.is_dir()).await.unwrap_or(false)\n            && std::fs::OpenOptions::new().append(true).open(p).is_ok(),\n        None => false,\n    }\n}","typeGuard":"fn copy_failed(status: &std::process::ExitStatus) -> bool { !status.success() }","tryCatchPattern":"match installer.install(&artifact).await {\n    Err(e) if e.to_string().contains(\"failed to copy core\") => {\n        tracing::warn!(\"elevated copy failed; stopping core and retrying once\");\n        core_client.stop_core().await?;\n        installer.install(&artifact).await.context(\n            \"core copy failed even after elevation; unlock the destination or grant admin rights\"\n        )?;\n    }\n    Ok(()) => {},\n    Err(e) => return Err(e),\n}","preventionTips":["Stop the core process before replacing its binary","Run installers from a location that does not require per-file elevation when possible","Surface the UAC prompt clearly so users do not cancel it unknowingly","Check antivirus/AV lock on the destination directory when installs intermittently fail"],"tags":["filesystem","windows","permissions","process"],"backgroundTag":"file-write-failed","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}