{"record":{"id":"e6a887e5c3121117","repo":"jdx/mise","slug":"refusing-to-remove-directory-as-a-file-declare","errorCode":null,"errorMessage":"refusing to remove directory {} as a file; declare it in [bootstrap.directories]","messagePattern":"refusing to remove directory (.+?) as a file; declare it in \\[bootstrap\\.directories\\]","errorType":"error_code","errorClass":"eyre::Report","httpStatus":null,"severity":"error","filePath":"src/system/managed_files.rs","lineNumber":660,"sourceCode":"            state: config.state,\n            replace: config.replace,\n            notify: config.notify,\n            origin,\n            inspection: None,\n        })\n    }\n\n    pub(crate) fn plan(&self) -> Result<ResourcePlan> {\n        plan_file(self).map(|plan| {\n            plan.with_origin(self.origin.clone())\n                .with_file_phase(self.phase)\n        })\n    }\n\n    fn operation(&self) -> Result<Option<PrivilegedAction>> {\n        match self.plan()?.action {\n            ResourceAction::Noop => return Ok(None),\n            ResourceAction::Unknown if self.state == ManagedState::Absent => bail!(\n                \"refusing to remove directory {} as a file; declare it in [bootstrap.directories]\",\n                self.path.display()\n            ),\n            ResourceAction::Unknown => bail!(\n                \"refusing to replace non-file path {}; set replace = true to allow replacement\",\n                self.path.display()\n            ),\n            _ => {}\n        }\n        Ok(Some(match self.state {\n            ManagedState::Present => PrivilegedAction::WriteFile {\n                path: self.path.clone(),\n                content: self.content.clone().expect(\"present file has content\"),\n                owner: self.owner.clone(),\n                group: self.group.clone(),\n                mode: self.mode,\n                replace: self.replace,\n            },","sourceCodeStart":642,"sourceCodeEnd":678,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/managed_files.rs#L642-L678","documentation":"At operation() time, after planning, a file resource whose target path turns out to be something other than a regular file (typically a directory) and whose requested state is Absent cannot be removed with file semantics. The managed_files subsystem refuses to recursively delete a directory declared under [bootstrap.files] and points the user at [bootstrap.directories].","triggerScenarios":"Executing a PrivilegedAction for a [bootstrap.files] entry with state = \"absent\" whose plan() returns ResourceAction::Unknown because the on-disk path exists as a directory.","commonSituations":"The path changed from a file to a directory across tool versions or manual edits; declaring removal of a path that a package replaced with a directory; stale declarations from an older machine layout.","solutions":["Move the entry to [bootstrap.directories] with state = \"absent\" (and recursive = true if needed) to remove it as a directory.","Manually remove the directory on the system if it should not be managed.","Correct the path if the declaration was meant to target the actual file inside the directory."],"exampleFix":"# before\n[bootstrap.files]\n\"/opt/app/cache\" = { state = \"absent\" }\n\n# after\n[bootstrap.directories]\n\"/opt/app/cache\" = { state = \"absent\", recursive = true }","handlingStrategy":"validation","validationCode":"// preflight: check on-disk kind before declaring a file absent\nfn preflight_absent_file(path: &Path) -> Result<(), String> {\n    match std::fs::symlink_metadata(path) {\n        Ok(md) if md.is_dir() => Err(format!(\"{} is a directory; declare it in [bootstrap.directories]\", path.display())),\n        _ => Ok(()),\n    }\n}","typeGuard":null,"tryCatchPattern":"// treat the refusal as an actionable config error, not a transient failure\nmatch result {\n    Err(e) if e.contains(\"refusing to remove directory\") => {\n        eprintln!(\"config fix needed: {}\", e); // move entry to [bootstrap.directories]\n    }\n    other => other?,\n}","preventionTips":["Verify path kinds on the target hosts when porting managed-file declarations.","Keep file-vs-directory classification in one source of truth.","Re-run status after package upgrades that may reshape managed paths."],"tags":["managed-files","type-mismatch","filesystem"],"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"}