Files
uv/crates/puffin-installer/src/cache.rs
T
konsti de9e85978b Fix tempdir rename (#94)
This fixes two bugs on linux:

`/tmp` and `$HOME` are technically on two different partitions on my
machine, which means that rename-as-atomic-dir-write doesn't work. The
solution is to create the temp dir in the target directory.

zip files may contain directory entries, we can't create files for them
but need to create directories. We could skip them though because iirc
they are not in the RECORD so they won't be uninstalled.
2023-10-12 18:47:38 +00:00

38 lines
922 B
Rust

use std::path::{Path, PathBuf};
static WHEEL_CACHE: &str = "wheels-v0";
#[derive(Debug)]
pub(crate) struct WheelCache {
root: PathBuf,
}
impl WheelCache {
/// Create a handle to the wheel cache.
pub(crate) fn new(root: &Path) -> Self {
Self {
root: root.join(WHEEL_CACHE),
}
}
/// Return the path at which a given wheel would be stored.
pub(crate) fn entry(&self, id: &str) -> PathBuf {
self.root.join(id)
}
/// Initialize the wheel cache.
pub(crate) async fn init(&self) -> std::io::Result<()> {
tokio::fs::create_dir_all(&self.root).await
}
/// Returns a handle to the wheel cache directory.
pub(crate) async fn read_dir(&self) -> std::io::Result<tokio::fs::ReadDir> {
tokio::fs::read_dir(&self.root).await
}
/// Returns the cache root.
pub(crate) fn root(&self) -> &Path {
&self.root
}
}