Use fs-err in more crates (#100)

Closes https://github.com/astral-sh/puffin/issues/88.
This commit is contained in:
Charlie Marsh 2023-10-16 09:37:58 -04:00 committed by GitHub
parent fa2fd14587
commit 7e8ffeb2df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 33 additions and 14 deletions

7
Cargo.lock generated
View file

@ -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",

View file

@ -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;

View file

@ -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 }

View file

@ -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;

View file

@ -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 }

View file

@ -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()))?;
}

View file

@ -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;

View file

@ -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,

View file

@ -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 }

View file

@ -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::ReadDir> {
tokio::fs::read_dir(&self.root).await
pub(crate) async fn read_dir(&self) -> std::io::Result<fs::ReadDir> {
fs::read_dir(&self.root).await
}
/// Returns the cache root.

View file

@ -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.

View file

@ -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 }

View file

@ -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<Self> {
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())? {