{"record":{"id":"72c0fb5302d21a63","repo":"jdx/mise","slug":"directory-contents-cannot-be-verified-safely-left","errorCode":null,"errorMessage":"directory contents cannot be verified safely; left untouched","messagePattern":"directory contents cannot be verified safely; left untouched","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/history/recovery.rs","lineNumber":100,"sourceCode":"    let Some(after) = after else {\n        bail!(\"write completion was not recorded; inspect the live file before retrying recovery\");\n    };\n    if PathState::observe(path) != *after {\n        bail!(\"changed after the operation; left untouched\");\n    }\n    // Entry count alone cannot establish a directory's identity. Never\n    // replace a populated directory on that evidence.\n    if matches!(after, PathState::Dir { entries, .. } if *entries != 0)\n        && !(matches!(prior, PathSnapshot::Directory { .. })\n            && matches!(\n                after,\n                PathState::Dir {\n                    identity: Some(_),\n                    ..\n                }\n            ))\n    {\n        bail!(\"directory contents cannot be verified safely; left untouched\");\n    }\n    validate_snapshot(state_dir, prior)?;\n    if PathState::observe(path) != *after {\n        bail!(\"changed while preparing recovery; left untouched\");\n    }\n    restore(state_dir, path, prior)\n}\n\nfn validate_destination(path: &Path) -> Result<()> {\n    if !path.is_absolute() || path.components().any(|c| matches!(c, Component::ParentDir)) {\n        bail!(\"invalid recovery destination\");\n    }\n    for parent in path.ancestors().skip(1) {\n        if std::fs::symlink_metadata(parent).is_ok_and(|meta| meta.is_symlink()) {\n            bail!(\"a parent directory is now a symlink; left untouched\");\n        }\n    }\n    Ok(())","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/history/recovery.rs#L82-L118","documentation":"When the recorded evidence for a directory is a non-empty Dir state without a verified identity (or the prior snapshot is not a matching Directory snapshot), mise cannot prove what the directory's contents should be. Rather than replace a populated directory on entry-count evidence alone, it bails and leaves the directory untouched.","triggerScenarios":"recover_path reaches the directory verification branch with `after` being PathState::Dir with entries != 0, but there is no verified identity (`identity: None`) and the prior snapshot is not a matching PathSnapshot::Directory — so contents cannot be validated.","commonSituations":"Recovering an interrupted directory operation (move/replace) where the journal lacks content hashes/identities for directory entries; a crash during a directory write left partial entries; the recovery store predates identity-recording so legacy entries lack the needed proof.","solutions":["Manually inspect the directory and its intended contents; resolve the difference by hand (copy entries from the recovery/temp store).","If the current directory contents are acceptable, accept them with `mise dot recover <operation> --keep-current`.","Recover individual files inside the directory one level deeper where snapshots are file-granular, then remove the now-empty/verified directory state.","If the store is legacy/corrupt, rebuild the enrollment/recovery state after backing up the live directory."],"exampleFix":"// before: directory can't be verified\n$ mise dot recover   # directory contents cannot be verified safely\n// after\nls ~/.config/somedir/            # inspect manually\nmise dot recover <op> --keep-current   # accept current contents","handlingStrategy":"try-catch","validationCode":"export function canVerifyDirectory(after: DirState, prior: Snapshot): boolean {\n  // non-empty dirs need a verified identity or a matching Directory snapshot\n  return after.entries === 0 || after.identity != null || prior.kind === 'directory';\n}","typeGuard":"function hasVerifiedIdentity(s: DirState): boolean {\n  return s.identity != null;\n}","tryCatchPattern":"try {\n  await dotRecover(op);\n} catch (e) {\n  if (/directory contents cannot be verified/.test(String(e))) {\n    manuallyReconcile(dirPath); // copy from recovery store as needed\n    await dotRecover(op, { keepCurrent: true });\n  } else throw e;\n}","preventionTips":["Prefer file-level enrollment over whole-directory operations","Back up populated directories before recovery","Keep recovery store format current so identity data is recorded"],"tags":["recovery","directory","dotfiles","safety-guard"],"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"}