This commit is contained in:
Adrian Heine 2020-10-17 23:44:52 +02:00
parent b53267f406
commit da98bfba8c
20 changed files with 80 additions and 61 deletions

View file

@ -11,7 +11,7 @@ pub struct Dir<P> {
}
impl<P> Dir<P> {
pub fn new(path: P) -> Self {
pub const fn new(path: P) -> Self {
Self { path }
}
}

View file

@ -12,7 +12,7 @@ pub struct File<D, C> {
}
impl<D, C> File<D, C> {
pub fn new(path: D, content: C) -> Self {
pub const fn new(path: D, content: C) -> Self {
Self { path, content }
}
}

View file

@ -63,7 +63,12 @@ impl<C: CommandRunner, _C: Borrow<C>, P: AsRef<Path>, S: AsRef<str>, B: AsRef<st
}
async fn execute(&self) -> Result<(), Box<dyn Error>> {
if !self.target.as_ref().exists() {
if self.target.as_ref().exists() {
self
.run_git(&["fetch", self.source.as_ref(), self.branch.as_ref()])
.await?;
self.run_git(&["merge", "FETCH_HEAD"]).await?;
} else {
self
.command_runner
.borrow()
@ -80,11 +85,6 @@ impl<C: CommandRunner, _C: Borrow<C>, P: AsRef<Path>, S: AsRef<str>, B: AsRef<st
],
)
.await?;
} else {
self
.run_git(&["fetch", self.source.as_ref(), self.branch.as_ref()])
.await?;
self.run_git(&["merge", "FETCH_HEAD"]).await?;
}
Ok(())
}

View file

@ -13,7 +13,7 @@ pub struct GitSubmodules<'a, P, C> {
}
impl<'a, P, C> GitSubmodules<'a, P, C> {
pub fn new(target: P, command_runner: &'a C) -> Self {
pub const fn new(target: P, command_runner: &'a C) -> Self {
Self {
target,
command_runner,

View file

@ -34,8 +34,8 @@ impl<'a, N, C: CommandRunner, S> Dump<'a, N, C, S> {
impl<N: AsRef<str>, C: CommandRunner, S: Storage> Symbol for Dump<'_, N, C, S> {
async fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let dump_date = self.storage.recent_date()?;
let _modified_date = self.run_sql(&format!("select UNIX_TIMESTAMP(MAX(UPDATE_TIME)) from information_schema.tables WHERE table_schema = '{}'", self.db_name.as_ref())).await?;
let modified_date = _modified_date.trim_end();
let output = self.run_sql(&format!("select UNIX_TIMESTAMP(MAX(UPDATE_TIME)) from information_schema.tables WHERE table_schema = '{}'", self.db_name.as_ref())).await?;
let modified_date = output.trim_end();
Ok(modified_date != "NULL" && u64::from_str(modified_date)? <= dump_date)
}

View file

@ -11,7 +11,7 @@ pub struct UserSession<'a, U, C> {
}
impl<'a, U, C> UserSession<'a, U, C> {
pub fn new(user_name: U, command_runner: &'a C) -> Self {
pub const fn new(user_name: U, command_runner: &'a C) -> Self {
Self {
user_name,
command_runner,

View file

@ -14,7 +14,7 @@ pub struct Csr<C, D, K, P> {
}
impl<C, D, K, P> Csr<C, D, K, P> {
pub fn new(command_runner: C, domain: D, key_path: K, csr_path: P) -> Self {
pub const fn new(command_runner: C, domain: D, key_path: K, csr_path: P) -> Self {
Self {
command_runner,
domain,

View file

@ -8,19 +8,17 @@ use std::path::Path;
pub struct Key<C, P> {
file_path: P,
command_runner: C,
bytes: u32,
}
impl<C, P> Key<C, P> {
pub fn new(command_runner: C, file_path: P) -> Self {
pub const fn new(command_runner: C, file_path: P) -> Self {
Self {
file_path,
command_runner,
bytes: 4096,
}
}
fn get_bytes(&self) -> u32 {
4096
}
}
#[async_trait(?Send)]
@ -57,7 +55,7 @@ impl<C: CommandRunner, P: AsRef<Path>> Symbol for Key<C, P> {
"genrsa",
"-out",
self.file_path.as_ref(),
self.get_bytes().to_string(),
self.bytes.to_string(),
],
)
.await

View file

@ -15,7 +15,7 @@ pub struct User<U, C> {
}
impl<U, C> User<U, C> {
pub fn new(user_name: U, command_runner: C) -> Self {
pub const fn new(user_name: U, command_runner: C) -> Self {
Self {
user_name,
command_runner,
@ -41,7 +41,7 @@ impl<U: AsRef<str>, C: CommandRunner> Symbol for User<U, C> {
// adduser is not reentrant because finding the next uid
// and creating the account is not an atomic operation
let wait = WAIT.acquire().await;
self
let res = self
.command_runner
.run_successfully(
"adduser",
@ -51,7 +51,9 @@ impl<U: AsRef<str>, C: CommandRunner> Symbol for User<U, C> {
self.user_name.as_ref(),
],
)
.await
.await;
drop(wait);
res
}
}