{"record":{"id":"6991963a7e0213ba","repo":"jdx/mise","slug":"refusing-to-replace-non-file-path-set-replace","errorCode":null,"errorMessage":"refusing to replace non-file path {}; set replace = true to allow replacement","messagePattern":"refusing to replace non-file path (.+?); set replace = true to allow replacement","errorType":"error_code","errorClass":"eyre::Report","httpStatus":null,"severity":"error","filePath":"src/system/managed_files.rs","lineNumber":664,"sourceCode":"            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            },\n            ManagedState::Absent => PrivilegedAction::RemoveFile {\n                path: self.path.clone(),\n            },\n        }))","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/managed_files.rs#L646-L682","documentation":"When a [bootstrap.files] entry targets a path occupied by something that is not a regular file (directory, symlink-to-directory, etc.) and the requested state is not Absent, operation() refuses to clobber it unless the entry explicitly sets replace = true. This is a safety guard against destroying unexpected directory trees while installing a file.","triggerScenarios":"Executing a managed file action where plan() yields ResourceAction::Unknown for a non-file existing path and the entry's state is Present (replace not enabled).","commonSituations":"Installing a config where a package or previous setup created a directory at the same path; switching a managed path from directory to file semantics without opting in; mount points or sockets sitting at the declared path.","solutions":["Set `replace = true` on the file entry to authorize replacing the non-file path.","Remove or relocate the existing non-file path manually or via a [bootstrap.directories] absent entry.","Adjust the declared path if it unintentionally collides with a directory."],"exampleFix":"# before\n[bootstrap.files]\n\"/etc/app\" = { content = \"...\", state = \"present\" }\n\n# after\n[bootstrap.files]\n\"/etc/app\" = { content = \"...\", state = \"present\", replace = true }","handlingStrategy":"validation","validationCode":"// preflight: require explicit replace=true when target exists as non-file\nfn preflight_present_file(path: &Path, replace: bool) -> Result<(), String> {\n    match std::fs::symlink_metadata(path) {\n        Ok(md) if !md.is_file() && !replace => {\n            Err(format!(\"{} exists and is not a file; set replace = true\", path.display()))\n        }\n        _ => Ok(()),\n    }\n}","typeGuard":null,"tryCatchPattern":"// catch the refusal and surface the remediation flag\nmatch result {\n    Err(e) if e.contains(\"set replace = true\") => {\n        eprintln!(\"add `replace = true` to the entry or clear the path: {}\", e);\n    }\n    other => other?,\n}","preventionTips":["Run `status`/plan before `prepare` to preview Unknown actions on live systems.","Only enable replace = true after inspecting what occupies the path.","Avoid declaring file paths that packages also manage as directories."],"tags":["managed-files","safety-guard","filesystem"],"backgroundTag":"file-already-exists","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"}