jdx/mise · error

directory changed while restoring permissions

Error message

directory changed while restoring permissions: {}

What it means

restore_dir_modes re-applies saved permission bits to directories it created earlier in a write step. Before chmod it re-checks each path is still a real directory (not a symlink or replaced file); if the filesystem entry changed, it aborts instead of setting permissions on the wrong object.

Solutions

  1. Remove or fix the object now at that path (it should be a real directory) and retry the operation
  2. Stop concurrent processes touching MISE_STATE_DIR and re-run the operation
  3. Check the path for unexpected symlinks: ls -la on the reported path

Example fix

// before: path became a symlink
mv ~/.local/state/mise/history/dir ~/.local/state/mise/history/dir.bak
mkdir ~/.local/state/mise/history/dir   // after: restore real dir, retry
Defensive patterns

Strategy: retry

Validate before calling

let md = std::fs::symlink_metadata(dir)?;
if !md.is_dir() || md.file_type().is_symlink() {
    eprintln!("path changed, skipping: {}", dir.display());
}

Try / catch

match history.write_object(step) {
    Err(e) if e.to_string().contains("directory changed while restoring permissions") => {
        std::thread::sleep(Duration::from_millis(50));
        history.write_object(step)?; // retry once after settling
    }
    other => other?,
}

Prevention

When it happens

Trigger: Between capturing the (dir, mode) pairs and restoring them, the path was replaced by a symlink or a non-directory file — e.g. a concurrent process removed/renamed the directory and put something else there, or the write_object recovery path detected replaced paths (directory_permission_recovery_rejects_replaced_paths).

Common situations: Concurrent mise operations or external tools racing with a history write; a state-dir path being replaced by a symlink; interrupted operations partially cleaned up by other tooling.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/ef53c9d026388e4c. Report an issue: GitHub.

Appendix: source

Thrown at src/system/history/replay.rs:1602

    // a regular file is replaced in place: the atomic write keeps its mode
    file::write_atomic(path, &bytes)?;
    #[cfg(unix)]
    {
        use std::os::unix::fs::PermissionsExt;
        std::fs::set_permissions(path, std::fs::Permissions::from_mode(bits))?;
    }
    Ok(())
}

/// Puts back the recorded mode of the directories above a restored file
/// (a `0700` directory recreated by `create_dir_all` would be `0755`).
#[cfg(unix)]
fn restore_dir_modes(_step: &Step, created: &[(PathBuf, u32)]) -> Result<()> {
    use std::os::unix::fs::PermissionsExt;
    for (dir, bits) in created {
        let metadata = std::fs::symlink_metadata(dir)?;
        if !metadata.is_dir() || metadata.file_type().is_symlink() {
            bail!(
                "directory changed while restoring permissions: {}",
                display_path(dir)
            );
        }
        std::fs::set_permissions(dir, std::fs::Permissions::from_mode(*bits))?;
    }
    Ok(())
}

#[cfg(not(unix))]
fn restore_dir_modes(step: &Step, _created: &[(PathBuf, u32)]) -> Result<()> {
    if step.bits.is_some() || !step.dir_bits.is_empty() {
        debug!(
            "history: {}: recorded permission bits are not restored on this platform",
            display_path(&step.path)
        );
    }
    Ok(())

View on GitHub (pinned to 533346cc37)