{"record":{"id":"20435a567fcec98b","repo":"denoland/deno","slug":"failed-to-atomic-rename-laufey-cache-to-e","errorCode":null,"errorMessage":"failed to atomic-rename LAUFEY cache to {}: {e}","messagePattern":"failed to atomic-rename LAUFEY cache to (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/tools/desktop.rs","lineNumber":2049,"sourceCode":"    if marker.exists() {\n      return Ok(dir);\n    }\n\n    // Discard any prior failed-extract debris (no marker ⇒ partial).\n    // `rename` refuses a non-empty target.\n    if dir.exists() {\n      std::fs::remove_dir_all(&dir)?;\n    }\n\n    let staging_path = staging.into_path();\n    if let Err(e) = std::fs::rename(&staging_path, &dir) {\n      // Lost a rename race with a concurrent process — its dir is at\n      // our target path now. Drop our staged copy and use theirs.\n      let _ = std::fs::remove_dir_all(&staging_path);\n      if marker.exists() {\n        return Ok(dir);\n      }\n      return Err(deno_core::anyhow::anyhow!(\n        \"failed to atomic-rename LAUFEY cache to {}: {e}\",\n        dir.display(),\n      ));\n    }\n\n    // The laufey release archive linker-signs the `laufey` binary with\n    // identifier=`laufey` rather than the .app's CFBundleIdentifier. UN\n    // (UNUserNotificationCenter) rejects authorization requests when\n    // the running binary's signed identifier disagrees with the host\n    // bundle's id (UNErrorCodeNotificationsNotAllowed, error code 1).\n    // In HMR mode the user's project bundle isn't involved — we run\n    // laufey.app directly — so we have to fix the cached copy itself.\n    // Re-sign every Mach-O inside the cached laufey.app with the bundle\n    // id so the running identity is internally consistent. No-op on\n    // non-macOS targets / hosts (no `codesign(1)`).\n    #[cfg(target_os = \"macos\")]\n    if target.contains(\"apple-darwin\")\n      && let Err(e) = harmonize_cached_laufey_identifiers(&dir, backend)","sourceCodeStart":2031,"sourceCodeEnd":2067,"githubUrl":"https://github.com/denoland/deno/blob/f7822238cab635a3a19f99f493f675fa81a7f9d8/cli/tools/desktop.rs#L2031-L2067","documentation":"The downloaded archive is extracted into a sibling staging tempdir and then moved into place with fs::rename(staging, dir) so concurrent `deno desktop` runs never observe a half-populated cache. If the rename fails, the code first checks whether a concurrent process won the race (success marker exists) and only then errors. This message therefore means the rename failed for a non-race reason: permissions, an unexpected existing directory, or something holding locks on the target path.","triggerScenarios":"fs::rename of the staged cache dir fails while no concurrent process's success marker exists at the target: the cache dir exists and is locked (Windows antivirus/indexer), the user lacks write permission on the cache root, a stale half-deleted directory survived the remove_dir_all above, or the filesystem refuses the rename.","commonSituations":"Windows Defender or a search indexer briefly locks the freshly created cache directory; a previous run was killed mid-extract leaving a corrupt dir; the cache lives on a filesystem mounted read-only or with restrictive permissions; two runs raced and one left no marker because it also failed.","solutions":["Delete the laufey cache directory named in the error and re-run — this clears stale locks and corrupt leftovers.","Check write permissions on the cache root (ls -ld on the parent, or icacls on Windows) and fix ownership.","On Windows, temporarily exclude the deno cache dir from real-time antivirus scanning, or just re-run after a few seconds once the scanner releases the handle.","Ensure no other `deno desktop` process is mid-download to the same cache (check with tman list / ps)."],"exampleFix":"# before\ndeno desktop\n# error: failed to atomic-rename LAUFEY cache to /home/me/.cache/deno/desktop/laufey/...\n\n# after: clear the stuck target and retry\nrm -rf /home/me/.cache/deno/desktop/laufey/v1.2.3-aarch64-apple-darwin\ndeno desktop","handlingStrategy":"retry","validationCode":"# Make sure the target cache dir is removable/writable before the run\ncache_dir=\"$HOME/.cache/deno/desktop/laufey/$VER-$TARGET\"\nrm -rf \"$cache_dir\" 2>/dev/null\ntouch \"$(dirname \"$cache_dir\")/.write-probe\" && rm -f \"$(dirname \"$cache_dir\")/.write-probe\"","typeGuard":null,"tryCatchPattern":"Catch the 'failed to atomic-rename' error, delete the target cache dir named in the message, and retry once after a short pause (Windows AV locks usually release within seconds); if it fails identically twice, stop and report a permissions problem rather than looping.","preventionTips":["Exclude the deno cache directory from real-time antivirus/indexer scanning on Windows.","Ensure the cache root is user-writable (chown/chmod or icacls) before CI runs.","Avoid launching several `deno desktop` builds against the same cache dir in lockstep; the race is handled, but the fallback path is what produces this error when the winner also fails."],"tags":["filesystem","concurrency","cache","windows","rename"],"backgroundTag":"file-rename-failed","analyzedSha":"f7822238cab635a3a19f99f493f675fa81a7f9d8","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}