From fe65331660dab27af0f6a4c76a5e3589ba96be9e Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Thu, 13 Jul 2023 10:22:00 -0700 Subject: [PATCH] use fs-err in turborepo fs related libs --- Cargo.lock | 8 ++++++++ crates/turborepo-fs/Cargo.toml | 1 + crates/turborepo-fs/src/lib.rs | 5 +++-- crates/turborepo-paths/Cargo.toml | 1 + crates/turborepo-paths/src/absolute_system_path.rs | 3 ++- crates/turborepo-paths/src/absolute_system_path_buf.rs | 6 ++++-- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bade5c59c66e3..60c451d56000a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2515,6 +2515,12 @@ dependencies = [ "syn 2.0.25", ] +[[package]] +name = "fs-err" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0845fa252299212f0389d64ba26f34fa32cfe41588355f21ed507c59a0f64541" + [[package]] name = "fs_extra" version = "1.3.0" @@ -9551,6 +9557,7 @@ dependencies = [ "anyhow", "camino", "dunce", + "fs-err", "path-clean 1.0.1", "serde", "test-case", @@ -9643,6 +9650,7 @@ name = "turborepo-fs" version = "0.1.0" dependencies = [ "anyhow", + "fs-err", "tempfile", "turbopath", "walkdir", diff --git a/crates/turborepo-fs/Cargo.toml b/crates/turborepo-fs/Cargo.toml index 844418c703d0d..a841cdb2318d2 100644 --- a/crates/turborepo-fs/Cargo.toml +++ b/crates/turborepo-fs/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] anyhow = { workspace = true } +fs-err = "2.9.0" turbopath = { workspace = true } walkdir = "2.3.3" diff --git a/crates/turborepo-fs/src/lib.rs b/crates/turborepo-fs/src/lib.rs index 1cbfed057de84..beaf3f0e526e2 100644 --- a/crates/turborepo-fs/src/lib.rs +++ b/crates/turborepo-fs/src/lib.rs @@ -1,6 +1,7 @@ -use std::fs::{self, DirBuilder, Metadata}; +use std::fs::{DirBuilder, FileType, Metadata}; use anyhow::Result; +use fs_err as fs; use turbopath::{AbsoluteSystemPath, AnchoredSystemPathBuf}; use walkdir::WalkDir; @@ -89,7 +90,7 @@ pub fn copy_file( fn copy_file_with_type( from: impl AsRef, - from_type: fs::FileType, + from_type: FileType, to: impl AsRef, ) -> Result<()> { let from = from.as_ref(); diff --git a/crates/turborepo-paths/Cargo.toml b/crates/turborepo-paths/Cargo.toml index dc5e433bf72cc..20c1be0237006 100644 --- a/crates/turborepo-paths/Cargo.toml +++ b/crates/turborepo-paths/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" [dependencies] camino = { workspace = true } dunce = { workspace = true } +fs-err = "2.9.0" path-clean = "1.0.1" # TODO: Make this a crate feature serde = { workspace = true } diff --git a/crates/turborepo-paths/src/absolute_system_path.rs b/crates/turborepo-paths/src/absolute_system_path.rs index a10d6e5b1e307..e9fd3e0d4f1a5 100644 --- a/crates/turborepo-paths/src/absolute_system_path.rs +++ b/crates/turborepo-paths/src/absolute_system_path.rs @@ -5,13 +5,14 @@ use std::os::unix::fs::symlink as symlink_dir; #[cfg(windows)] use std::os::windows::fs::{symlink_dir, symlink_file}; use std::{ - fmt, fs, + fmt, fs::{File, Metadata, OpenOptions}, io, path::Path, }; use camino::{Utf8Component, Utf8Components, Utf8Path, Utf8PathBuf}; +use fs_err as fs; use path_clean::PathClean; use crate::{ diff --git a/crates/turborepo-paths/src/absolute_system_path_buf.rs b/crates/turborepo-paths/src/absolute_system_path_buf.rs index 0e7e48ee01e43..d25de5a14980f 100644 --- a/crates/turborepo-paths/src/absolute_system_path_buf.rs +++ b/crates/turborepo-paths/src/absolute_system_path_buf.rs @@ -1,12 +1,13 @@ use std::{ borrow::Borrow, - fmt, fs, + fmt, io::{self, Write}, ops::Deref, path::{Path, PathBuf}, }; use camino::{Utf8Components, Utf8Path, Utf8PathBuf}; +use fs_err as fs; use path_clean::PathClean; use serde::Serialize; @@ -233,7 +234,8 @@ impl AbsoluteSystemPathBuf { } pub fn try_exists(&self) -> Result { - Ok(fs::try_exists(&self.0)?) + // try_exists is an experimental API and not yet in fs_err + Ok(std::fs::try_exists(&self.0)?) } pub fn extension(&self) -> Option<&str> {