Avoid panic with missing temporary directory (#6929)

Forward an error for missing temp directories:

```
$ env TMPDIR=.tmp uv-debug pip install httpx
  error: No such file or directory (os error 2) at path "/home/konsti/projects/uv/.tmp/.tmpgIBhhh"
```

Fixes #6878
This commit is contained in:
konsti 2024-09-02 09:32:42 +02:00 committed by GitHub
parent 7e6df8ffd4
commit 9edf2d8132
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 14 additions and 10 deletions

View File

@ -1,5 +1,6 @@
use std::collections::BTreeMap;
use std::fmt::Debug;
use std::io;
use std::path::PathBuf;
use std::str::FromStr;
@ -145,14 +146,16 @@ impl<'a> RegistryClientBuilder<'a> {
}
}
impl<'a> From<BaseClientBuilder<'a>> for RegistryClientBuilder<'a> {
fn from(value: BaseClientBuilder<'a>) -> Self {
Self {
impl<'a> TryFrom<BaseClientBuilder<'a>> for RegistryClientBuilder<'a> {
type Error = io::Error;
fn try_from(value: BaseClientBuilder<'a>) -> Result<Self, Self::Error> {
Ok(Self {
index_urls: IndexUrls::default(),
index_strategy: IndexStrategy::default(),
cache: Cache::temp().unwrap(),
cache: Cache::temp()?,
base_client_builder: value,
}
})
}
}

View File

@ -277,7 +277,7 @@ pub(crate) async fn pip_compile(
}
// Initialize the registry client.
let client = RegistryClientBuilder::from(client_builder)
let client = RegistryClientBuilder::try_from(client_builder)?
.cache(cache.clone())
.index_urls(index_locations.index_urls())
.index_strategy(index_strategy)

View File

@ -270,7 +270,7 @@ pub(crate) async fn pip_install(
}
// Initialize the registry client.
let client = RegistryClientBuilder::from(client_builder)
let client = RegistryClientBuilder::try_from(client_builder)?
.cache(cache.clone())
.index_urls(index_locations.index_urls())
.index_strategy(index_strategy)

View File

@ -220,7 +220,7 @@ pub(crate) async fn pip_sync(
}
// Initialize the registry client.
let client = RegistryClientBuilder::from(client_builder)
let client = RegistryClientBuilder::try_from(client_builder)?
.cache(cache.clone())
.index_urls(index_locations.index_urls())
.index_strategy(index_strategy)

View File

@ -257,7 +257,7 @@ pub(crate) async fn add(
}
// Initialize the registry client.
let client = RegistryClientBuilder::from(client_builder)
let client = RegistryClientBuilder::try_from(client_builder)?
.index_urls(settings.index_locations.index_urls())
.index_strategy(settings.index_strategy)
.markers(&markers)

View File

@ -249,7 +249,8 @@ async fn venv_impl(
}
// Instantiate a client.
let client = RegistryClientBuilder::from(client_builder)
let client = RegistryClientBuilder::try_from(client_builder)
.into_diagnostic()?
.cache(cache.clone())
.index_urls(index_locations.index_urls())
.index_strategy(index_strategy)