jdx/mise · error · eyre::Report
refusing to remove directory
Error message
refusing to remove directory {} as a file; declare it in [bootstrap.directories] What it means
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].
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.
Example fix
# before
[bootstrap.files]
"/opt/app/cache" = { state = "absent" }
# after
[bootstrap.directories]
"/opt/app/cache" = { state = "absent", recursive = true } Defensive patterns
Strategy: validation
Validate before calling
// preflight: check on-disk kind before declaring a file absent
fn preflight_absent_file(path: &Path) -> Result<(), String> {
match std::fs::symlink_metadata(path) {
Ok(md) if md.is_dir() => Err(format!("{} is a directory; declare it in [bootstrap.directories]", path.display())),
_ => Ok(()),
}
} Try / catch
// treat the refusal as an actionable config error, not a transient failure
match result {
Err(e) if e.contains("refusing to remove directory") => {
eprintln!("config fix needed: {}", e); // move entry to [bootstrap.directories]
}
other => other?,
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- refusing to remove directory as a file
- refusing to remove non-directory path
- is not a directory; resolve its type before pulling
- managed file parent is not a directory
- refusing to replace non-file path
AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17).
Data as JSON: /api/errors/e6a887e5c3121117.
Report an issue: GitHub.
Appendix: source
Thrown at src/system/managed_files.rs:660
state: config.state,
replace: config.replace,
notify: config.notify,
origin,
inspection: None,
})
}
pub(crate) fn plan(&self) -> Result<ResourcePlan> {
plan_file(self).map(|plan| {
plan.with_origin(self.origin.clone())
.with_file_phase(self.phase)
})
}
fn operation(&self) -> Result<Option<PrivilegedAction>> {
match self.plan()?.action {
ResourceAction::Noop => return Ok(None),
ResourceAction::Unknown if self.state == ManagedState::Absent => bail!(
"refusing to remove directory {} as a file; declare it in [bootstrap.directories]",
self.path.display()
),
ResourceAction::Unknown => bail!(
"refusing to replace non-file path {}; set replace = true to allow replacement",
self.path.display()
),
_ => {}
}
Ok(Some(match self.state {
ManagedState::Present => PrivilegedAction::WriteFile {
path: self.path.clone(),
content: self.content.clone().expect("present file has content"),
owner: self.owner.clone(),
group: self.group.clone(),
mode: self.mode,
replace: self.replace,
},View on GitHub (pinned to 533346cc37)