{"record":{"id":"843ba1d9e975218d","repo":"jdx/mise","slug":"managed-file-parent-is-not-a-directory","errorCode":null,"errorMessage":"managed file parent is not a directory: {}","messagePattern":"managed file parent is not a directory: (.+?)","errorType":"error_code","errorClass":"eyre::Report","httpStatus":null,"severity":"error","filePath":"src/system/managed_files.rs","lineNumber":1533,"sourceCode":"    _mode: u32,\n) -> Result<()> {\n    bail!(\"managed system files are only supported on Unix\")\n}\n\nfn write_file(\n    path: &Path,\n    content: &[u8],\n    owner: Option<&str>,\n    group: Option<&str>,\n    mode: u32,\n    replace: bool,\n) -> Result<()> {\n    let parent = path\n        .parent()\n        .ok_or_else(|| eyre!(\"managed file has no parent: {}\", path.display()))?;\n    match fs::metadata(parent) {\n        Ok(metadata) if metadata.is_dir() => {}\n        Ok(_) => bail!(\n            \"managed file parent is not a directory: {}\",\n            parent.display()\n        ),\n        Err(error) if error.kind() == std::io::ErrorKind::NotFound => {\n            bail!(\"managed file parent does not exist: {}\", parent.display())\n        }\n        Err(error) => return Err(error.into()),\n    }\n    // Prepare the complete replacement before mutating the destination. In\n    // particular, a metadata permission error must leave the old path intact.\n    let mut temporary = tempfile::NamedTempFile::new_in(parent)?;\n    temporary.write_all(content)?;\n    set_metadata(temporary.path(), owner, group, mode)?;\n    temporary.as_file_mut().sync_all()?;\n    match fs::symlink_metadata(path) {\n        Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}\n        Err(error) => return Err(error.into()),\n        Ok(metadata) if metadata.file_type().is_file() => {}","sourceCodeStart":1515,"sourceCodeEnd":1551,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/managed_files.rs#L1515-L1551","documentation":"Before atomically replacing a managed file, the library validates the destination's parent directory. This error fires when the parent path exists and `fs::metadata` succeeds, but the metadata is not a directory — e.g. the parent is a regular file, symlink to a file, or other non-directory entry. The library refuses to proceed because it cannot create a temporary file inside a non-directory.","triggerScenarios":"Calling a managed-file write/install with a path whose parent exists but is a plain file — e.g. path \"/etc/somefile/config.txt\" where \"/etc/somefile\" is a file, or a config value where a filename was given where a directory was intended.","commonSituations":"Config mistakes where the managed path embeds a filename that actually exists as a file; a previous write created the parent as a file; leftover artifacts from a prior tool version.","solutions":["Inspect the parent path (`ls -la <parent>`) and remove or rename the non-directory entry if it is stale","Correct the configured managed-file path so the parent component is an actual directory","Create the intended directory structure manually before re-running"],"exampleFix":"// before\ninstall_managed_file(Path::new(\"/etc/nginx.conf/conf.d/app.conf\"), ...); // /etc/nginx.conf is a file\n// after\nfs::create_dir_all(\"/etc/nginx/conf.d\")?;\ninstall_managed_file(Path::new(\"/etc/nginx/conf.d/app.conf\"), ...);","handlingStrategy":"validation","validationCode":"fn validate_parent_is_dir(path: &std::path::Path) -> Result<(), String> {\n    let parent = path.parent().ok_or(\"no parent\")?;\n    match std::fs::metadata(parent) {\n        Ok(m) if m.is_dir() => Ok(()),\n        Ok(_) => Err(format!(\"{} is not a directory\", parent.display())),\n        Err(e) => Err(e.to_string()),\n    }\n}","typeGuard":"fn parent_is_dir(path: &std::path::Path) -> bool {\n    path.parent().map_or(false, |p| std::fs::metadata(p).map_or(false, |m| m.is_dir()))\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"parent is not a directory\") => {\n        eprintln!(\"fix path config: parent exists but is a file\");\n    }\n    other => other?,\n}","preventionTips":["Validate configured paths at startup, not at write time","Never reuse a filename as a directory component","Add pre-flight checks in deployment scripts (test -d \"$parent\")"],"tags":["filesystem","path","managed-files"],"backgroundTag":"path-is-not-a-directory","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"}