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/lib.rs | 10 +++++----- xtask/src/not_bash.rs | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 4050f9d01..cebb14abc 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -17,7 +17,7 @@ use std::{ use crate::{ codegen::Mode, - not_bash::{pushd, run}, + not_bash::{fs2, pushd, run}, }; pub use anyhow::Result; @@ -167,11 +167,11 @@ pub fn run_release(dry_run: bool) -> Result<()> { } let website_root = project_root().join("../rust-analyzer.github.io"); - let changelog_dir = website_root.join("/thisweek/_posts"); + let changelog_dir = website_root.join("./thisweek/_posts"); let today = run!("date --iso")?; let commit = run!("git rev-parse HEAD")?; - let changelog_n = fs::read_dir(changelog_dir.as_path())?.count(); + let changelog_n = fs2::read_dir(changelog_dir.as_path())?.count(); let contents = format!( "\ @@ -194,9 +194,9 @@ Release: release:{}[] ); let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n)); - fs::write(&path, &contents)?; + fs2::write(&path, &contents)?; - fs::copy(project_root().join("./docs/user/readme.adoc"), website_root.join("manual.adoc"))?; + fs2::copy(project_root().join("./docs/user/readme.adoc"), website_root.join("manual.adoc"))?; Ok(()) } 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