From 4bc56ebd936cc1b580ef88c40eead2ba3209cdbe Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sat, 29 Aug 2020 17:47:13 +0300 Subject: Replace custom `not_bash::fs2` setup with fs_err crate --- xtask/Cargo.toml | 1 + xtask/src/dist.rs | 2 +- xtask/src/not_bash.rs | 47 +++-------------------------------------------- 3 files changed, 5 insertions(+), 45 deletions(-) (limited to 'xtask') diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 0750b5657..01a838825 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -18,4 +18,5 @@ quote = "1.0.2" ungrammar = "1.1.3" walkdir = "2.3.1" write-json = "0.1.0" +fs-err = "2.3" # Avoid adding more dependencies to this crate diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index 01d903cde..aa7d94967 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs @@ -115,7 +115,7 @@ impl Patch { self } - fn commit(&self) -> Result<()> { + fn commit(&self) -> io::Result<()> { fs2::write(&self.path, &self.contents) } } diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs index ef811e5bf..038898993 100644 --- a/xtask/src/not_bash.rs +++ b/xtask/src/not_bash.rs @@ -4,55 +4,14 @@ use std::{ cell::RefCell, env, ffi::OsString, - io::Write, + io::{self, Write}, path::{Path, PathBuf}, process::{Command, Stdio}, }; use anyhow::{bail, Context, Result}; -pub mod fs2 { - use std::{fs, path::Path}; - - use anyhow::{Context, Result}; - - pub fn read_dir>(path: P) -> Result { - let path = path.as_ref(); - fs::read_dir(path).with_context(|| format!("Failed to read {}", path.display())) - } - - pub fn read_to_string>(path: P) -> Result { - let path = path.as_ref(); - fs::read_to_string(path).with_context(|| format!("Failed to read {}", path.display())) - } - - pub fn write, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> { - let path = path.as_ref(); - fs::write(path, contents).with_context(|| format!("Failed to write {}", path.display())) - } - - pub fn copy, Q: AsRef>(from: P, to: Q) -> Result { - let from = from.as_ref(); - let to = to.as_ref(); - fs::copy(from, to) - .with_context(|| format!("Failed to copy {} to {}", from.display(), to.display())) - } - - pub fn remove_file>(path: P) -> Result<()> { - let path = path.as_ref(); - fs::remove_file(path).with_context(|| format!("Failed to remove file {}", path.display())) - } - - pub fn remove_dir_all>(path: P) -> Result<()> { - let path = path.as_ref(); - fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display())) - } - - pub fn create_dir_all>(path: P) -> Result<()> { - let path = path.as_ref(); - fs::create_dir_all(path).with_context(|| format!("Failed to create dir {}", path.display())) - } -} +pub use fs_err as fs2; #[macro_export] macro_rules! run { @@ -98,7 +57,7 @@ impl Drop for Pushenv { } } -pub fn rm_rf(path: impl AsRef) -> Result<()> { +pub fn rm_rf(path: impl AsRef) -> io::Result<()> { let path = path.as_ref(); if !path.exists() { return Ok(()); -- cgit v1.2.3