From 968edf239dc663b6717a34ffa1672aa5590b57dd Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Wed, 7 Oct 2026 10:26:54 +0000 Subject: [PATCH 1/4] fix(install): keep incomplete-install markers out of the cache A version whose install never finished is marked incomplete so nothing selects it. The marker lived under MISE_CACHE_DIR, so `mise cache clear` or cache pruning deleted it and the half-done version then counted as installed. Markers now live in MISE_STATE_DIR/incomplete-installs; a marker an older mise left in the cache still counts. The tool-version lock keeps its old identity so old and new mise processes still share it. Co-Authored-By: Claude Opus 5.5 Entire-Checkpoint: 01M4AYDR22FEMVJ7VTVY5P96VP --- ...st_install_incomplete_survives_cache_clear | 43 ++++++ src/backend/http.rs | 3 +- src/backend/mod.rs | 27 ++-- src/backend/packslip.rs | 2 +- src/runtime_symlinks.rs | 18 +-- src/toolset/install_state.rs | 126 +++++++++++++++--- src/toolset/tool_version.rs | 4 +- 7 files changed, 176 insertions(+), 47 deletions(-) create mode 100644 e2e/cli/test_install_incomplete_survives_cache_clear diff --git a/e2e/cli/test_install_incomplete_survives_cache_clear b/e2e/cli/test_install_incomplete_survives_cache_clear new file mode 100644 index 00000000000..1b49d32fd74 --- /dev/null +++ b/e2e/cli/test_install_incomplete_survives_cache_clear @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# A version whose install never finished stays incomplete after the cache is +# cleared, so it is neither listed nor selected over the complete one. +plugin="$MISE_DATA_DIR/plugins/halfdone" +mkdir -p "$plugin/bin" +cat >"$plugin/bin/list-all" <<'SH' +#!/usr/bin/env bash +echo 1.0.0 1.1.0 +SH +# 1.1.0 writes a working binary, then fails: an install that died partway. +cat >"$plugin/bin/install" <<'SH' +#!/usr/bin/env bash +mkdir -p "$ASDF_INSTALL_PATH/bin" +printf '#!/usr/bin/env bash\necho "halfdone %s"\n' "$ASDF_INSTALL_VERSION" >"$ASDF_INSTALL_PATH/bin/halfdone" +chmod +x "$ASDF_INSTALL_PATH/bin/halfdone" +[ "$ASDF_INSTALL_VERSION" != "1.1.0" ] +SH +chmod +x "$plugin/bin/list-all" "$plugin/bin/install" + +cat >mise.toml <<'TOML' +[tools] +halfdone = "1" +TOML + +mise install halfdone@1.0.0 +assert "mise x -- halfdone" "halfdone 1.0.0" + +# Keep the half-done install directory, as `always_keep_install` does. +assert_fail "MISE_ALWAYS_KEEP_INSTALL=1 mise install halfdone@1.1.0" +assert_directory_exists "$MISE_DATA_DIR/installs/halfdone/1.1.0" +assert_not_contains "mise ls --installed halfdone" "1.1.0" +assert "mise x -- halfdone" "halfdone 1.0.0" + +mise cache clear +assert_directory_exists "$MISE_STATE_DIR/incomplete-installs/halfdone/1.1.0" +assert_not_contains "mise ls --installed halfdone" "1.1.0" +assert "mise x -- halfdone" "halfdone 1.0.0" + +# Uninstalling the half-done version clears its marker with it. +mise uninstall halfdone@1.1.0 +assert_directory_not_exists "$MISE_DATA_DIR/installs/halfdone/1.1.0" +assert_directory_not_exists "$MISE_STATE_DIR/incomplete-installs/halfdone/1.1.0" diff --git a/src/backend/http.rs b/src/backend/http.rs index 1120609148b..1e70d0f35d7 100644 --- a/src/backend/http.rs +++ b/src/backend/http.rs @@ -22,6 +22,7 @@ use crate::runtime_symlinks::is_runtime_symlink; use crate::toolset::ToolRequest; use crate::toolset::ToolVersion; use crate::toolset::ToolVersionOptions; +use crate::toolset::install_state; use crate::ui::progress_report::SingleReport; use crate::{dirs, env, file, hash}; use async_trait::async_trait; @@ -1474,7 +1475,7 @@ impl Backend for HttpBackend { _ => { let install_path = Self::lookup_install_path(tv); install_path.exists() - && !self.incomplete_file_path(tv).exists() + && !install_state::is_incomplete(tv.ba(), &tv.state_key()) && (!check_symlink || !is_runtime_symlink(&install_path)) } } diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 609fca6a4f9..71dde29e103 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -2977,7 +2977,7 @@ pub trait Backend: Debug + Send + Sync { ) -> bool { let check_path = |install_path: &Path, check_symlink: bool| { let is_installed = install_path.exists(); - let is_not_incomplete = !self.incomplete_file_path(tv).exists(); + let is_not_incomplete = !install_state::is_incomplete(tv.ba(), &tv.state_key()); let is_valid_symlink = !check_symlink || !is_runtime_symlink(install_path); let is_healthy = is_installed && self.is_install_path_healthy(install_path); // An identity-layout installation is complete once its receipt is there; @@ -3613,7 +3613,7 @@ pub trait Backend: Debug + Send + Sync { // version is a pre-release must not keep winning, and neither // may one left pointing into an interrupted install. if (!filter || !self.is_backend_prerelease(&version)) - && !install_state::incomplete_file_path(self.ba(), &version).exists() + && !install_state::is_incomplete(self.ba(), &version) { return Ok(Some(version)); } @@ -3623,7 +3623,7 @@ pub trait Backend: Debug + Send + Sync { .into_iter() .filter(|v| !v.starts_with('.')) .filter(|v| !is_runtime_symlink(&installs_path.join(v))) - .filter(|v| !install_state::incomplete_file_path(self.ba(), v).exists()) + .filter(|v| !install_state::is_incomplete(self.ba(), v)) .filter(|v| v != "latest") .sorted_by_cached_key(|v| (Versioning::new(v), v.to_string())) .collect_vec(); @@ -3735,6 +3735,7 @@ pub trait Backend: Debug + Send + Sync { remove_all_with_progress(self.ba().installs_path(), pr)?; remove_all_with_progress(self.ba().cache_path(), pr)?; remove_all_with_progress(self.ba().downloads_path(), pr)?; + install_state::clear_incomplete_markers(self.ba())?; Ok(()) } fn get_aliases(&self) -> eyre::Result> { @@ -4545,6 +4546,8 @@ pub trait Backend: Debug + Send + Sync { pr.set_message(format!("remove {}", would_remove.join(", "))); } } else { + // The marker is outside the cache dir removed above. + install_state::clear_incomplete_marker(tv.ba(), &tv.state_key())?; self.cleanup_empty_installs_dir(); } Ok(()) @@ -4644,14 +4647,10 @@ pub trait Backend: Debug + Send + Sync { file::create_dir_all(tv.install_path())?; file::create_dir_all(tv.download_path())?; file::create_dir_all(tv.cache_path())?; - // `file::create` rather than `File::create`: it names the path in the error. The three - // calls above can return Ok without having created anything -- `std::fs::create_dir_all` - // does that for a path Windows refuses, such as one ending in `nul` -- and the first thing - // to notice is this write, three calls away from the cause. Unwrapped it was a bare - // `The system cannot find the path specified. (os error 3)` naming neither the file nor - // the operation. - file::create(&self.incomplete_file_path(tv))?; - Ok(()) + // The three calls above can return Ok without having created anything for a version + // Windows refuses as a path; the marker sits in a directory named for the same version, + // so its write is what reports it, naming the path. + install_state::mark_incomplete(tv.ba(), &tv.state_key()) } fn cleanup_install_dirs_on_error(&self, tv: &ToolVersion) { if !Settings::get().always_keep_install { @@ -4710,14 +4709,10 @@ pub trait Backend: Debug + Send + Sync { .await && self.verify_repaired_install(ctx, tv).await.is_ok(); if !usable { - let _ = file::create(&self.incomplete_file_path(tv)); + let _ = install_state::mark_incomplete(tv.ba(), &tv.state_key()); } } - fn incomplete_file_path(&self, tv: &ToolVersion) -> PathBuf { - install_state::incomplete_file_path(tv.ba(), &tv.state_key()) - } - async fn path_env_for_cmd(&self, config: &Arc, tv: &ToolVersion) -> Result { let path = self .list_bin_paths(config, tv) diff --git a/src/backend/packslip.rs b/src/backend/packslip.rs index 4de7f9d0432..882bfe70317 100644 --- a/src/backend/packslip.rs +++ b/src/backend/packslip.rs @@ -2475,7 +2475,7 @@ mod tests { "original binary" ); assert!( - !install_state::incomplete_file_path(&ba, &tv.state_key()).exists(), + !install_state::is_incomplete(&ba, &tv.state_key()), "the generic marker is cleared after the payload succeeds" ); assert!(crate::packslip::skills_incomplete_path(&install_path).is_file()); diff --git a/src/runtime_symlinks.rs b/src/runtime_symlinks.rs index 7cbcc3d2755..d9dd1134855 100644 --- a/src/runtime_symlinks.rs +++ b/src/runtime_symlinks.rs @@ -277,7 +277,7 @@ fn is_install_incomplete(backend: &Arc, installs_dir: &Path, v: &st let key = crate::install_layout::resolver::link_target(&installs_dir.join(v)) .and_then(|install| install.file_name().map(|n| n.to_string_lossy().to_string())) .unwrap_or_else(|| v.to_string()); - install_state::incomplete_file_path(backend.ba(), &key).exists() + install_state::is_incomplete(backend.ba(), &key) } /// Real install directories a rebuild must never replace with a selector @@ -542,24 +542,20 @@ mod tests { )) } - /// Removes the markers [`interrupted_install`] wrote when the test ends. - struct InterruptedInstall(PathBuf); + /// Removes the marker [`interrupted_install`] wrote when the test ends. + struct InterruptedInstall(Arc, String); impl Drop for InterruptedInstall { fn drop(&mut self) { - let _ = fs::remove_dir_all(&self.0); + let _ = install_state::clear_incomplete_marker(&self.0, &self.1); } } /// Leaves version `v` of `backend` the way an interrupted install does: - /// the incomplete marker is still in the cache. + /// the incomplete marker is still in place. fn interrupted_install(backend: &Arc, v: &str) -> Result { - let marker = install_state::incomplete_file_path(backend.ba(), v); - fs::create_dir_all(marker.parent().unwrap())?; - fs::write(&marker, "")?; - Ok(InterruptedInstall( - marker.parent().unwrap().parent().unwrap().to_path_buf(), - )) + install_state::mark_incomplete(backend.ba(), v)?; + Ok(InterruptedInstall(backend.ba().clone(), v.to_string())) } #[test] diff --git a/src/toolset/install_state.rs b/src/toolset/install_state.rs index 5c38b761330..0e8c8312561 100644 --- a/src/toolset/install_state.rs +++ b/src/toolset/install_state.rs @@ -285,7 +285,7 @@ fn scan_versions(dir: &Path, tool_dir_name: &str) -> Result> { .file_name() .map(|n| n.to_string_lossy().to_string()) .unwrap_or_else(|| name.clone()); - if !incomplete_marker(tool_dir_name, &key).exists() { + if !is_incomplete_in(tool_dir_name, &key) { versions.push(name); } continue; @@ -306,7 +306,7 @@ fn scan_versions(dir: &Path, tool_dir_name: &str) -> Result> { } else if !file_type.is_dir() { continue; } - if incomplete_marker(tool_dir_name, &name).exists() { + if is_incomplete_in(tool_dir_name, &name) { continue; } versions.push(name); @@ -1087,27 +1087,79 @@ fn strip_url_credentials(value: &toml::Value) -> toml::Value { toml::Value::String(url.to_string()) } -/// Marks `v` of `ba` as mid-install; also the identity of its install lock. -/// Keyed by the tool's cache dir, which install, uninstall and link share -/// across local, shared and system install paths. -pub(crate) fn incomplete_file_path(ba: &BackendArg, v: &str) -> PathBuf { - ba.cache_path().join(v).join("incomplete") +/// Marks `v` of the tool whose directory is `tool_dir_name` as mid-install. +/// It lives in the state dir rather than the cache, so `mise cache clear` and +/// cache pruning cannot turn an install that never finished into a complete +/// one. Keyed by the tool's directory name, which install, uninstall and link +/// share across local, shared and system install paths. +/// +/// The version is a directory rather than the marker's own name: on Windows a +/// file named for a reserved device (`nul`) opens that device, while a +/// directory of that name makes the marker write fail and name the path. +fn incomplete_marker(tool_dir_name: impl AsRef, v: &str) -> PathBuf { + incomplete_markers_dir(tool_dir_name) + .join(v) + .join("incomplete") } -fn incomplete_marker(tool_dir_name: impl AsRef, v: &str) -> PathBuf { +fn incomplete_markers_dir(tool_dir_name: impl AsRef) -> PathBuf { + dirs::STATE.join("incomplete-installs").join(tool_dir_name) +} + +/// Where mise 2026.10.3 and earlier marked an install incomplete. A marker an +/// older mise left there still counts until 2027.1, so an install it never +/// finished is not taken for complete after an upgrade. +fn legacy_incomplete_marker(tool_dir_name: impl AsRef, v: &str) -> PathBuf { dirs::CACHE.join(tool_dir_name).join(v).join("incomplete") } +/// `cache/` and the incomplete markers share the tool's directory name. +fn marker_dir_name(ba: &BackendArg) -> &std::ffi::OsStr { + ba.cache_path() + .file_name() + .expect("a tool's cache path names its directory") +} + +fn is_incomplete_in(tool_dir_name: impl AsRef, v: &str) -> bool { + let tool_dir_name = tool_dir_name.as_ref(); + incomplete_marker(tool_dir_name, v).exists() + || legacy_incomplete_marker(tool_dir_name, v).exists() +} + +/// Whether an install of `v` of `ba` started and never finished. +pub(crate) fn is_incomplete(ba: &BackendArg, v: &str) -> bool { + is_incomplete_in(marker_dir_name(ba), v) +} + +/// Marks `v` of `ba` as mid-install until [`clear_incomplete_marker`]. +pub(crate) fn mark_incomplete(ba: &BackendArg, v: &str) -> Result<()> { + let path = incomplete_marker(marker_dir_name(ba), v); + if let Some(parent) = path.parent() { + file::create_dir_all(parent)?; + } + // `file::create` rather than `File::create`: it names the path in the error, + // and `create_dir_all` can return Ok without having created anything -- + // `std::fs::create_dir_all` does that for a path Windows refuses, such as + // one ending in `nul`. Unwrapped it was a bare `The system cannot find the + // path specified. (os error 3)` naming neither the file nor the operation. + file::create(&path)?; + Ok(()) +} + +/// The lock is keyed by where the incomplete marker used to live, which is +/// what older mise processes still lock: moving the marker must not let an old +/// and a new mise install the same version at once. fn tool_version_lock(ba: &BackendArg, v: &str) -> LockFile { - LockFile::new(&incomplete_file_path(ba, v)).with_pid() + LockFile::new(&ba.cache_path().join(v).join("incomplete")).with_pid() } /// Acquires the transaction lock for one logical tool version. /// /// The incomplete marker is shared by local, shared, and system install paths, /// so install, uninstall, and link use this logical identity while mutating the -/// marker and install path. The marker path is only the lock identity; the -/// lock itself remains a separate stable file under the lockfiles cache. +/// marker and install path. The lock's identity is the marker's former cache +/// path (see `tool_version_lock`); the lock itself remains a separate stable +/// file under the lockfiles cache. pub fn lock_tool_version(ba: &BackendArg, v: &str) -> Result { lock_tool_version_with_notice(ba, v, &|_| {}) } @@ -1130,10 +1182,25 @@ pub(crate) fn lock_tool_version_with_notice( } pub fn clear_incomplete_marker(ba: &BackendArg, v: &str) -> Result<()> { - let incomplete_path = incomplete_file_path(ba, v); - match file::remove_file(&incomplete_path) { + let tool_dir_name = marker_dir_name(ba); + let marker = incomplete_marker(tool_dir_name, v); + remove_marker(&marker)?; + if let Some(dir) = marker.parent() { + // Only empty; anything else in it is not ours to remove. + let _ = std::fs::remove_dir(dir); + } + remove_marker(&legacy_incomplete_marker(tool_dir_name, v)) +} + +/// Drops every incomplete marker of `ba`, for a purge that removes all its versions. +pub(crate) fn clear_incomplete_markers(ba: &BackendArg) -> Result<()> { + file::remove_all(incomplete_markers_dir(marker_dir_name(ba))) +} + +fn remove_marker(path: &Path) -> Result<()> { + match file::remove_file(path) { std::result::Result::Ok(()) => { - if let Some(parent) = incomplete_path.parent() + if let Some(parent) = path.parent() && let Err(err) = file::sync_dir(parent) { debug!("error syncing incomplete marker parent: {:?}", err); @@ -1224,8 +1291,10 @@ pub(crate) fn reset_tools() { #[cfg(test)] mod tests { use super::{ - InstallStateTool, incomplete_marker, lock_tool_version, merge_plugin_tools, - normalize_version_for_sort, read_tool_manifest_from, scan_versions, tool_version_lock, + InstallStateTool, clear_incomplete_marker, incomplete_marker, is_incomplete, + legacy_incomplete_marker, lock_tool_version, mark_incomplete, marker_dir_name, + merge_plugin_tools, normalize_version_for_sort, read_tool_manifest_from, scan_versions, + tool_version_lock, }; use crate::args::BackendArg; use crate::plugins::PluginType; @@ -1593,6 +1662,31 @@ explicit_backend = true assert_eq!(versions, ["1.0.0"]); } + /// Clearing the cache must not make an unfinished install look complete, + /// and a marker an older mise left in the cache still counts. + #[test] + fn incomplete_markers_live_outside_the_cache_and_honor_legacy_ones() { + let ba = BackendArg::from(format!("marker_test_{}", std::process::id()).as_str()); + let tool_dir_name = marker_dir_name(&ba).to_owned(); + let marker = incomplete_marker(&tool_dir_name, "1.0.0"); + assert!(!marker.starts_with(*crate::dirs::CACHE)); + + mark_incomplete(&ba, "1.0.0").unwrap(); + let _ = std::fs::remove_dir_all(ba.cache_path()); + assert!(is_incomplete(&ba, "1.0.0")); + clear_incomplete_marker(&ba, "1.0.0").unwrap(); + assert!(!is_incomplete(&ba, "1.0.0")); + assert!(!marker.parent().unwrap().exists()); + + let legacy = legacy_incomplete_marker(&tool_dir_name, "2.0.0"); + std::fs::create_dir_all(legacy.parent().unwrap()).unwrap(); + std::fs::write(&legacy, "").unwrap(); + assert!(is_incomplete(&ba, "2.0.0")); + clear_incomplete_marker(&ba, "2.0.0").unwrap(); + assert!(!is_incomplete(&ba, "2.0.0")); + let _ = std::fs::remove_dir_all(ba.cache_path()); + } + /// Also pins that `DirEntry::file_type()` reports a Windows junction as a symlink, which is /// what the scan keys on. `make_symlink` writes a junction there, so if that were not so, /// `broken` would be dropped below — and the *live* junction would never have been listed diff --git a/src/toolset/tool_version.rs b/src/toolset/tool_version.rs index fb9c989abf7..8d58d96d0bc 100644 --- a/src/toolset/tool_version.rs +++ b/src/toolset/tool_version.rs @@ -610,11 +610,11 @@ impl ToolVersion { } /// Whether an install into `path` was interrupted: the incomplete marker for - /// it is still in the cache. + /// it is still in place. pub(crate) fn is_incomplete_at(&self, path: &Path) -> bool { let key = crate::install_layout::resolver::dir_name_of(path) .unwrap_or_else(|| self.tv_pathname()); - install_state::incomplete_file_path(self.ba(), &key).exists() + install_state::is_incomplete(self.ba(), &key) } pub(crate) fn aube_install_identity(&self) -> Option { From 8e118c75c1d2088ebe12f339ccb9ab61999d1c2a Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Wed, 7 Oct 2026 10:51:02 +0000 Subject: [PATCH 2/4] fix(install): recheck a legacy marker after taking its lock An install that held the lock may have finished and cleared the marker while the migration waited; marking it incomplete again would hide a completed install. Co-Authored-By: Claude Opus 5.5 Entire-Checkpoint: 01M4AZSXYQ0CH6XCTZTD93590T --- src/toolset/install_state.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/toolset/install_state.rs b/src/toolset/install_state.rs index a14a0c743f3..2e9bb33314e 100644 --- a/src/toolset/install_state.rs +++ b/src/toolset/install_state.rs @@ -1141,6 +1141,10 @@ pub(crate) fn migrate_legacy_incomplete_markers() -> Result { all_moved = false; continue; }; + // The install that held the lock may have finished and cleared it. + if !legacy.is_file() { + continue; + } let marker = incomplete_marker(&tool_dir_name, &v); if let Some(parent) = marker.parent() { file::create_dir_all(parent)?; From 4cbab78328800b018f47813553f09961b5f6164b Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Wed, 7 Oct 2026 11:10:54 +0000 Subject: [PATCH 3/4] test(install): plant incomplete markers in the state dir These tests simulated an interrupted install by writing the marker at the old cache path. Once a startup has migrated, that path is no longer read, so they now write where mise does. Clearing a marker also removes its version directory, so a second touch needs mkdir -p. Co-Authored-By: Claude Opus 5.5 Entire-Checkpoint: 01M4B0YA7JTGFFAX07N4QVAQ8Z --- e2e/backend/test_aqua_failed_install_cleanup | 2 +- e2e/backend/test_npm_aube | 2 +- e2e/backend/test_runtime_symlink_stale_prune | 4 +-- e2e/cli/test_install_layout_cli_variants | 6 ++-- e2e/cli/test_link | 35 ++++++++++---------- e2e/sync/test_sync_python_uv | 11 +++--- 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/e2e/backend/test_aqua_failed_install_cleanup b/e2e/backend/test_aqua_failed_install_cleanup index 23dcd22e548..31c0208c12e 100644 --- a/e2e/backend/test_aqua_failed_install_cleanup +++ b/e2e/backend/test_aqua_failed_install_cleanup @@ -12,7 +12,7 @@ assert_fail "mise x tilt@9999.9999.9999 -- tilt version" # The parent installs directory should be fully cleaned up, not left empty. assert_directory_not_exists "$MISE_DATA_DIR/installs/tilt" -assert "test ! -e \"$MISE_CACHE_DIR/tilt/9999.9999.9999/incomplete\"" +assert "test ! -e \"$MISE_STATE_DIR/incomplete-installs/tilt/9999.9999.9999/incomplete\"" # A subsequent successful install should work correctly. assert_contains "mise x tilt@0.36.3 -- tilt version" "v0.36.3" diff --git a/e2e/backend/test_npm_aube b/e2e/backend/test_npm_aube index 8b1148180bb..d267cfd13bf 100644 --- a/e2e/backend/test_npm_aube +++ b/e2e/backend/test_npm_aube @@ -67,7 +67,7 @@ node = "20.11.1" EOF MISE_LOCKFILE=1 mise -C auto-lock install assert_succeed "find '$MISE_DATA_DIR/installs/npm-inflight' -maxdepth 1 -name '1.0.6~aube~*' | grep -q ." -assert_succeed "test ! -e '$MISE_CACHE_DIR/npm-inflight/1.0.6/incomplete'" +assert_succeed "test ! -e '$MISE_STATE_DIR/incomplete-installs/npm-inflight/1.0.6/incomplete'" # Generate-mode upgrades fill graphs after changing the lockfile revision. mkdir upgrade-lock diff --git a/e2e/backend/test_runtime_symlink_stale_prune b/e2e/backend/test_runtime_symlink_stale_prune index 127b7ccde11..89f723c9124 100644 --- a/e2e/backend/test_runtime_symlink_stale_prune +++ b/e2e/backend/test_runtime_symlink_stale_prune @@ -28,8 +28,8 @@ mise install stalelink@1.1.0 assert "readlink $INSTALLS/1.1" "./1.1.0" # an install interrupted partway through -mkdir -p "$MISE_CACHE_DIR/stalelink/1.1.0" -touch "$MISE_CACHE_DIR/stalelink/1.1.0/incomplete" +mkdir -p "$MISE_STATE_DIR/incomplete-installs/stalelink/1.1.0" +touch "$MISE_STATE_DIR/incomplete-installs/stalelink/1.1.0/incomplete" mise install stalelink@1.0.0 diff --git a/e2e/cli/test_install_layout_cli_variants b/e2e/cli/test_install_layout_cli_variants index 1c52e16b412..689dd92402c 100644 --- a/e2e/cli/test_install_layout_cli_variants +++ b/e2e/cli/test_install_layout_cli_variants @@ -64,13 +64,13 @@ assert "mise -C $work/solo2 install" solo2_dir="$(mise -C "$work/solo2" where tiny)" assert "mise where tiny@3.1.0" "$solo2_dir" # as if a refresh of the variant had been interrupted -mkdir -p "$MISE_CACHE_DIR/tiny/$(basename "$solo2_dir")" -touch "$MISE_CACHE_DIR/tiny/$(basename "$solo2_dir")/incomplete" +mkdir -p "$MISE_STATE_DIR/incomplete-installs/tiny/$(basename "$solo2_dir")" +touch "$MISE_STATE_DIR/incomplete-installs/tiny/$(basename "$solo2_dir")/incomplete" assert "mise install tiny@3.1.0" bare_dir="$(mise where tiny@3.1.0)" [[ $bare_dir != "$solo2_dir" ]] || fail "the bare version was installed into the variant" # the variant is still the project's, once its own refresh is done -rm "$MISE_CACHE_DIR/tiny/$(basename "$solo2_dir")/incomplete" +rm "$MISE_STATE_DIR/incomplete-installs/tiny/$(basename "$solo2_dir")/incomplete" assert "mise -C $work/solo2 where tiny" "$solo2_dir" assert "mise installs ls tiny --json | jq -r '.[] | select(.selected and .version == \"3.1.0\") | .dir' | sort | tr '\n' ' '" "$(printf '%s\n' "$bare_dir" "$solo2_dir" | sort | tr '\n' ' ')" diff --git a/e2e/cli/test_link b/e2e/cli/test_link index ec09112b7e3..6de49953ca8 100644 --- a/e2e/cli/test_link +++ b/e2e/cli/test_link @@ -12,38 +12,39 @@ assert_contains "mise ls tiny" "tiny 9.8.7 (symlink)" # and `mise doctor` treat any version with an `incomplete` marker as not # installed). `mise link` should clear that marker. mkdir -p tmp/tiny2 -mkdir -p "$MISE_CACHE_DIR/tiny/9.9.9" -touch "$MISE_CACHE_DIR/tiny/9.9.9/incomplete" -mkdir -p "$MISE_CACHE_DIR/tiny/9.9.8" -touch "$MISE_CACHE_DIR/tiny/9.9.8/incomplete" +mkdir -p "$MISE_STATE_DIR/incomplete-installs/tiny/9.9.9" +touch "$MISE_STATE_DIR/incomplete-installs/tiny/9.9.9/incomplete" +mkdir -p "$MISE_STATE_DIR/incomplete-installs/tiny/9.9.8" +touch "$MISE_STATE_DIR/incomplete-installs/tiny/9.9.8/incomplete" mise link tiny@9.9.9 tmp/tiny2 # `mise ls -i` only lists versions considered installed; the linked version # must appear despite the pre-existing stale marker. assert_contains "mise ls -i tiny" "tiny 9.9.9 (symlink)" # the stale marker should have been removed by `mise link`. -assert "test ! -f \"$MISE_CACHE_DIR/tiny/9.9.9/incomplete\"" +assert "test ! -f \"$MISE_STATE_DIR/incomplete-installs/tiny/9.9.9/incomplete\"" # a sibling version's marker must not be affected. -assert "test -f \"$MISE_CACHE_DIR/tiny/9.9.8/incomplete\"" +assert "test -f \"$MISE_STATE_DIR/incomplete-installs/tiny/9.9.8/incomplete\"" # Re-linking the same target should repair a newly-created stale marker without # requiring --force. -touch "$MISE_CACHE_DIR/tiny/9.9.9/incomplete" +mkdir -p "$MISE_STATE_DIR/incomplete-installs/tiny/9.9.9" +touch "$MISE_STATE_DIR/incomplete-installs/tiny/9.9.9/incomplete" mise link tiny@9.9.9 tmp/tiny2 -assert "test ! -f \"$MISE_CACHE_DIR/tiny/9.9.9/incomplete\"" +assert "test ! -f \"$MISE_STATE_DIR/incomplete-installs/tiny/9.9.9/incomplete\"" # A dangling external link is not a complete install and must keep the marker. mise link tiny@9.9.8 tmp/missing -assert "test -f \"$MISE_CACHE_DIR/tiny/9.9.8/incomplete\"" +assert "test -f \"$MISE_STATE_DIR/incomplete-installs/tiny/9.9.8/incomplete\"" # Path equality alone must not treat an ordinary managed install as an existing # external link. -mkdir -p "$MISE_CACHE_DIR/tiny/3.1.0" -touch "$MISE_CACHE_DIR/tiny/3.1.0/incomplete" +mkdir -p "$MISE_STATE_DIR/incomplete-installs/tiny/3.1.0" +touch "$MISE_STATE_DIR/incomplete-installs/tiny/3.1.0/incomplete" assert_fail "mise link tiny@3.1.0 \"$MISE_DATA_DIR/installs/tiny/3.1.0\"" assert_fail "mise link --force tiny@3.1.0 \"$MISE_DATA_DIR/installs/tiny/3.1.0\"" assert_directory_exists "$MISE_DATA_DIR/installs/tiny/3.1.0" -assert "test -f \"$MISE_CACHE_DIR/tiny/3.1.0/incomplete\"" +assert "test -f \"$MISE_STATE_DIR/incomplete-installs/tiny/3.1.0/incomplete\"" # A filesystem alias to the managed install is still the install itself. # In particular, --force must not remove the directory before replacing it @@ -56,10 +57,10 @@ assert "test -f \"$MISE_DATA_DIR/installs/tiny/3.1.0/sentinel\"" # Request-style versions use their normalized install pathname for both the # symlink and incomplete marker. mkdir -p tmp/tiny-ref -mkdir -p "$MISE_CACHE_DIR/tiny/ref-feature-foo" -touch "$MISE_CACHE_DIR/tiny/ref-feature-foo/incomplete" +mkdir -p "$MISE_STATE_DIR/incomplete-installs/tiny/ref-feature-foo" +touch "$MISE_STATE_DIR/incomplete-installs/tiny/ref-feature-foo/incomplete" mise link tiny@ref:feature/foo tmp/tiny-ref -assert "test ! -f \"$MISE_CACHE_DIR/tiny/ref-feature-foo/incomplete\"" +assert "test ! -f \"$MISE_STATE_DIR/incomplete-installs/tiny/ref-feature-foo/incomplete\"" assert "mise where tiny@ref:feature/foo" "$MISE_DATA_DIR/installs/tiny/ref-feature-foo" assert "readlink \"$MISE_DATA_DIR/installs/tiny/ref-feature-foo\"" "$PWD/tmp/tiny-ref" @@ -101,9 +102,9 @@ assert "readlink \"$MISE_DATA_DIR/installs/linked-tiny/9.9.6\"" "$PWD/tmp/tiny2" # Marker removal errors remain strict, while the marker itself is preserved. mkdir -p tmp/tiny3 -mkdir -p "$MISE_CACHE_DIR/tiny/9.9.7/incomplete" +mkdir -p "$MISE_STATE_DIR/incomplete-installs/tiny/9.9.7/incomplete" assert_fail "mise link tiny@9.9.7 tmp/tiny3" -assert "test -d \"$MISE_CACHE_DIR/tiny/9.9.7/incomplete\"" +assert "test -d \"$MISE_STATE_DIR/incomplete-installs/tiny/9.9.7/incomplete\"" # A link whose target went away is still an entry occupying its version's name. It used to be # invisible to `mise ls` -- no config names it, and every check resolved the link before answering diff --git a/e2e/sync/test_sync_python_uv b/e2e/sync/test_sync_python_uv index 502881e8dc6..2ce29975d55 100644 --- a/e2e/sync/test_sync_python_uv +++ b/e2e/sync/test_sync_python_uv @@ -5,8 +5,8 @@ export MISE_PYTHON_GITHUB_ATTESTATIONS=0 # (astral-sh/uv#19278). Bump once 0.11.10 ships with attestations restored. assert "mise use -g uv@0.11.8 python@3.11.3" assert "mise x -- uv python install 3.11.1" -mkdir -p "$MISE_CACHE_DIR/python/3.11.1" -touch "$MISE_CACHE_DIR/python/3.11.1/incomplete" +mkdir -p "$MISE_STATE_DIR/incomplete-installs/python/3.11.1" +touch "$MISE_STATE_DIR/incomplete-installs/python/3.11.1/incomplete" test_uv_python_dir="$(mise x -- uv python dir)" # Multiple provider entries can map to the same mise version. Preserve the # first sorted entry, matching the previous create-if-missing behavior. @@ -14,12 +14,13 @@ mkdir -p "$test_uv_python_dir/pypy-3.11.1-linux-x86_64-gnu" mkdir -p "$test_uv_python_dir/unrecognized" export UV_PYTHON_DOWNLOADS=never assert "mise sync python --uv" -assert "test ! -f \"$MISE_CACHE_DIR/python/3.11.1/incomplete\"" +assert "test ! -f \"$MISE_STATE_DIR/incomplete-installs/python/3.11.1/incomplete\"" assert "mise where python@3.11.1" assert_contains "readlink \"$MISE_DATA_DIR/installs/python/3.11.1\"" "cpython-3.11.1" -touch "$MISE_CACHE_DIR/python/3.11.1/incomplete" +mkdir -p "$MISE_STATE_DIR/incomplete-installs/python/3.11.1" +touch "$MISE_STATE_DIR/incomplete-installs/python/3.11.1/incomplete" assert "mise sync python --uv" -assert "test ! -f \"$MISE_CACHE_DIR/python/3.11.1/incomplete\"" +assert "test ! -f \"$MISE_STATE_DIR/incomplete-installs/python/3.11.1/incomplete\"" assert "mise x python@3.11.1 -- python -V" "Python 3.11.1" assert "mise x -- uv run -p 3.11.3 -- python -V" "Python 3.11.3" From 5b0d034bfd5c0b2aae13388cfa5948ab21a62692 Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Wed, 7 Oct 2026 11:10:56 +0000 Subject: [PATCH 4/4] fix(install): keep migrating past an unreadable cache entry A tool dir that cannot be read, or a lock that cannot be taken, now leaves that marker for a later run instead of aborting the migration. Co-Authored-By: Claude Opus 5.5 Entire-Checkpoint: 01M4B0YC335FQXFM6XC19GRAN9 --- src/toolset/install_state.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/toolset/install_state.rs b/src/toolset/install_state.rs index 2e9bb33314e..c8d7e560d33 100644 --- a/src/toolset/install_state.rs +++ b/src/toolset/install_state.rs @@ -1131,13 +1131,26 @@ static LEGACY_INCOMPLETE_MARKERS_REMAIN: Lazy = pub(crate) fn migrate_legacy_incomplete_markers() -> Result { let mut all_moved = true; for tool_dir_name in file::dir_subdirs(&dirs::CACHE)? { - for v in file::dir_subdirs(&dirs::CACHE.join(&tool_dir_name))? { + // One unreadable entry must not keep the rest from moving; it is left + // in place, still honored, for a later run. + let versions = match file::dir_subdirs(&dirs::CACHE.join(&tool_dir_name)) { + std::result::Result::Ok(versions) => versions, + Err(err) => { + debug!("migrate: reading {tool_dir_name} in the cache failed: {err:?}"); + all_moved = false; + continue; + } + }; + for v in versions { let legacy = legacy_incomplete_marker(&tool_dir_name, &v); if !legacy.is_file() { continue; } // The legacy path is also the version's lock identity. - let Some(_lock) = LockFile::new(&legacy).try_lock()? else { + let Some(_lock) = LockFile::new(&legacy).try_lock().unwrap_or_else(|err| { + debug!("migrate: locking {}: {err:?}", display_path(&legacy)); + None + }) else { all_moved = false; continue; };