Skip to content

Commit b7803ad

Browse files
committed
use cutome remove_file and remove_dir_all instead of map_err everywhere
1 parent d0d7344 commit b7803ad

File tree

8 files changed

+21
-26
lines changed

8 files changed

+21
-26
lines changed

src/build.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::cmd::{Command, MountKind, Runnable, SandboxBuilder};
22
use crate::prepare::Prepare;
33
use crate::{Crate, Toolchain, Workspace};
44
use failure::Error;
5-
use remove_dir_all::remove_dir_all;
65
use std::path::PathBuf;
76
use std::vec::Vec;
87

@@ -146,8 +145,7 @@ impl BuildDirectory {
146145
) -> Result<R, Error> {
147146
let source_dir = self.source_dir();
148147
if source_dir.exists() {
149-
remove_dir_all(&source_dir)
150-
.map_err(|error| crate::utils::improve_remove_error(error, &source_dir))?;
148+
crate::utils::remove_dir_all(&source_dir)?;
151149
}
152150

153151
let mut prepare = Prepare::new(&self.workspace, toolchain, krate, &source_dir, patches);
@@ -160,17 +158,15 @@ impl BuildDirectory {
160158
sandbox,
161159
})?;
162160

163-
remove_dir_all(&source_dir)
164-
.map_err(|error| crate::utils::improve_remove_error(error, &source_dir))?;
161+
crate::utils::remove_dir_all(&source_dir)?;
165162
Ok(res)
166163
}
167164

168165
/// Remove all the contents of the build directory, freeing disk space.
169166
pub fn purge(&mut self) -> Result<(), Error> {
170167
let build_dir = self.build_dir();
171168
if build_dir.exists() {
172-
remove_dir_all(&build_dir)
173-
.map_err(|error| crate::utils::improve_remove_error(error, &build_dir))?;
169+
crate::utils::remove_dir_all(&build_dir)?;
174170
}
175171
Ok(())
176172
}

src/crates/cratesio.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::Workspace;
33
use failure::Error;
44
use flate2::read::GzDecoder;
55
use log::info;
6-
use remove_dir_all::remove_dir_all;
76
use std::fs::File;
87
use std::io::{BufReader, BufWriter, Read};
98
use std::path::{Path, PathBuf};
@@ -62,8 +61,7 @@ impl CrateTrait for CratesIOCrate {
6261
fn purge_from_cache(&self, workspace: &Workspace) -> Result<(), Error> {
6362
let path = self.cache_path(workspace);
6463
if path.exists() {
65-
std::fs::remove_file(&path)
66-
.map_err(|error| crate::utils::improve_remove_error(error, &path))?;
64+
crate::utils::remove_file(&path)?;
6765
}
6866
Ok(())
6967
}
@@ -80,7 +78,7 @@ impl CrateTrait for CratesIOCrate {
8078
dest.display()
8179
);
8280
if let Err(err) = unpack_without_first_dir(&mut tar, dest) {
83-
let _ = remove_dir_all(dest);
81+
let _ = crate::utils::remove_dir_all(dest);
8482
Err(err
8583
.context(format!(
8684
"unable to download {} version {}",

src/crates/git.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ impl CrateTrait for GitRepo {
121121
fn purge_from_cache(&self, workspace: &Workspace) -> Result<(), Error> {
122122
let path = self.cached_path(workspace);
123123
if path.exists() {
124-
remove_dir_all::remove_dir_all(&path)
125-
.map_err(|error| crate::utils::improve_remove_error(error, &path))?;
124+
crate::utils::remove_dir_all(&path)?;
126125
}
127126
Ok(())
128127
}

src/crates/local.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ mod tests {
145145
println!("{} should cause copy to fail", bad_link.display());
146146
assert_copy_err_has_filename();
147147

148-
fs::remove_file(&bad_link)
149-
.map_err(|error| crate::utils::improve_remove_error(error, &bad_link))?;
148+
crate::utils::remove_file(&bad_link)?;
150149
// make sure it works without that link
151150
super::copy_dir(tmp_src.path(), tmp_dest.path())?;
152151

src/crates/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mod local;
55
use crate::Workspace;
66
use failure::Error;
77
use log::info;
8-
use remove_dir_all::remove_dir_all;
98
use std::path::Path;
109

1110
trait CrateTrait: std::fmt::Display {
@@ -69,8 +68,7 @@ impl Crate {
6968
"crate source directory {} already exists, cleaning it up",
7069
dest.display()
7170
);
72-
remove_dir_all(dest)
73-
.map_err(|error| crate::utils::improve_remove_error(error, dest))?;
71+
crate::utils::remove_dir_all(dest)?;
7472
}
7573
self.as_trait().copy_source_to(workspace, dest)
7674
}

src/prepare.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::cmd::Command;
22
use crate::{build::CratePatch, Crate, Toolchain, Workspace};
33
use failure::{Error, Fail, ResultExt};
44
use log::info;
5-
use std::fs::remove_file;
65
use std::path::Path;
76
use toml::{
87
value::{Array, Table},
@@ -73,7 +72,7 @@ impl<'a> Prepare<'a> {
7372
fn remove_cargo_config(&self) -> Result<(), Error> {
7473
let path = self.source_dir.join(".cargo").join("config");
7574
if path.exists() {
76-
remove_file(&path).map_err(|error| crate::utils::improve_remove_error(error, &path))?;
75+
crate::utils::remove_file(&path)?;
7776
info!("removed {}", path.display());
7877
}
7978
Ok(())

src/utils.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ fn strip_verbatim_from_prefix(prefix: &PrefixComponent<'_>) -> Option<PathBuf> {
5050
Some(ret)
5151
}
5252

53+
pub(crate) fn remove_file(path: &Path) -> std::io::Result<()> {
54+
std::fs::remove_file(&path).map_err(|error| crate::utils::improve_remove_error(error, &path))
55+
}
56+
57+
pub(crate) fn remove_dir_all(path: &Path) -> std::io::Result<()> {
58+
remove_dir_all::remove_dir_all(path)
59+
.map_err(|error| crate::utils::improve_remove_error(error, path))
60+
}
61+
5362
#[derive(Debug)]
5463
struct RemoveError {
5564
kind: std::io::ErrorKind,
@@ -68,7 +77,7 @@ impl std::fmt::Display for RemoveError {
6877
}
6978
}
7079

71-
pub(crate) fn improve_remove_error(error: std::io::Error, path: &Path) -> std::io::Error {
80+
fn improve_remove_error(error: std::io::Error, path: &Path) -> std::io::Error {
7281
std::io::Error::new(
7382
error.kind(),
7483
RemoveError {

src/workspace.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::inside_docker::CurrentContainer;
44
use crate::Toolchain;
55
use failure::{Error, ResultExt};
66
use log::info;
7-
use remove_dir_all::remove_dir_all;
87
use std::path::{Path, PathBuf};
98
use std::sync::Arc;
109
use std::time::Duration;
@@ -213,8 +212,7 @@ impl Workspace {
213212
pub fn purge_all_build_dirs(&self) -> Result<(), Error> {
214213
let dir = self.builds_dir();
215214
if dir.exists() {
216-
remove_dir_all(&dir)
217-
.map_err(|error| crate::utils::improve_remove_error(error, &dir))?;
215+
crate::utils::remove_dir_all(&dir)?;
218216
}
219217
Ok(())
220218
}
@@ -237,8 +235,7 @@ impl Workspace {
237235

238236
for path in &paths {
239237
if path.exists() {
240-
remove_dir_all(&path)
241-
.map_err(|error| crate::utils::improve_remove_error(error, &path))?;
238+
crate::utils::remove_dir_all(&path)?;
242239
}
243240
}
244241

0 commit comments

Comments
 (0)