Browse Source

Update

master
Adrian Heine 8 years ago
parent
commit
2c47bb10f5
  1. 9
      src/symbols/owner.rs
  2. 10
      src/symbols/systemd/node_js_user_service.rs
  3. 9
      src/symbols/systemd/user_session.rs

9
src/symbols/owner.rs

@ -1,3 +1,4 @@
use std::borrow::{ Borrow, Cow };
use std::error::Error;
use std::fmt;
use std::fs;
@ -11,12 +12,12 @@ use command_runner::CommandRunner;
pub struct Owner<'a, D> where D: AsRef<str> + fmt::Display {
path: D,
user_name: &'a str,
user_name: Cow<'a, str>,
command_runner: &'a CommandRunner
}
impl<'a, D> Owner<'a, D> where D: AsRef<str> + fmt::Display {
pub fn new(path: D, user_name: &'a str, command_runner: &'a CommandRunner) -> Self {
pub fn new(path: D, user_name: Cow<'a, str>, command_runner: &'a CommandRunner) -> Self {
Owner { path: path, user_name: user_name, command_runner: command_runner }
}
}
@ -24,12 +25,12 @@ impl<'a, D> Owner<'a, D> where D: AsRef<str> + fmt::Display {
impl<'a, D> Symbol for Owner<'a, D> where D: AsRef<str> + fmt::Display {
fn target_reached(&self) -> Result<bool, Box<Error>> {
let actual_uid = fs::metadata(self.path.as_ref()).unwrap().uid();
let target_uid = get_user_by_name(self.user_name).unwrap().uid();
let target_uid = get_user_by_name(self.user_name.borrow()).unwrap().uid();
Ok(actual_uid == target_uid)
}
fn execute(&self) -> Result<(), Box<Error>> {
try!(self.command_runner.run_with_args("chown", &[self.user_name, self.path.as_ref()]));
try!(self.command_runner.run_with_args("chown", &[self.user_name.borrow(), self.path.as_ref()]));
Ok(())
}
}

10
src/symbols/systemd/node_js_user_service.rs

@ -10,6 +10,7 @@ use std::time::Duration;
use std::ops::Deref;
use command_runner::CommandRunner;
use resources::{ FileResource, Resource };
use symbols::Symbol;
use symbols::file::File as FileSymbol;
@ -125,9 +126,6 @@ impl<'a, P, C> Symbol for NodeJsSystemdUserService<'a, P, C> where P: AsRef<str>
}
fn execute(&self) -> Result<(), Box<Error>> {
try!(self.command_runner.run_with_args("mkdir", &["-p", Path::new(self.path.as_ref()).parent().unwrap().to_str().unwrap()]));
// FIXME: Permissions
// try!(create_dir_all(Path::new(&path).parent().unwrap()));
match self.file.execute() {
Ok(_) => {},
Err(e) => return Err(e)
@ -164,11 +162,11 @@ impl<'a, P, C> Symbol for NodeJsSystemdUserService<'a, P, C> where P: AsRef<str>
Ok(())
}
/* // FIXME
fn get_prerequisites(&self) -> Vec<Box<Resource>> {
self.file.get_prerequisites()
let mut r: Vec<Box<Resource>> = vec![ Box::new(FileResource { path: ("/var/lib/systemd/linger/".to_string() + self.user_name).into() }) ];
r.extend(self.file.get_prerequisites().into_iter());
r
}
*/
}
impl<'a, P, C> fmt::Display for NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> + fmt::Display, C: Deref<Target=str> {

9
src/symbols/systemd/user_session.rs

@ -1,3 +1,4 @@
use std::borrow::{ Borrow, Cow };
use std::error::Error;
use std::fmt;
use std::io::Error as IoError;
@ -35,12 +36,12 @@ impl<E: Error> fmt::Display for SystemdUserSessionError<E> {
}
pub struct SystemdUserSession<'a> {
user_name: &'a str,
user_name: Cow<'a, str>,
command_runner: &'a CommandRunner
}
impl<'a> SystemdUserSession<'a> {
pub fn new(user_name: &'a str, command_runner: &'a CommandRunner) -> Self {
pub fn new(user_name: Cow<'a, str>, command_runner: &'a CommandRunner) -> Self {
SystemdUserSession {
user_name: user_name,
command_runner: command_runner
@ -51,13 +52,13 @@ impl<'a> SystemdUserSession<'a> {
impl<'a> Symbol for SystemdUserSession<'a> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
let mut path = PathBuf::from("/var/lib/systemd/linger");
path.push(self.user_name);
path.push(self.user_name.borrow() as &str);
Ok(path.exists())
// Could also do `loginctl show-user ${self.user_name} | grep -F 'Linger=yes`
}
fn execute(&self) -> Result<(), Box<Error>> {
match self.command_runner.run_with_args("loginctl", &["enable-linger", self.user_name]) {
match self.command_runner.run_with_args("loginctl", &["enable-linger", self.user_name.borrow()]) {
Ok(output) => { println!("{:?} {:?}", from_utf8(&output.stdout).unwrap(), from_utf8(&output.stderr).unwrap() ); match output.status.code() {
Some(0) => Ok(()),
_ => Err(Box::new(SystemdUserSessionError::GenericError as SystemdUserSessionError<IoError>))

Loading…
Cancel
Save