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,8 +21,10 @@ 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) {
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",
......@@ -38,15 +40,15 @@ impl Command for CreateDir {
self.path.display(),
err.to_string()
))
}),
err => err,
}
})
}
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) {
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",
......@@ -63,9 +65,7 @@ impl Command for CreateDir {
self.path.display(),
err.to_string()
))
}),
err => err,
}
})
}
}
......
......@@ -22,8 +22,10 @@ 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) {
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",
......@@ -40,15 +42,15 @@ impl Command for RemoveDir {
self.path.display(),
err.to_string()
))
}),
err => err,
}
})
}
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) {
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",
......@@ -64,9 +66,7 @@ impl Command for RemoveDir {
self.path.display(),
err.to_string()
))
}),
err => err,
}
})
}
}
......
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