{"record":{"id":"e1520cd875764c34","repo":"jdx/mise","slug":"recovery-directory-descends-through-a-file-or-syml","errorCode":null,"errorMessage":"recovery directory descends through a file or symlink","messagePattern":"recovery directory descends through a file or symlink","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/history/recovery.rs","lineNumber":181,"sourceCode":"                if relative.as_os_str().is_empty()\n                    || !relative\n                        .components()\n                        .all(|c| matches!(c, Component::Normal(_)))\n                    || !seen.insert(relative)\n                {\n                    bail!(\"invalid path inside recovery directory\");\n                }\n            }\n            for leaf in files\n                .iter()\n                .map(|f| &f.rel)\n                .chain(links.iter().map(|f| &f.rel))\n            {\n                if seen\n                    .iter()\n                    .any(|other| *other != leaf && other.starts_with(leaf))\n                {\n                    bail!(\"recovery directory descends through a file or symlink\");\n                }\n            }\n            for file in files {\n                read_blob(state_dir, &file.content)?;\n            }\n        }\n        PathSnapshot::Unrecorded { reason, .. } => bail!(\"no usable preimage: {reason}\"),\n        _ => {}\n    }\n    Ok(())\n}\n\nfn remove_leaf(path: &Path) -> Result<()> {\n    match std::fs::symlink_metadata(path) {\n        Ok(meta) if meta.is_dir() => std::fs::remove_dir(path)?,\n        Ok(_) => std::fs::remove_file(path)?,\n        Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}\n        Err(error) => return Err(error.into()),","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/history/recovery.rs#L163-L199","documentation":"After ensuring all individual rel paths are normal and unique, validate_snapshot additionally rejects leaf paths that are a prefix of another recorded path. This means the snapshot claims a directory entry that is itself recorded as a file or symlink — recovery cannot create children under a file/symlink, so the snapshot is structurally inconsistent and is rejected before any writes happen.","triggerScenarios":"recover_path on a snapshot where e.g. rel `a` is recorded as a file or link while `a/b` is also recorded (as dir or file), so `seen` contains a path that starts_with the leaf path.","commonSituations":"Corrupted or hand-assembled journals; snapshots recorded while the tree was being modified concurrently (a dir became a file mid-scan); merging snapshots from different runs with overlapping paths.","solutions":["Fix the journal so paths are consistent — either drop the descendants under the file/symlink leaf or record the leaf as a directory","Re-record the snapshot with the tree in a stable state (no concurrent modifications)","If the tree genuinely changed (file replaced by dir), discard the old snapshot and take a new one"],"exampleFix":"// before\n# journal contains file 'a' AND file 'a/b'  -> inconsistent\nrecover_path(path, prior)?;\n// after\n# remove or fix one of the conflicting entries, e.g. keep the tree form:\n# dirs: a/, files: a/b\nvalidate/re-record snapshot; recover_path(path, prior)?;","handlingStrategy":"validation","validationCode":"fn consistent_prefixes(rels: &[std::path::PathBuf]) -> bool {\n    !rels.iter().any(|leaf| {\n        rels.iter().any(|other| *other != *leaf && other.starts_with(leaf))\n    })\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build snapshot entries from a single stable directory scan (no concurrent mutation)","Assert no file/link leaf is also a directory prefix when serializing","Re-snapshot after any file↔directory conversion instead of merging old journals"],"tags":["journal","consistency","filesystem"],"backgroundTag":"internal-invariant-violation","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"}