Some small fixes

This commit is contained in:
Adrian Heine 2020-09-03 11:31:09 +02:00
parent d173198729
commit 42690f1d50
7 changed files with 46 additions and 24 deletions

View file

@ -13,7 +13,7 @@ pub struct Install<'a, T: AsRef<Path>, C: CommandRunner> {
impl<'a, T: AsRef<Path>, C: CommandRunner> Install<'a, T, C> {
pub fn new(target: T, command_runner: &'a C) -> Self {
Install {
Self {
target,
command_runner,
}
@ -36,9 +36,9 @@ impl<T: AsRef<Path>, C: CommandRunner> Symbol for Install<'_, T, C> {
if !self.target.as_ref().exists() {
return Ok(false);
}
let output = self
let result = self
.command_runner
.get_output(
.run_with_args(
"sh",
args![
"-c",
@ -46,7 +46,12 @@ impl<T: AsRef<Path>, C: CommandRunner> Symbol for Install<'_, T, C> {
],
)
.await?;
Ok(!String::from_utf8(output).unwrap().contains("(empty)"))
Ok(
result.status.success()
&& !String::from_utf8(result.stdout)
.unwrap()
.contains("(empty)"),
)
}
async fn execute(&self) -> Result<(), Box<dyn Error>> {

View file

@ -1,7 +1,12 @@
use crate::command_runner::CommandRunner;
use crate::symbols::Symbol;
use async_trait::async_trait;
use once_cell::sync::Lazy;
use std::error::Error;
use tokio::sync::Semaphore;
pub type Wait = Lazy<Semaphore>;
static WAIT: Wait = Lazy::new(|| Semaphore::new(1));
#[derive(Debug)]
pub struct User<U, C> {
@ -33,6 +38,9 @@ impl<U: AsRef<str>, C: CommandRunner> Symbol for User<U, C> {
}
async fn execute(&self) -> Result<(), Box<dyn Error>> {
// adduser is not reentrant because finding the next uid
// and creating the account is not an atomic operation
let wait = WAIT.acquire().await;
self
.command_runner
.run_successfully(