mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25:00 +00:00
Lock the toolchains directory during toolchain operations (#4733)
This commit is contained in:
parent
a380e8e4df
commit
c8987269ff
4 changed files with 14 additions and 1 deletions
|
@ -19,7 +19,7 @@ use crate::platform::{Arch, Libc, Os};
|
||||||
use crate::python_version::PythonVersion;
|
use crate::python_version::PythonVersion;
|
||||||
use crate::toolchain::{self, ToolchainKey};
|
use crate::toolchain::{self, ToolchainKey};
|
||||||
use crate::ToolchainRequest;
|
use crate::ToolchainRequest;
|
||||||
use uv_fs::Simplified;
|
use uv_fs::{LockedFile, Simplified};
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
@ -65,6 +65,14 @@ impl InstalledToolchains {
|
||||||
Self { root: root.into() }
|
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:
|
/// Prefer, in order:
|
||||||
/// 1. The specific toolchain directory specified by the user, i.e., `UV_TOOLCHAIN_DIR`
|
/// 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`
|
/// 2. A directory in the system-appropriate user-level data directory, e.g., `~/.local/uv/toolchains`
|
||||||
|
@ -224,6 +232,7 @@ impl InstalledToolchain {
|
||||||
Ok(Self { path, key })
|
Ok(Self { path, key })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The path to this toolchain's Python executable.
|
||||||
pub fn executable(&self) -> PathBuf {
|
pub fn executable(&self) -> PathBuf {
|
||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
self.path.join("install").join("python.exe")
|
self.path.join("install").join("python.exe")
|
||||||
|
@ -234,6 +243,7 @@ impl InstalledToolchain {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The [`PythonVersion`] of the toolchain.
|
||||||
pub fn version(&self) -> PythonVersion {
|
pub fn version(&self) -> PythonVersion {
|
||||||
self.key.version()
|
self.key.version()
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,6 +122,7 @@ impl Toolchain {
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let toolchains = InstalledToolchains::from_settings()?.init()?;
|
let toolchains = InstalledToolchains::from_settings()?.init()?;
|
||||||
let toolchain_dir = toolchains.root();
|
let toolchain_dir = toolchains.root();
|
||||||
|
let _lock = toolchains.acquire_lock()?;
|
||||||
|
|
||||||
let download = PythonDownload::from_request(&request)?;
|
let download = PythonDownload::from_request(&request)?;
|
||||||
let client = client_builder.build();
|
let client = client_builder.build();
|
||||||
|
|
|
@ -31,6 +31,7 @@ pub(crate) async fn install(
|
||||||
|
|
||||||
let toolchains = InstalledToolchains::from_settings()?.init()?;
|
let toolchains = InstalledToolchains::from_settings()?.init()?;
|
||||||
let toolchain_dir = toolchains.root();
|
let toolchain_dir = toolchains.root();
|
||||||
|
let _lock = toolchains.acquire_lock()?;
|
||||||
|
|
||||||
let requests: Vec<_> = if targets.is_empty() {
|
let requests: Vec<_> = if targets.is_empty() {
|
||||||
if let Some(requests) = requests_from_version_file().await? {
|
if let Some(requests) = requests_from_version_file().await? {
|
||||||
|
|
|
@ -23,6 +23,7 @@ pub(crate) async fn uninstall(
|
||||||
}
|
}
|
||||||
|
|
||||||
let toolchains = InstalledToolchains::from_settings()?.init()?;
|
let toolchains = InstalledToolchains::from_settings()?.init()?;
|
||||||
|
let _lock = toolchains.acquire_lock()?;
|
||||||
|
|
||||||
let requests = targets
|
let requests = targets
|
||||||
.iter()
|
.iter()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue