]> git.lizzy.rs Git - rust.git/commitdiff
Replace custom `not_bash::fs2` setup with fs_err crate
authorVeetaha <veetaha2@gmail.com>
Sat, 29 Aug 2020 14:47:13 +0000 (17:47 +0300)
committerVeetaha <veetaha2@gmail.com>
Sat, 29 Aug 2020 14:47:13 +0000 (17:47 +0300)
Cargo.lock
xtask/Cargo.toml
xtask/src/dist.rs
xtask/src/not_bash.rs

index 867a6c1dcdde3e606d77f1d1f167c31923d93c9f..cec4462f2045429574028263e68f24f9aefd981a 100644 (file)
@@ -385,6 +385,12 @@ dependencies = [
  "toolchain",
 ]
 
+[[package]]
+name = "fs-err"
+version = "2.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1a51f8b7158efbe531f7baa74e38e49fbc41239e5d66720bb37ed39c27c241a"
+
 [[package]]
 name = "fsevent"
 version = "2.0.2"
@@ -1875,6 +1881,7 @@ version = "0.1.0"
 dependencies = [
  "anyhow",
  "flate2",
+ "fs-err",
  "pico-args",
  "proc-macro2",
  "quote",
index 0750b5657fb30df191f087e15daba5f0370c2424..01a8388253876cac635950159cab1a1b38ae370f 100644 (file)
@@ -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
index 01d903cdee7de3e83eb645e663b45be6ad893d20..aa7d949677dc0d3ac6f525d012e09d7cc9844921 100644 (file)
@@ -115,7 +115,7 @@ fn replace(&mut self, from: &str, to: &str) -> &mut Patch {
         self
     }
 
-    fn commit(&self) -> Result<()> {
+    fn commit(&self) -> io::Result<()> {
         fs2::write(&self.path, &self.contents)
     }
 }
index ef811e5bf34b0853be200495017d031e76712335..038898993ac046cea756fefa0851b02d379d19ab 100644 (file)
@@ -4,55 +4,14 @@
     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<P: AsRef<Path>>(path: P) -> Result<fs::ReadDir> {
-        let path = path.as_ref();
-        fs::read_dir(path).with_context(|| format!("Failed to read {}", path.display()))
-    }
-
-    pub fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String> {
-        let path = path.as_ref();
-        fs::read_to_string(path).with_context(|| format!("Failed to read {}", path.display()))
-    }
-
-    pub fn write<P: AsRef<Path>, 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<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> {
-        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<P: AsRef<Path>>(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<P: AsRef<Path>>(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<P: AsRef<Path>>(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 @@ fn drop(&mut self) {
     }
 }
 
-pub fn rm_rf(path: impl AsRef<Path>) -> Result<()> {
+pub fn rm_rf(path: impl AsRef<Path>) -> io::Result<()> {
     let path = path.as_ref();
     if !path.exists() {
         return Ok(());