Commit 2275dee4 authored by Alexis Janon's avatar Alexis Janon
Browse files

Now display path using path.display instead of debug output

Much cleaner, and more robust as the output should not change (the debug
output may evolve depending on the needs of the upstream developers)
parent 18d1f00f
......@@ -68,7 +68,7 @@ impl SysFsControllerList {
path::Component::ParentDir => if !absolute_path.pop() {
return Err(Error::from(io::Error::new(
io::ErrorKind::PermissionDenied,
format!("Could not access {:?}: permission denied", path),
format!("Could not access {}: permission denied", path.display()),
)));
},
path::Component::Normal(_) => absolute_path.push(&component),
......@@ -78,7 +78,7 @@ impl SysFsControllerList {
match self.is_authorized_path(&absolute_path) {
false => Err(Error::from(io::Error::new(
io::ErrorKind::PermissionDenied,
format!("Could not access {:?}: permission denied", path),
format!("Could not access {}: permission denied", path.display()),
))),
true => Ok(CommandResult::from(())),
}
......
......@@ -34,8 +34,8 @@ impl SliceInfoAnswer {
})?;
let value = fs::read_to_string(&path).map_err(|err| {
Error::from(format!(
"Could not read from file {:?}: {}",
path,
"Could not read from file {}: {}",
path.display(),
err.to_string()
))
})?;
......
......@@ -20,19 +20,22 @@ impl CreateDir {
impl Command for CreateDir {
fn exec(&mut self) -> Result<CommandResult> {
debug!("Creating directory {:?}", self.path);
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);
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,
"Could not create directory {}: {}",
self.path.display(),
err.to_string()
))
}),
......@@ -41,13 +44,13 @@ impl Command for CreateDir {
}
fn rollback(&mut self) -> Result<CommandResult> {
debug!("{{rollback}} Removing directory {:?}", self.path);
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
"{{rollback}} Could not remove directory {}: not found",
self.path.display()
);
Ok(())
}
......@@ -56,8 +59,8 @@ impl Command for CreateDir {
.map_err(Error::from)
.map_err(|err| {
Error::from(format!(
"{{rollback}} Could not remove directory {:?}: {}",
self.path,
"{{rollback}} Could not remove directory {}: {}",
self.path.display(),
err.to_string()
))
}),
......
......@@ -57,28 +57,28 @@ impl Command for FindGetSetValue {
);
let path = match self.path {
Some(ref value) => value,
None => return Err(Error::from(format!("Missing previous value for path {:?}. (probably an internal bug, you should report it)", self.path)))
None => return Err(Error::from(format!("Missing previous value for path {}. (probably an internal bug, you should report it)", self.path.display())))
};
if let Err(err) = self.controllers.check_path(&path) {
return Err(err);
}
trace!("Reading from file {:?}", path);
trace!("Reading from file {}", path.display());
let old_value = fs::read_to_string(path).map_err(|err| {
Error::from(format!(
"Could not read from file {:?}: {}",
path,
"Could not read from file {}: {}",
path.display(),
err.to_string()
))
})?;
trace!("New value: `{}`. Old value: `{}`", self.value, old_value);
self.old_value = Some(old_value);
trace!("Writing to file {:?}", path);
trace!("Writing to file {}", path.display());
fs::write(path, &self.value)
.map(|_| CommandResult::from(()))
.map_err(|err| {
Error::from(format!(
"Could not write to file {:?}: {}",
path,
"Could not write to file {}: {}",
path.display(),
err.to_string()
))
})
......@@ -110,30 +110,33 @@ impl Command for FindGetSetValue {
)?);
match self.path {
Some(ref value) => value,
None => return Err(Error::from(format!("{{rollback}} Missing previous value for path {:?}. (probably an internal bug, you should report it)", self.path)))
None => return Err(Error::from(format!("{{rollback}} Missing previous value for path {}. (probably an internal bug, you should report it)", self.path.display())))
}
}
};
if let Err(err) = self.controllers.check_path(&path) {
return Err(err);
}
debug!("{{rollback}} Reading and writing to file {:?}", path);
debug!(
"{{rollback}} Reading and writing to file {}",
path.display()
);
let old_value = match self.old_value {
Some(ref value) => value,
None => return Err(Error::from(format!("{{rollback}} Missing previous value for path {:?}, cannot rollback. (probably an internal bug, you should report it)", self.path)))
None => return Err(Error::from(format!("{{rollback}} Missing previous value for path {}, cannot rollback. (probably an internal bug, you should report it)", self.path.display())))
};
trace!(
"{{rollback}} New value: `{}`. Old value: `{}`",
self.value,
old_value
);
trace!("{{rollback}} Writing to file {:?}", path);
trace!("{{rollback}} Writing to file {}", path.display());
fs::write(path, old_value)
.map(|_| CommandResult::from(()))
.map_err(|err| {
Error::from(format!(
"{{rollback}} Could not write to file {:?}: {}",
path,
"{{rollback}} Could not write to file {}: {}",
path.display(),
err.to_string()
))
})
......
......@@ -29,15 +29,15 @@ impl Command for GetSetValue {
return Err(err);
}
if !self.path.exists() {
warn!("Could not find file {:?}", self.path);
warn!("Could not find file {}", self.path.display());
return Ok(CommandResult::from(()));
}
debug!("Reading and writing {:?}", self.path);
trace!("Reading from file {:?}", self.path);
debug!("Reading and writing {}", self.path.display());
trace!("Reading from file {}", self.path.display());
let old_value = fs::read_to_string(&self.path).map_err(|err| {
Error::from(format!(
"Could not read from file {:?}: {}",
self.path,
"Could not read from file {}: {}",
self.path.display(),
err.to_string()
))
})?;
......@@ -47,13 +47,13 @@ impl Command for GetSetValue {
old_value
);
self.old_value = Some(old_value);
trace!("Writing to file {:?}", self.path);
trace!("Writing to file {}", self.path.display());
fs::write(&self.path, &self.value)
.map(|_| CommandResult::from(()))
.map_err(|err| {
Error::from(format!(
"Could not write to file {:?}: {}",
self.path,
"Could not write to file {}: {}",
self.path.display(),
err.to_string()
))
})
......@@ -63,23 +63,23 @@ impl Command for GetSetValue {
if let Err(err) = self.controllers.check_path(&self.path) {
return Err(err);
}
debug!("{{rollback}} Reading and writing {:?}", self.path);
debug!("{{rollback}} Reading and writing {}", self.path.display());
let old_value = match self.old_value {
Some(ref value) => value,
None => return Err(Error::from(format!("Missing previous value for path {:?}, cannot rollback. (probably an internal bug, you should report it)", self.path)))
None => return Err(Error::from(format!("Missing previous value for path {}, cannot rollback. (probably an internal bug, you should report it)", self.path.display())))
};
trace!(
"{{rollback}} New value: \"{}\". Old value: \"{}\"",
self.value,
old_value
);
trace!("{{rollback}} Writing to file {:?}", self.path);
trace!("{{rollback}} Writing to file {}", self.path.display());
fs::write(&self.path, old_value)
.map(|_| CommandResult::from(()))
.map_err(|err| {
Error::from(format!(
"{{rollback}} Could not write to file {:?}: {}",
self.path,
"{{rollback}} Could not write to file {}: {}",
self.path.display(),
err.to_string()
))
})
......
......@@ -21,11 +21,14 @@ impl RemoveDir {
impl Command for RemoveDir {
fn exec(&mut self) -> Result<CommandResult> {
debug!("Removing directory {:?}", self.path);
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);
warn!(
"Could not remove directory {}: not found",
self.path.display()
);
Ok(())
}
other => other,
......@@ -33,8 +36,8 @@ impl Command for RemoveDir {
.map_err(Error::from)
.map_err(|err| {
Error::from(format!(
"Could not remove directory {:?}: {}",
self.path,
"Could not remove directory {}: {}",
self.path.display(),
err.to_string()
))
}),
......@@ -43,13 +46,13 @@ impl Command for RemoveDir {
}
fn rollback(&mut self) -> Result<CommandResult> {
debug!("{{rollback}} Creating directory {:?}", self.path);
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
"{{rollback}} Could not create directory {}: already exists",
self.path.display()
);
Ok(())
}
......@@ -57,8 +60,8 @@ impl Command for RemoveDir {
}.map(CommandResult::from)
.map_err(|err| {
Error::from(format!(
"{{rollback}} Could not create directory {:?}: {}",
self.path,
"{{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