From 3f675179e5566514fde2730c0a8b47195a688d6d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 14 Feb 2020 18:56:07 +0100 Subject: Add fs2 module for better error messages --- xtask/src/not_bash.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'xtask/src/not_bash.rs') diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs index 56d6c6c2d..027571b62 100644 --- a/xtask/src/not_bash.rs +++ b/xtask/src/not_bash.rs @@ -10,6 +10,29 @@ use std::{ 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 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())) + } +} + macro_rules! _run { ($($expr:expr),*) => { run!($($expr),*; echo = true) -- cgit v1.2.3