From 2ea0b4818ab8dcb1b480d156eaac9f58f1317d92 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 22 Sep 2019 21:50:08 -0700 Subject: [PATCH] Updated run_sfc_scan() * Output is UTF-16, decode it as such * Simplifies section * Reworked checking the result * Use separate exceptions for corruption and general errors --- scripts/wk/os/win.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/scripts/wk/os/win.py b/scripts/wk/os/win.py index b99a1e13..6cd72e46 100644 --- a/scripts/wk/os/win.py +++ b/scripts/wk/os/win.py @@ -4,7 +4,6 @@ import logging import os import pathlib -import re import time from wk import cfg @@ -120,28 +119,28 @@ def run_sfc_scan(): err_path = log_path.with_suffix('.err') # Run SFC - proc = run_program(cmd, check=False) + proc = run_program(cmd, check=False, encoding='utf-16') # Fix paths log_path = non_clobber_path(log_path) err_path = non_clobber_path(err_path) # Save output - output = proc.stdout.replace('\0', '') - errors = proc.stderr.replace('\0', '') os.makedirs(log_path.parent, exist_ok=True) with open(log_path, 'w') as _f: - _f.write(output) + _f.write(proc.stdout) with open(err_path, 'w') as _f: - _f.write(errors) + _f.write(proc.stderr) # Check result - if re.findall(r'did\s+not\s+find\s+any\s+integrity\s+violations', output): + if 'did not find any integrity violations' in proc.stdout: pass - elif re.findall(r'successfully\s+repaired\s+them', output): + elif 'successfully repaired' in proc.stdout: raise GenericWarning('Repaired') + elif 'found corrupt files' in proc.stdout: + raise GenericError('Corruption detected') else: - raise GenericError + raise OSError if __name__ == '__main__':