Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock the toolchains directory during toolchain operations #4733

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion crates/uv-toolchain/src/managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::platform::{Arch, Libc, Os};
use crate::python_version::PythonVersion;
use crate::toolchain::{self, ToolchainKey};
use crate::ToolchainRequest;
use uv_fs::Simplified;
use uv_fs::{LockedFile, Simplified};

#[derive(Error, Debug)]
pub enum Error {
Expand Down Expand Up @@ -65,6 +65,14 @@ impl InstalledToolchains {
Self { root: root.into() }
}

/// Lock the toolchains directory.
pub fn acquire_lock(&self) -> Result<LockedFile, Error> {
Ok(LockedFile::acquire(
self.root.join(".lock"),
self.root.user_display(),
)?)
}

/// Prefer, in order:
/// 1. The specific toolchain directory specified by the user, i.e., `UV_TOOLCHAIN_DIR`
/// 2. A directory in the system-appropriate user-level data directory, e.g., `~/.local/uv/toolchains`
Expand Down Expand Up @@ -224,6 +232,7 @@ impl InstalledToolchain {
Ok(Self { path, key })
}

/// The path to this toolchain's Python executable.
pub fn executable(&self) -> PathBuf {
if cfg!(windows) {
self.path.join("install").join("python.exe")
Expand All @@ -234,6 +243,7 @@ impl InstalledToolchain {
}
}

/// The [`PythonVersion`] of the toolchain.
pub fn version(&self) -> PythonVersion {
self.key.version()
}
Expand Down
1 change: 1 addition & 0 deletions crates/uv-toolchain/src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ impl Toolchain {
) -> Result<Self, Error> {
let toolchains = InstalledToolchains::from_settings()?.init()?;
let toolchain_dir = toolchains.root();
let _lock = toolchains.acquire_lock()?;

let download = PythonDownload::from_request(&request)?;
let client = client_builder.build();
Expand Down
1 change: 1 addition & 0 deletions crates/uv/src/commands/toolchain/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub(crate) async fn install(

let toolchains = InstalledToolchains::from_settings()?.init()?;
let toolchain_dir = toolchains.root();
let _lock = toolchains.acquire_lock()?;

let requests: Vec<_> = if targets.is_empty() {
if let Some(requests) = requests_from_version_file().await? {
Expand Down
1 change: 1 addition & 0 deletions crates/uv/src/commands/toolchain/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(crate) async fn uninstall(
}

let toolchains = InstalledToolchains::from_settings()?.init()?;
let _lock = toolchains.acquire_lock()?;

let requests = targets
.iter()
Expand Down
Loading