{"record":{"id":"e4ecbd2b4400f19c","repo":"jdx/mise","slug":"too-many-symlinks-while-resolving-atomic-write-tar","errorCode":null,"errorMessage":"too many symlinks while resolving atomic write target: {}","messagePattern":"too many symlinks while resolving atomic write target: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/file.rs","lineNumber":581,"sourceCode":"\n    let mut target = path.to_path_buf();\n    for followed in 0..=MAX_SYMLINKS {\n        if !target.is_symlink() {\n            return Ok(desymlink_path(&target));\n        }\n        if followed == MAX_SYMLINKS {\n            break;\n        }\n        let link = fs::read_link(&target)\n            .wrap_err_with(|| format!(\"failed to read symlink: {}\", display_path(&target)))?;\n        target = if link.is_absolute() {\n            link\n        } else {\n            target.parent().unwrap_or_else(|| Path::new(\"\")).join(link)\n        };\n    }\n\n    bail!(\n        \"too many symlinks while resolving atomic write target: {}\",\n        display_path(path)\n    )\n}\n\npub(crate) fn persist_atomic(mut temporary: tempfile::NamedTempFile, path: &Path) -> Result<()> {\n    const RETRIES: u32 = 20;\n\n    for attempt in 0..=RETRIES {\n        match temporary.persist(path) {\n            Ok(_) => return Ok(()),\n            Err(err) if should_retry_atomic_persist(&err.error) && attempt < RETRIES => {\n                temporary = err.file;\n                std::thread::sleep(Duration::from_millis(5 * u64::from(attempt + 1)));\n            }\n            Err(err) => return Err(err.error.into()),\n        }\n    }","sourceCodeStart":563,"sourceCodeEnd":599,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/file.rs#L563-L599","documentation":"Before an atomic write, mise resolves the final target path by following symlinks (bounded loop). If the chain of symlinks does not terminate within the loop limit — a symlink cycle or extremely deep chain — it aborts with this error rather than looping forever or writing through an unexpected path.","triggerScenarios":"Calling `atomic_write_target` (via `prepare_atomic_write`) on a path whose parent chain contains a symlink loop, e.g. `ln -s a b; ln -s b a`, or more symlink hops than the internal limit.","commonSituations":"Corrupted tool-install symlink trees; dotfile managers (GNU stow etc.) creating cyclic links; a symlink loop inside a mise data/config directory after a crashed sync.","solutions":["Find and remove the symlink cycle on the path (e.g. with `find -L . -type l` or `namei` on the displayed path)","Recreate the affected symlinks pointing to real directories","Reinstall the affected tool (`mise install -f <tool>`) to rebuild its directory layout"],"exampleFix":"// before\nln -s b a && ln -s a b   # cycle; mise write fails\n// after\nrm a b && mkdir -p realdir && ln -s realdir a","handlingStrategy":"validation","validationCode":"function hasSymlinkLoop(path) {\n  const seen = new Set();\n  let cur = require('fs').realpathSync.native(path, undefined, () => null); // or walk manually\n  let p = path;\n  for (let i = 0; i < 40 && require('fs').lstatSync(p).isSymbolicLink(); i++) {\n    if (seen.has(p)) return true;\n    seen.add(p);\n    p = require('path').resolve(require('path').dirname(p), require('fs').readlinkSync(p));\n  }\n  return false;\n}\n// check with: find -L ~/.local/share/mise -type l 2>/dev/null","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Audit symlink trees under mise directories with `find -L ... -type l`","Avoid symlink managers (stow, dfm) inside mise data dirs","Reinstall tools after filesystem crashes or interrupted syncs"],"tags":["filesystem","symlink","atomic-write"],"backgroundTag":"file-write-failed","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}