blacknon / hwatch

A modern alternative to the watch command, records the differences in execution results and can check this differences at after.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Logging does not work

FedericoStra opened this issue · comments

If I try to log to a file I get this error:

$ hwatch -n 3 -l hwatch_log.json date
directory "" is not exists.

A lazy solution is to replace https://github.com/blacknon/hwatch/blob/master/src/main.rs#L221-L238 with

    // check _logfile directory
    // TODO(blacknon): commonに移す?(ここで直書きする必要性はなさそう)
    if logfile != None {
        let _log_path = Path::new(logfile.unwrap());
        let _log_dir = _log_path.parent().unwrap();
        let _cur_dir = std::env::current_dir().expect("cannot get current directory");
        let _abs_log_path = _cur_dir.join(_log_path);
        let _abs_log_dir = _cur_dir.join(_log_dir);

        // check _log_path exist
        if _abs_log_path.exists() {
            println!("file {:?} is exists.", _abs_log_path);
            std::process::exit(1);
        }

        // check _log_dir exist
        if !_abs_log_dir.exists() {
            println!("directory {:?} is not exists.", _abs_log_dir);
            std::process::exit(1);
        }
    }

however this does not fully resolve the underlying issue, as putting this checks in advance is both superfluous and insufficient. In fact, a more serious problem is the .unwrap() in https://github.com/blacknon/hwatch/blob/master/src/common.rs#L26 which should be dealt with instead.

Oh..., I will check it and fix it in the next version.
Please wait for a little while.