jdx/mise · error

refusing to replace non-directory path: {}

Error message

refusing to replace non-directory path: {}

What it means

create_directory() refuses to replace an existing non-directory path (regular file, symlink, ...) with a directory unless the entry sets replace = true. With replace = true mise does remove_file() then create_dir() and applies metadata.

Source

Thrown at src/system/managed_files.rs:1419

            bail!("refusing to remove directory as a file: {}", path.display())
        }
        Ok(_) => fs::remove_file(path).map_err(Into::into),
    }
}

fn create_directory(
    path: &Path,
    owner: Option<&str>,
    group: Option<&str>,
    mode: u32,
    replace: bool,
) -> Result<()> {
    match fs::symlink_metadata(path) {
        Err(error) if error.kind() == std::io::ErrorKind::NotFound => fs::create_dir(path)?,
        Err(error) => return Err(error.into()),
        Ok(metadata) if metadata.file_type().is_dir() => {}
        Ok(_) if !replace => {
            bail!("refusing to replace non-directory path: {}", path.display())
        }
        Ok(_) => {
            fs::remove_file(path)?;
            fs::create_dir(path)?;
        }
    }
    set_metadata(path, owner, group, mode)
}

fn remove_directory(path: &Path, recursive: bool) -> Result<()> {
    match fs::symlink_metadata(path) {
        Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(()),
        Err(err) => Err(err.into()),
        Ok(metadata) if !metadata.file_type().is_dir() => {
            bail!("refusing to remove non-directory path: {}", path.display())
        }
        Ok(_) if recursive => fs::remove_dir_all(path).map_err(Into::into),
        Ok(_) => fs::remove_dir(path).map_err(Into::into),

View on GitHub (pinned to 9dcfcaa0dc)

Solutions

  1. Set replace = true on the directory entry
  2. Or delete the offending file/symlink manually first, then re-run bootstrap

Example fix

# before: /opt/app is currently a regular file
[bootstrap.directories]
"/opt/app" = { mode = "0755" }

# after
[bootstrap.directories]
"/opt/app" = { mode = "0755", replace = true }
Defensive patterns

Strategy: validation

Validate before calling

match std::fs::symlink_metadata(path) {
    Ok(m) if !m.file_type().is_dir() && !replace => {
        return Err(eyre::eyre!("path exists as non-directory; set replace = true"));
    }
    _ => {}
}

Type guard

fn can_create_directory_here(path: &std::path::Path, replace: bool) -> bool {
    match std::fs::symlink_metadata(path) {
        Err(_) => true,
        Ok(m) => m.file_type().is_dir() || replace,
    }
}

Prevention

When it happens

Trigger: A [bootstrap.directories] entry whose path exists as a file or symlink while the entry lacks replace = true.

Common situations: Converting a location that previously held a file into a directory; a leftover symlink from another tool occupying the path.

Related errors


AI-assisted analysis of jdx/mise@9dcfcaa0dc (2026-08-17). Data as JSON: /api/errors/dc5bb1db46e40537. Report an issue: GitHub.