From 70e2ea9d7bb11222021f4b5dc56b45e3d47c7290 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Thu, 21 Sep 2017 22:35:53 -0700 Subject: [PATCH] Fixed runtime error on windows (-f option not defined) --- src/main.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index d31e336..e98ffd6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,6 +52,8 @@ use unix_daemonize::{daemonize_redirect, ChdirMode}; use core::ops::Deref; use errors::*; +#[cfg(unix)] +use getopts::Matches; use getopts::Options; use iron::prelude::*; use mount::Mount; @@ -88,8 +90,11 @@ fn main() { } } -#[cfg(unix)] -fn daemonize() -> Result<()> { + #[cfg(unix)] +fn daemonize(options : &getopts::Matches) -> Result<()> { + if options.opt_present("f") { + return Ok(()); + } let mut log_file = utils::get_data_root()?; log_file.push("polaris.log"); match daemonize_redirect(Some(&log_file), Some(&log_file), ChdirMode::NoChdir) { @@ -107,7 +112,7 @@ fn run() -> Result<()> { options.optopt("p", "port", "set polaris to run on a custom port", "PORT"); options.optopt("d", "database", "set the path to index database", "FILE"); options.optopt("w", "web", "set the path to web client files", "DIRECTORY"); - + #[cfg(unix)] options.optflag("f", "foreground", @@ -124,11 +129,8 @@ fn run() -> Result<()> { return Ok(()); } - //attribute inside the if clause, because they are not yet allowed on `if` expressions - if !matches.opt_present("f") { - #[cfg(unix)] - daemonize()?; - } + #[cfg(unix)] + daemonize(&matches)?; // Init DB println!("Starting up database");