Commit 2b852d77 authored by Alexis Janon's avatar Alexis Janon
Browse files

cleanup: changed match to if let in CreateDir and RemoveDir

Changed `return match { Ok(_) => no_error_code, err => err }`
to `if let Err(err) { return Err(err) }; no_error_code`
This may be less idiomatic (not sure) but is much nicer to read and
understand (at least to me)
parent 5a04aad1
Pipeline #4067 failed with stage
in 2 minutes and 24 seconds
......@@ -21,51 +21,51 @@ impl CreateDir {
impl Command for CreateDir {
fn exec(&mut self) -> Result<CommandResult> {
debug!("Creating directory {}", self.path.display());
match self.controllers.check_path(&self.path) {
Ok(_) => match fs::create_dir(&self.path) {
Err(ref err) if err.kind() == io::ErrorKind::AlreadyExists => {
warn!(
"Could not create directory {}: already exists",
self.path.display()
);
Ok(())
}
other => other,
}.map(CommandResult::from)
.map_err(|err| {
Error::from(format!(
"Could not create directory {}: {}",
self.path.display(),
err.to_string()
))
}),
err => err,
if let Err(err) = self.controllers.check_path(&self.path) {
return Err(err);
}
match fs::create_dir(&self.path) {
Err(ref err) if err.kind() == io::ErrorKind::AlreadyExists => {
warn!(
"Could not create directory {}: already exists",
self.path.display()
);
Ok(())
}
other => other,
}.map(CommandResult::from)
.map_err(|err| {
Error::from(format!(
"Could not create directory {}: {}",
self.path.display(),
err.to_string()
))
})
}
fn rollback(&mut self) -> Result<CommandResult> {
debug!("{{rollback}} Removing directory {}", self.path.display());
match self.controllers.check_path(&self.path) {
Ok(_) => match fs::remove_dir(&self.path) {
Err(ref err) if err.kind() == io::ErrorKind::NotFound => {
warn!(
"{{rollback}} Could not remove directory {}: not found",
self.path.display()
);
Ok(())
}
other => other,
}.map(CommandResult::from)
.map_err(Error::from)
.map_err(|err| {
Error::from(format!(
"{{rollback}} Could not remove directory {}: {}",
self.path.display(),
err.to_string()
))
}),
err => err,
if let Err(err) = self.controllers.check_path(&self.path) {
return Err(err);
}
match fs::remove_dir(&self.path) {
Err(ref err) if err.kind() == io::ErrorKind::NotFound => {
warn!(
"{{rollback}} Could not remove directory {}: not found",
self.path.display()
);
Ok(())
}
other => other,
}.map(CommandResult::from)
.map_err(Error::from)
.map_err(|err| {
Error::from(format!(
"{{rollback}} Could not remove directory {}: {}",
self.path.display(),
err.to_string()
))
})
}
}
......
......@@ -22,51 +22,51 @@ impl RemoveDir {
impl Command for RemoveDir {
fn exec(&mut self) -> Result<CommandResult> {
debug!("Removing directory {}", self.path.display());
match self.controllers.check_path(&self.path) {
Ok(_) => match fs::remove_dir(&self.path) {
Err(ref err) if err.kind() == io::ErrorKind::NotFound => {
warn!(
"Could not remove directory {}: not found",
self.path.display()
);
Ok(())
}
other => other,
}.map(CommandResult::from)
.map_err(Error::from)
.map_err(|err| {
Error::from(format!(
"Could not remove directory {}: {}",
self.path.display(),
err.to_string()
))
}),
err => err,
if let Err(err) = self.controllers.check_path(&self.path) {
return Err(err);
}
match fs::remove_dir(&self.path) {
Err(ref err) if err.kind() == io::ErrorKind::NotFound => {
warn!(
"Could not remove directory {}: not found",
self.path.display()
);
Ok(())
}
other => other,
}.map(CommandResult::from)
.map_err(Error::from)
.map_err(|err| {
Error::from(format!(
"Could not remove directory {}: {}",
self.path.display(),
err.to_string()
))
})
}
fn rollback(&mut self) -> Result<CommandResult> {
debug!("{{rollback}} Creating directory {}", self.path.display());
match self.controllers.check_path(&self.path) {
Ok(_) => match fs::create_dir(&self.path) {
Err(ref err) if err.kind() == io::ErrorKind::AlreadyExists => {
warn!(
"{{rollback}} Could not create directory {}: already exists",
self.path.display()
);
Ok(())
}
other => other,
}.map(CommandResult::from)
.map_err(|err| {
Error::from(format!(
"{{rollback}} Could not create directory {}: {}",
self.path.display(),
err.to_string()
))
}),
err => err,
if let Err(err) = self.controllers.check_path(&self.path) {
return Err(err);
}
match fs::create_dir(&self.path) {
Err(ref err) if err.kind() == io::ErrorKind::AlreadyExists => {
warn!(
"{{rollback}} Could not create directory {}: already exists",
self.path.display()
);
Ok(())
}
other => other,
}.map(CommandResult::from)
.map_err(|err| {
Error::from(format!(
"{{rollback}} Could not create directory {}: {}",
self.path.display(),
err.to_string()
))
})
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment