Retry CHKDSK on failures

Fixes issue #159
This commit is contained in:
2Shirt 2021-04-15 21:13:28 -06:00
parent ed6f188eb2
commit 943c1e11b9
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -334,21 +334,26 @@ def run_chkdsk_online():
cmd.extend(['/scan', '/perf']) cmd.extend(['/scan', '/perf'])
log_path = format_log_path(log_name='CHKDSK', tool=True) log_path = format_log_path(log_name='CHKDSK', tool=True)
err_path = log_path.with_suffix('.err') err_path = log_path.with_suffix('.err')
retried = False
# Run scan # Run scan
proc = run_program(cmd, check=False) proc = run_program(cmd, check=False)
if proc.returncode > 1:
# Try again
retried = True
proc = run_program(cmd, check=False)
# Check result # Check result
if proc.returncode == 1: if (proc.returncode == 0 and retried) or proc.returncode == 1:
raise GenericWarning('Repaired (or manually aborted)') raise GenericWarning('Repaired (or manually aborted)')
if proc.returncode > 1: if proc.returncode > 1:
raise GenericError('Issue(s) detected') raise GenericError('Issue(s) detected')
# Save output # Save output
os.makedirs(log_path.parent, exist_ok=True) os.makedirs(log_path.parent, exist_ok=True)
with open(log_path, 'w') as _f: with open(log_path, 'a') as _f:
_f.write(proc.stdout) _f.write(proc.stdout)
with open(err_path, 'w') as _f: with open(err_path, 'a') as _f:
_f.write(proc.stderr) _f.write(proc.stderr)