Skip to content

Commit ac4b134

Browse files
bors[bot]Veetaha
andauthored
Merge #5914
5914: Replace custom `xtask::not_bash::fs2` setup with fs_err crate r=matklad a=Veetaha Co-authored-by: Veetaha <veetaha2@gmail.com>
2 parents dd685d0 + 4bc56eb commit ac4b134

File tree

4 files changed

+12
-45
lines changed

4 files changed

+12
-45
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xtask/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ quote = "1.0.2"
1818
ungrammar = "1.1.3"
1919
walkdir = "2.3.1"
2020
write-json = "0.1.0"
21+
fs-err = "2.3"
2122
# Avoid adding more dependencies to this crate

xtask/src/dist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl Patch {
115115
self
116116
}
117117

118-
fn commit(&self) -> Result<()> {
118+
fn commit(&self) -> io::Result<()> {
119119
fs2::write(&self.path, &self.contents)
120120
}
121121
}

xtask/src/not_bash.rs

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,14 @@ use std::{
44
cell::RefCell,
55
env,
66
ffi::OsString,
7-
io::Write,
7+
io::{self, Write},
88
path::{Path, PathBuf},
99
process::{Command, Stdio},
1010
};
1111

1212
use anyhow::{bail, Context, Result};
1313

14-
pub mod fs2 {
15-
use std::{fs, path::Path};
16-
17-
use anyhow::{Context, Result};
18-
19-
pub fn read_dir<P: AsRef<Path>>(path: P) -> Result<fs::ReadDir> {
20-
let path = path.as_ref();
21-
fs::read_dir(path).with_context(|| format!("Failed to read {}", path.display()))
22-
}
23-
24-
pub fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String> {
25-
let path = path.as_ref();
26-
fs::read_to_string(path).with_context(|| format!("Failed to read {}", path.display()))
27-
}
28-
29-
pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> {
30-
let path = path.as_ref();
31-
fs::write(path, contents).with_context(|| format!("Failed to write {}", path.display()))
32-
}
33-
34-
pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> {
35-
let from = from.as_ref();
36-
let to = to.as_ref();
37-
fs::copy(from, to)
38-
.with_context(|| format!("Failed to copy {} to {}", from.display(), to.display()))
39-
}
40-
41-
pub fn remove_file<P: AsRef<Path>>(path: P) -> Result<()> {
42-
let path = path.as_ref();
43-
fs::remove_file(path).with_context(|| format!("Failed to remove file {}", path.display()))
44-
}
45-
46-
pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
47-
let path = path.as_ref();
48-
fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display()))
49-
}
50-
51-
pub fn create_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
52-
let path = path.as_ref();
53-
fs::create_dir_all(path).with_context(|| format!("Failed to create dir {}", path.display()))
54-
}
55-
}
14+
pub use fs_err as fs2;
5615

5716
#[macro_export]
5817
macro_rules! run {
@@ -98,7 +57,7 @@ impl Drop for Pushenv {
9857
}
9958
}
10059

101-
pub fn rm_rf(path: impl AsRef<Path>) -> Result<()> {
60+
pub fn rm_rf(path: impl AsRef<Path>) -> io::Result<()> {
10261
let path = path.as_ref();
10362
if !path.exists() {
10463
return Ok(());

0 commit comments

Comments
 (0)