Commit bfead0fa authored by Alexis Janon's avatar Alexis Janon
Browse files

check_path for find_get_set and get_set primitives

parent 174fce88
......@@ -59,6 +59,9 @@ impl Command for FindGetSetValue {
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)))
};
if let Err(err) = self.controllers.check_path(&path) {
return Err(err);
}
trace!("Reading from file {:?}", path);
let old_value = fs::read_to_string(path).map_err(|err| {
Error::from(format!(
......@@ -111,6 +114,9 @@ impl Command for FindGetSetValue {
}
}
};
if let Err(err) = self.controllers.check_path(&path) {
return Err(err);
}
debug!("{{rollback}} Reading and writing to file {:?}", path);
let old_value = match self.old_value {
Some(ref value) => value,
......
use configuration::sysfscontroller::SysFsControllerList;
use std::fs;
use std::path::PathBuf;
use std::rc::Rc;
use transaction::*;
#[derive(Clone, PartialEq, Eq)]
......@@ -7,20 +9,25 @@ pub struct GetSetValue {
path: PathBuf,
value: String,
old_value: Option<String>,
controllers: Rc<SysFsControllerList>,
}
impl GetSetValue {
pub fn new(path: PathBuf, value: String) -> Self {
pub fn new(path: PathBuf, value: String, controllers: Rc<SysFsControllerList>) -> Self {
GetSetValue {
path,
value,
old_value: None,
controllers,
}
}
}
impl Command for GetSetValue {
fn exec(&mut self) -> Result<CommandResult> {
if let Err(err) = self.controllers.check_path(&self.path) {
return Err(err);
}
if !self.path.exists() {
warn!("Could not find file {:?}", self.path);
return Ok(CommandResult::from(()));
......@@ -53,6 +60,9 @@ impl Command for GetSetValue {
}
fn rollback(&mut self) -> Result<CommandResult> {
if let Err(err) = self.controllers.check_path(&self.path) {
return Err(err);
}
debug!("{{rollback}} Reading and writing {:?}", self.path);
let old_value = match self.old_value {
Some(ref value) => value,
......
......@@ -33,8 +33,9 @@ impl Exec {
.values()
.map(SysFsController::get_tasks_filename),
).map(|(path, tasks_filename)| path.join(&name).join(tasks_filename))
.map(|path| GetSetValue::new(path.to_path_buf(), "0".to_owned()))
.map(Box::new)
.map(|path| {
GetSetValue::new(path.to_path_buf(), "0".to_owned(), Rc::clone(&controllers))
}).map(Box::new)
.map(|b| b as Box<Command>)
.collect::<Vec<_>>();
let mut process_cmd = process::Command::new(cmd);
......
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