Skip to content

Commit

Permalink
Add some error handling in rules update feature
Browse files Browse the repository at this point in the history
  • Loading branch information
wagga40 committed Aug 17, 2022
1 parent 0f0eb78 commit 387bc71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Binary file modified docs/Zircolite_manual.pdf
Binary file not shown.
11 changes: 8 additions & 3 deletions zircolite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,11 +1264,16 @@ def checkIfNewerAndMove(self):
rulesets = Path(self.tmpDir).rglob("*.json")
for ruleset in rulesets:
hash_new = hashlib.md5(open(ruleset, "rb").read()).hexdigest()
hash_old = hashlib.md5(
open(f"rules/{ruleset.name}", "rb").read()
).hexdigest()
if Path(f"rules/{ruleset.name}").is_file():
hash_old = hashlib.md5(
open(f"rules/{ruleset.name}", "rb").read()
).hexdigest()
else:
hash_old = ""
if hash_new != hash_old:
count += 1
if not Path(f"rules/").exists():
Path(f"rules/").mkdir()
shutil.move(ruleset, f"rules/{ruleset.name}")
self.updatedRulesets.append(f"rules/{ruleset.name}")
self.logger.info(
Expand Down
6 changes: 5 additions & 1 deletion zircolite_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,9 +889,13 @@ def checkIfNewerAndMove(self):
rulesets = Path(self.tmpDir).rglob("*.json")
for ruleset in rulesets:
hash_new = hashlib.md5(open(ruleset,'rb').read()).hexdigest()
hash_old = hashlib.md5(open(f'rules/{ruleset.name}','rb').read()).hexdigest()
if Path(f'rules/{ruleset.name}').is_file():
hash_old = hashlib.md5(open(f'rules/{ruleset.name}','rb').read()).hexdigest()
else: hash_old = ""
if hash_new != hash_old:
count += 1
if not Path(f'rules/').exists():
Path(f'rules/').mkdir()
shutil.move(ruleset, f'rules/{ruleset.name}')
self.updatedRulesets.append(f'rules/{ruleset.name}')
self.logger.info(f"{Fore.CYAN} [+] Updated : rules/{ruleset.name}{Fore.RESET}")
Expand Down

0 comments on commit 387bc71

Please sign in to comment.