From a3599ca5d03e950dd30fb12b1cab1413c62d00d8 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sat, 2 Jul 2022 16:39:46 +0900 Subject: [PATCH] adjust rules option when use update option #615 --- src/main.rs | 2 +- src/options/update_rules.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3cbc9432..5ae85436 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,7 +114,7 @@ impl App { } if configs::CONFIG.read().unwrap().args.update_rules { - match UpdateRules::update_rules() { + match UpdateRules::update_rules(configs::CONFIG.read().unwrap().args.rules.to_str().unwrap()) { Ok(output) => { if output != "You currently have the latest rules." { write_color_buffer( diff --git a/src/options/update_rules.rs b/src/options/update_rules.rs index 764a2a8a..e4244fe1 100644 --- a/src/options/update_rules.rs +++ b/src/options/update_rules.rs @@ -20,12 +20,12 @@ pub struct UpdateRules {} impl UpdateRules { /// update rules(hayabusa-rules subrepository) - pub fn update_rules() -> Result { + pub fn update_rules(rule_path: &str) -> Result { let mut result; let mut prev_modified_time: SystemTime = SystemTime::UNIX_EPOCH; let mut prev_modified_rules: HashSet = HashSet::default(); let hayabusa_repo = Repository::open(Path::new(".")); - let hayabusa_rule_repo = Repository::open(Path::new("rules")); + let hayabusa_rule_repo = Repository::open(Path::new(rule_path)); if hayabusa_repo.is_err() && hayabusa_rule_repo.is_err() { write_color_buffer( &BufferWriter::stdout(ColorChoice::Always), @@ -40,15 +40,15 @@ impl UpdateRules { // case of exist hayabusa-rules repository UpdateRules::_repo_main_reset_hard(hayabusa_rule_repo.as_ref().unwrap())?; // case of failed fetching origin/main, git clone is not executed so network error has occurred possibly. - prev_modified_rules = UpdateRules::get_updated_rules("rules", &prev_modified_time); - prev_modified_time = fs::metadata("rules").unwrap().modified().unwrap(); + prev_modified_rules = UpdateRules::get_updated_rules(rule_path, &prev_modified_time); + prev_modified_time = fs::metadata(rule_path).unwrap().modified().unwrap(); result = UpdateRules::pull_repository(&hayabusa_rule_repo.unwrap()); } else { // case of no exist hayabusa-rules repository in rules. // execute update because submodule information exists if hayabusa repository exists submodule information. - prev_modified_time = fs::metadata("rules").unwrap().modified().unwrap(); - let rules_path = Path::new("rules"); + prev_modified_time = fs::metadata(rule_path).unwrap().modified().unwrap(); + let rules_path = Path::new(rule_path); if !rules_path.exists() { create_dir(rules_path).ok(); } @@ -73,7 +73,7 @@ impl UpdateRules { } if result.is_ok() { let updated_modified_rules = - UpdateRules::get_updated_rules("rules", &prev_modified_time); + UpdateRules::get_updated_rules(rule_path, &prev_modified_time); result = UpdateRules::print_diff_modified_rule_dates( prev_modified_rules, updated_modified_rules,