Repository navigation
Conversation
199f1f5 to
2ed178b
Compare
| source: String, | ||
| version: String, |
2ed178b to
e8fe93f
Compare
e8fe93f to
5f8060c
Compare
Merging this PR will not alter performance
|
5f8060c to
935232e
Compare
| #[arg(long, env = EnvVars::UV_NO_MODIFY_PATH)] | ||
| pub no_modify_path: bool, |
There was a problem hiding this comment.
[P2] Accept the documented numeric PATH environment flag
UV_NO_MODIFY_PATH=1, the documented installer setting, is rejected because this boolean uses clap's default parser, which accepts only true and false. Installation therefore fails during argument parsing. Add BoolishValueParser::new(), following the existing environment-backed flags, and cover the numeric environment value in a focused test.
| let _lock = LockedFile::acquire( | ||
| destination.join(".uv-install.lock"), | ||
| LockedFileMode::Exclusive, | ||
| "uv installation", | ||
| ) |
There was a problem hiding this comment.
[P2] Hold the installation lock through receipt updates
The lock is released when install_binaries returns, before the receipt is written; receipt validation also happens before acquisition. Concurrent installers can therefore leave mismatched state: A installs its binaries and releases the lock, B installs its binaries and receipt, then A overwrites B's receipt. Move lock ownership into self_install and hold it from receipt validation through the final receipt write.
| } else if let Some(path) = std::env::var_os(EnvVars::XDG_CONFIG_HOME) | ||
| && Path::new(&path).is_absolute() | ||
| { | ||
| PathBuf::from(path).join("uv") |
There was a problem hiding this comment.
[P3] Share the existing legacy receipt discovery
This duplicates self_update::receipt_prefixes with different fallback behavior. When an absolute XDG_CONFIG_HOME is set but the receipt remains under ~/.config/uv, self-update can find it while this implementation cannot. The caller then discards the error and can replace a custom release source with the official default. Extract and reuse the existing legacy lookup so both commands recognize the same installations.
| self_replace::self_replace(&source)?; | ||
| continue; | ||
| } | ||
| uv_fs::copy_atomic_sync(&source, &target)?; |
There was a problem hiding this comment.
[P3] Rename the staged executables instead of copying again
Each executable has already been copied into a temporary directory under the destination. copy_atomic_sync creates another temporary file and copies the entire executable again before renaming it, adding redundant I/O and temporary storage. The staged files are already on the destination filesystem, so use uv_fs::rename_with_retry to commit them directly while retaining the Windows self-replacement branch.
| uv-dispatch = { workspace = true } | ||
| uv-distribution = { workspace = true } | ||
| uv-dirs = { workspace = true } | ||
| uv-distribution-filename = { workspace = true } |
There was a problem hiding this comment.
[P3] Remove the unused distribution-filename dependency
No code in the uv crate uses uv-distribution-filename. This adds an unnecessary direct dependency and lockfile entry contrary to the repository's unused-dependency checks. Remove it from this manifest and the corresponding uv dependency list in Cargo.lock.
| if modify_path { | ||
| update_shell::update_shell(&destination, printer).await?; |
There was a problem hiding this comment.
[P2] Treat unchanged shell configuration as a successful install
On Unix, repeating installation into a directory outside the current PATH before restarting the shell replaces the binaries successfully, then exits with an error. The shared helper deliberately errors when configuration files already contain the PATH entry, as covered by update_shell_tool_and_python. That diagnostic suits an explicit update-shell command but makes installation non-idempotent. Expose an unchanged outcome from the helper and accept it here while retaining genuine shell-update errors.
| let recorded = receipt | ||
| .install_prefix | ||
| .join(format!("uv{}", std::env::consts::EXE_SUFFIX)); | ||
| anyhow::ensure!( | ||
| uv_fs::is_same_file_allow_missing(&recorded, &executable) == Some(true), |
There was a problem hiding this comment.
[P2] Normalize legacy receipt prefixes in both lookup paths
For a cargo-dist receipt recording <root> while the executable lives at <root>/bin/uv, for_installation accepts the legacy layout, but this method checks only <root>/uv. Installing that distribution into a fresh directory therefore rejects its valid source receipt; the caller's .ok() silently replaces custom release metadata with ReleaseSource::default(). Share the legacy-prefix normalization between both lookup paths before checking executable identity.
| let output = command.output()?; | ||
| assert!( | ||
| output.status.success(), | ||
| "{}", | ||
| String::from_utf8_lossy(&output.stderr) | ||
| ); |
There was a problem hiding this comment.
[P3] Use command snapshots in the main installation test
This test hand-rolls output capture and stderr formatting, then switches to .status() for the installed executable and repeat installation. That duplicates assertion infrastructure and leaves those command outputs unspecified. Use explicit uv_snapshot! calls with context filters, following tests/python/python_install.rs::python_install and this module's legacy-receipt test; retain the focused filesystem and receipt assertions.
| uv_fs::with_retry_sync(&source, &target, "renaming", || { | ||
| fs_err::rename(&source, &target) | ||
| })?; |
There was a problem hiding this comment.
[P2] Handle the running Windows launcher during replacement
Running uvw self install into its own installation directory reaches this rename while uvw.exe is still running: uv_windows::spawn_child keeps the launcher alive until its child exits. The self-replacement branch handles only uv.exe, so replacing uvw.exe fails after retries, after the other binaries have been replaced and before the receipt is written. Retrying cannot resolve this parent-child dependency. Handle in-use Windows targets by renaming the old executable aside and deferring cleanup, following the pattern in execute_official_installer, before committing the staged replacement.
1662ede to
9ec3929
Compare
| let source = source.join(name); | ||
| anyhow::ensure!( | ||
| fs_err::symlink_metadata(&source)?.is_file(), |
There was a problem hiding this comment.
[P2] Verify that the staged uv is the running executable
If [email protected] runs beside an older uv and uvx, this copies the older unsuffixed binaries while the receipt and success message report 0.13.0. The uvx and uvw launchers explicitly support versioned executable names. for_executable does not prevent this mismatch because its errors are discarded by the caller. Pass the running executable into staging and verify that the selected source uv identifies it before replacing anything; unsupported layouts should fail clearly instead of successfully installing a different version.
| let executable = std::env::current_exe()?; | ||
| fs_err::create_dir_all(&destination)?; | ||
| let lock = LockedFile::acquire( |
There was a problem hiding this comment.
[P2] Retain executable identity across the installation lock wait
If a process launched from the destination waits behind an installer of another uv version, this saved executable path can be replaced during lock acquisition. install_binaries then compares source/uv with the same saved pathname, so the identity check succeeds even though it now selects the other installer's binary. The waiting process copies that binary but records its own CARGO_PKG_VERSION in the receipt and success message. Retain the executable's file identity across the wait and reject a changed source before replacing files.
| #[cfg(any(not(windows), feature = "windows-gui-bin"))] | ||
| fn installs_running_distribution_with_numeric_no_modify_path() -> Result<()> { | ||
| let context = uv_test::test_context_with_versions!(&[]) | ||
| .with_filter((r"uv [0-9]+\.[0-9]+\.[0-9]+[^ ]*", "uv [VERSION]")) |
There was a problem hiding this comment.
[P3] Filter only the expected installed version
This filter normalizes every uv version, so the installed executable's --version snapshot passes even if installation selects a different version. The receipt assertion does not catch that mismatch because receipt creation independently uses CARGO_PKG_VERSION. Filter the escaped expected version, following the existing self-update tests, and apply the same correction to installs_linked_running_distribution.
| #[cfg(not(windows))] | ||
| uv_fs::with_retry_sync(&source, &target, "renaming", || { | ||
| fs_err::rename(&source, &target) | ||
| })?; |
There was a problem hiding this comment.
[P3] Call the synchronous rename directly on non-Windows
with_retry_sync only implements retries on Windows; under this cfg(not(windows)) branch it simply invokes the closure once. The wrapper therefore suggests retry behavior that cannot occur here and requires readers to inspect another layer. Call fs_err::rename directly: it already satisfies the synchronous-operation requirement, and the corresponding Windows-only hawk override can remain unchanged.
| lint = "hawk::unnecessary_public" | ||
| crate = "uv_fs" | ||
| item = "with_retry_sync" | ||
| kind = "function" | ||
| level = "expect" | ||
| target = "cfg(not(windows))" |
There was a problem hiding this comment.
[P2] Restore the non-Windows visibility override
The installer now calls fs_err::rename directly on non-Windows, so with_retry_sync still has no production callers outside uv_fs on Linux; its external callers in uv-install-wheel are under #[cfg(not(unix))]. Removing this expectation exposes hawk::unnecessary_public in the Linux CI job, which runs Hawk with -D warnings. Restore this platform-specific override, since the Windows callers still require public visibility.
| fs_err::copy(&source, staged.path().join(name))?; | ||
| } |
There was a problem hiding this comment.
[P2] Recheck source identity after staging the distribution
When /a/uv self install --install-dir /b races with another native installation into /a, the processes hold different destination locks. The other installer can replace /a/uv after the identity check but before this copy. fs_err::copy reopens the pathname, so the retained handle does not prevent copying the replacement binary while recording the running process's CARGO_PKG_VERSION in the receipt. Recheck the source pathname against the retained identity after staging, and reject a changed source before committing any destination files.
| fs_err::rename(&previous, target) | ||
| .context("Failed to restore the previous executable")?; |
There was a problem hiding this comment.
[P2] Preserve the backup when executable restoration fails
If publishing the staged executable fails and the rollback rename also fails, this ? drops backup before backup.keep() is reached. TempDir cleanup can then delete the previous executable, removing the recoverable copy precisely when restoration failed. Retain the backup on the rollback-error path and include its location in the error; allow automatic cleanup only after successful restoration.
Standalone installation currently delegates executable placement and installation metadata to generated scripts. Add
uv self installbehind theself-managementpreview feature so a downloaded distribution can install its ownuv,uvx, and Windowsuvwexecutables. Managed installations record their location andPATHpreference beside the executables; unmanaged installations omit the receipt and shell changes. An adjacent receipt can identify an installation even when itsuvexecutable needs to be restored. The existing release and self-update paths remain unchanged.