diff --git a/Cargo.lock b/Cargo.lock index 69adc6480..d8eccf1c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -717,6 +717,9 @@ name = "fs-err" version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0845fa252299212f0389d64ba26f34fa32cfe41588355f21ed507c59a0f64541" +dependencies = [ + "tokio", +] [[package]] name = "fs2" @@ -1667,6 +1670,7 @@ checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" name = "platform-host" version = "0.0.1" dependencies = [ + "fs-err", "glibc_version", "goblin", "platform-info", @@ -1812,6 +1816,7 @@ dependencies = [ "clap", "colored", "directories", + "fs-err", "futures", "gourgeist", "indicatif", @@ -1858,6 +1863,7 @@ version = "0.0.1" dependencies = [ "anyhow", "cacache", + "fs-err", "install-wheel-rs", "pep440_rs 0.3.12", "puffin-client", @@ -1879,6 +1885,7 @@ version = "0.0.1" dependencies = [ "anyhow", "cacache", + "fs-err", "pep440_rs 0.3.12", "pep508_rs", "platform-host", diff --git a/crates/install-wheel-rs/src/python_bindings.rs b/crates/install-wheel-rs/src/python_bindings.rs index ebf11bb76..5d83c5371 100644 --- a/crates/install-wheel-rs/src/python_bindings.rs +++ b/crates/install-wheel-rs/src/python_bindings.rs @@ -1,11 +1,11 @@ #![allow(clippy::format_push_string)] // I will not replace clear and infallible with fallible, io looking code use crate::{install_wheel, Error, InstallLocation, LockedDir}; +use fs_err::File; use pyo3::create_exception; use pyo3::types::PyModule; use pyo3::{pyclass, pymethods, pymodule, PyErr, PyResult, Python}; use std::env; -use std::fs::File; use std::path::{Path, PathBuf}; use std::str::FromStr; use wheel_filename::WheelFilename; diff --git a/crates/platform-host/Cargo.toml b/crates/platform-host/Cargo.toml index 243558950..affa6dc42 100644 --- a/crates/platform-host/Cargo.toml +++ b/crates/platform-host/Cargo.toml @@ -10,6 +10,7 @@ authors = { workspace = true } license = { workspace = true } [dependencies] +fs-err = { workspace = true } glibc_version = { workspace = true } goblin = { workspace = true } platform-info = { workspace = true } diff --git a/crates/platform-host/src/lib.rs b/crates/platform-host/src/lib.rs index bec017fc8..57bc080f4 100644 --- a/crates/platform-host/src/lib.rs +++ b/crates/platform-host/src/lib.rs @@ -2,8 +2,9 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; -use std::{fmt, fs, io}; +use std::{fmt, io}; +use fs_err as fs; use goblin::elf::Elf; use platform_info::{PlatformInfo, PlatformInfoAPI, UNameAPI}; use regex::Regex; diff --git a/crates/puffin-cli/Cargo.toml b/crates/puffin-cli/Cargo.toml index 7024fcc26..627311b97 100644 --- a/crates/puffin-cli/Cargo.toml +++ b/crates/puffin-cli/Cargo.toml @@ -26,6 +26,7 @@ cacache = { workspace = true } clap = { workspace = true, features = ["derive"] } colored = { workspace = true } directories = { workspace = true } +fs-err = { workspace = true, features = ["tokio"] } futures = { workspace = true } indicatif = { workspace = true } itertools = { workspace = true } diff --git a/crates/puffin-cli/src/commands/clean.rs b/crates/puffin-cli/src/commands/clean.rs index 01495e315..6e21d5ab8 100644 --- a/crates/puffin-cli/src/commands/clean.rs +++ b/crates/puffin-cli/src/commands/clean.rs @@ -2,6 +2,7 @@ use std::fmt::Write; use std::path::Path; use anyhow::{Context, Result}; +use fs_err::tokio as fs; use tracing::debug; use crate::commands::ExitStatus; @@ -31,11 +32,11 @@ pub(crate) async fn clean(cache: Option<&Path>, mut printer: Printer) -> Result< .flatten() { if entry.file_type()?.is_dir() { - tokio::fs::remove_dir_all(entry.path()) + fs::remove_dir_all(entry.path()) .await .with_context(|| format!("Failed to clear cache at {}", cache.display()))?; } else { - tokio::fs::remove_file(entry.path()) + fs::remove_file(entry.path()) .await .with_context(|| format!("Failed to clear cache at {}", cache.display()))?; } diff --git a/crates/puffin-cli/src/commands/compile.rs b/crates/puffin-cli/src/commands/compile.rs index 48bfd8748..90c5ac9a6 100644 --- a/crates/puffin-cli/src/commands/compile.rs +++ b/crates/puffin-cli/src/commands/compile.rs @@ -1,5 +1,5 @@ +use fs_err::File; use std::fmt::Write; -use std::fs::File; use std::io::{stdout, BufWriter}; use std::path::Path; diff --git a/crates/puffin-cli/src/commands/venv.rs b/crates/puffin-cli/src/commands/venv.rs index f3f6ca61a..6a66c8db7 100644 --- a/crates/puffin-cli/src/commands/venv.rs +++ b/crates/puffin-cli/src/commands/venv.rs @@ -3,6 +3,7 @@ use std::path::Path; use anyhow::Result; use colored::Colorize; +use fs_err::tokio as fs; use crate::commands::ExitStatus; use crate::printer::Printer; @@ -28,8 +29,8 @@ pub(crate) async fn venv( )?; // If the path already exists, remove it. - tokio::fs::remove_file(path).await.ok(); - tokio::fs::remove_dir_all(path).await.ok(); + fs::remove_file(path).await.ok(); + fs::remove_dir_all(path).await.ok(); writeln!( printer, diff --git a/crates/puffin-installer/Cargo.toml b/crates/puffin-installer/Cargo.toml index a83bac679..d8136b7fc 100644 --- a/crates/puffin-installer/Cargo.toml +++ b/crates/puffin-installer/Cargo.toml @@ -19,10 +19,11 @@ wheel-filename = { path = "../wheel-filename" } anyhow = { workspace = true } cacache = { workspace = true } +fs-err = { workspace = true } rayon = { workspace = true } tempfile = { workspace = true } tokio = { workspace = true } tokio-util = { workspace = true } tracing = { workspace = true } url = { workspace = true } -zip = { workspace = true } +zip = { workspace = true } \ No newline at end of file diff --git a/crates/puffin-installer/src/cache.rs b/crates/puffin-installer/src/cache.rs index b7d43e823..788d6a46a 100644 --- a/crates/puffin-installer/src/cache.rs +++ b/crates/puffin-installer/src/cache.rs @@ -1,5 +1,7 @@ use std::path::{Path, PathBuf}; +use fs_err::tokio as fs; + static WHEEL_CACHE: &str = "wheels-v0"; #[derive(Debug)] @@ -22,12 +24,12 @@ impl WheelCache { /// Initialize the wheel cache. pub(crate) async fn init(&self) -> std::io::Result<()> { - tokio::fs::create_dir_all(&self.root).await + 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::read_dir(&self.root).await + pub(crate) async fn read_dir(&self) -> std::io::Result { + fs::read_dir(&self.root).await } /// Returns the cache root. diff --git a/crates/puffin-installer/src/unzipper.rs b/crates/puffin-installer/src/unzipper.rs index cdf46c075..95bfccc4d 100644 --- a/crates/puffin-installer/src/unzipper.rs +++ b/crates/puffin-installer/src/unzipper.rs @@ -1,6 +1,8 @@ use std::path::Path; use anyhow::Result; +use fs_err::tokio as fs; +use fs_err::File; use rayon::iter::ParallelBridge; use rayon::iter::ParallelIterator; use tracing::debug; @@ -55,7 +57,7 @@ impl Unzipper { .await??; // Write the unzipped wheel to the target directory. - tokio::fs::rename( + fs::rename( staging.path().join(remote.id()), wheel_cache.entry(&remote.id()), ) @@ -110,7 +112,7 @@ fn unzip_wheel(wheel: InMemoryDistribution, target: &Path) -> Result<()> { } // Write the file. - let mut outfile = std::fs::File::create(&path)?; + let mut outfile = File::create(&path)?; std::io::copy(&mut file, &mut outfile)?; // Set permissions. diff --git a/crates/puffin-interpreter/Cargo.toml b/crates/puffin-interpreter/Cargo.toml index 72ae2032b..1c8c4f8c7 100644 --- a/crates/puffin-interpreter/Cargo.toml +++ b/crates/puffin-interpreter/Cargo.toml @@ -17,6 +17,7 @@ puffin-package = { path = "../puffin-package" } anyhow = { workspace = true } cacache = { workspace = true } +fs-err = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } diff --git a/crates/puffin-interpreter/src/site_packages.rs b/crates/puffin-interpreter/src/site_packages.rs index 6569cf72c..4c3819699 100644 --- a/crates/puffin-interpreter/src/site_packages.rs +++ b/crates/puffin-interpreter/src/site_packages.rs @@ -3,6 +3,7 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use anyhow::{anyhow, Result}; +use fs_err::tokio as fs; use pep440_rs::Version; use puffin_package::package_name::PackageName; @@ -17,7 +18,7 @@ impl SitePackages { pub async fn from_executable(python: &PythonExecutable) -> Result { let mut index = BTreeMap::new(); - let mut dir = tokio::fs::read_dir(python.site_packages()).await?; + let mut dir = fs::read_dir(python.site_packages()).await?; while let Some(entry) = dir.next_entry().await? { if entry.file_type().await?.is_dir() { if let Some(dist_info) = DistInfo::try_from_path(&entry.path())? {