Commit b0182f27 authored by MrMan's avatar MrMan

debug progress

parent 4024cfa9
use std::fs::{File, copy};
use std::io::Write;
use std::path::{Path, PathBuf};
use std::path::Path;
use std::process::{Command, Stdio, Child as ChildProcess};
use std::sync::mpsc::{sync_channel, SyncSender, Receiver};
......@@ -11,7 +11,6 @@ use ensure_directory;
use simple_signal::{Signal};
use simple_signal;
use components::db::*;
use components::*;
use config::{DovecotCfg, DovecotDBSettings, DovecotSettingName};
......@@ -37,7 +36,7 @@ pub struct Dovecot {
}
impl Dovecot {
pub fn new(cfg: DovecotCfg, db: Option<DB>) -> Result<Dovecot, Error> {
pub fn new(cfg: DovecotCfg) -> Result<Dovecot, Error> {
// Create command bus channels
let (cmd_bus_tx, cmd_bus_rx) = sync_channel(0);
......@@ -125,11 +124,8 @@ impl ChildProcessManager for Dovecot {
fn spawn_child_process(&mut self) -> Result<&Option<ChildProcess>, Error> {
debug!("spawning postfix process...");
// Build arguments to start dovecot in *non* daemonized mode so we can control it
let config_output_dir = make_absolute_path(PathBuf::from(&self.cfg.config_output_dir))?;
// Build & save command to start dovecot in *non* daemonized mode so we can control it
let args = &["-F"];
// Build & save command
let mut cmd = Command::new(&self.cfg.bin_path);
cmd.args(args);
cmd.stdin(Stdio::null());
......@@ -174,7 +170,7 @@ impl Configurable<DovecotCfg> for Dovecot {
self.install_config()?;
// Run `doveadm reload`
let output = Command::new(&self.cfg.doveadm_bin_path)
Command::new(&self.cfg.doveadm_bin_path)
.args(&["reload"])
.output()?;
......@@ -222,7 +218,8 @@ impl FileConfigurable<DovecotCfg> for Dovecot {
info!("updating on-disk configuration for dovecot");
// Ensure configuration directory exists
let config_dir_abs_path = ensure_directory(&self.cfg.config_output_dir)?;
let dir = dir.unwrap_or(self.config_dir_path());
ensure_directory(&dir)?;
// Build dovecot conf template
let main_conf_tmpl = DovecotConfTemplate {
......@@ -259,7 +256,7 @@ impl FileConfigurable<DovecotCfg> for Dovecot {
};
let conf_path = output_dir.join(DOVECOT_USERDB_CONF_FILENAME);
let conf_abs_path = make_absolute_path(main_conf_path.to_path_buf())?;
let conf_abs_path = make_absolute_path(conf_path.to_path_buf())?;
// Render the main config
debug!("{} will be written to [{}]", &tmpl.filename, &conf_abs_path);
......@@ -277,7 +274,7 @@ impl FileConfigurable<DovecotCfg> for Dovecot {
};
let conf_path = output_dir.join(DOVECOT_PASSDB_CONF_FILENAME);
let conf_abs_path = make_absolute_path(main_conf_path.to_path_buf())?;
let conf_abs_path = make_absolute_path(conf_path.to_path_buf())?;
// Render the main config
debug!("{} will be written to [{}]", &tmpl.filename, &conf_abs_path);
......@@ -300,7 +297,7 @@ impl FileConfigurable<DovecotCfg> for Dovecot {
);
// Ensure configuration directory exists
let config_dir_abs_path = ensure_directory(&self.cfg.config_output_dir)?;
ensure_directory(&self.cfg.config_output_dir)?;
// Copy dovecot.conf
let dovecot_conf_from = config_dir_path.clone().join(DOVECOT_CONF_FILENAME);
......
......@@ -96,6 +96,7 @@ pub enum Error {
IO(IOError),
TemplateError(AskamaError),
InvalidEnvironment(&'static str),
InvalidRuntimeEnvironment(String),
DBError(String),
SQLiteDBError(SQLiteError),
}
......@@ -112,6 +113,7 @@ impl fmt::Display for Error {
&Error::IO(ref e) => write!(f, "IO error while building: {}", e),
&Error::TemplateError(ref e) => write!(f, "Error while using template: {}", e),
&Error::InvalidEnvironment(ref e) => write!(f, "Invalid environment (precondition failure): {}", e),
&Error::InvalidRuntimeEnvironment(ref e) => write!(f, "Invalid environment @ runtime: {}", e),
&Error::DBError(ref info) => write!(f, "Database error: {}", info),
&Error::SQLiteDBError(ref e) => write!(f, "SQLite DB error: {}", e),
}
......
......@@ -213,8 +213,8 @@ pub trait DovecotSettingName {
impl DovecotSettingName for DBType {
fn dovecot_setting_name(self) -> &'static str {
match self {
SQLite => "sqlite",
PostgresSQL => "pgsql",
DBType::SQLite => "sqlite",
DBType::PostgreSQL => "pgsql",
}
}
}
......
......@@ -178,7 +178,8 @@ pub fn ensure_directory(path: &str) -> Result<String, Error> {
// Ensure config directory exists and is a proper directory
if !dir.exists() { create_dir_all(&dir)?; }
if dir.exists() && !dir.is_dir() {
return Err(Error::InvalidEnvironment(&format!("Provided directory [{:?}] is invalid", dir.to_str())));
let msg = format!("Provided directory [{:?}] is invalid", dir.to_str());
return Err(Error::InvalidRuntimeEnvironment(msg));
}
make_absolute_path(dir.to_path_buf())
......
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