Adjusted ddrescue exit handling

* Wait for ddrescue_proc after KeyboardInterrupt
  * ddrescue prints extra info to the screen after a CTRL+c
* Explicitly mark KeyboardInterrupt events as an abort
* Add 'DDRESCUE PROCESS HALTED' message in red if exiting non-zero
  * More clearly indicates that user interaction is required
  * Fixes issue #72
This commit is contained in:
2Shirt 2018-12-18 20:35:21 -07:00
parent 44fe888230
commit 42407f0eca
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -953,7 +953,8 @@ def read_map_file(map_path):
def run_ddrescue(state, pass_settings): def run_ddrescue(state, pass_settings):
"""Run ddrescue pass.""" """Run ddrescue pass."""
return_code = None return_code = -1
aborted = False
if state.finished: if state.finished:
clear_screen() clear_screen()
@ -1007,7 +1008,6 @@ def run_ddrescue(state, pass_settings):
i = 0 i = 0
while True: while True:
# Update SMART display (every 30 seconds) # Update SMART display (every 30 seconds)
i += 1
if i % 30 == 0: if i % 30 == 0:
state.smart_source.get_smart_details() state.smart_source.get_smart_details()
with open(state.smart_out, 'w') as f: with open(state.smart_out, 'w') as f:
@ -1015,6 +1015,7 @@ def run_ddrescue(state, pass_settings):
timestamp=True) timestamp=True)
for line in report: for line in report:
f.write('{}\n'.format(line)) f.write('{}\n'.format(line))
i += 1
# Update progress # Update progress
bp.update_progress(state.current_pass) bp.update_progress(state.current_pass)
@ -1036,7 +1037,8 @@ def run_ddrescue(state, pass_settings):
except KeyboardInterrupt: except KeyboardInterrupt:
# Catch user abort # Catch user abort
pass aborted = True
ddrescue_proc.wait(timeout=10)
# Update progress/sidepane again # Update progress/sidepane again
bp.update_progress(state.current_pass) bp.update_progress(state.current_pass)
@ -1044,12 +1046,19 @@ def run_ddrescue(state, pass_settings):
# Was ddrescue aborted? # Was ddrescue aborted?
return_code = ddrescue_proc.poll() return_code = ddrescue_proc.poll()
if return_code is None or return_code is 130: if aborted:
clear_screen() print_standard(' ')
print_standard(' ')
print_error('DDRESCUE PROCESS HALTED')
print_standard(' ')
print_warning('Aborted') print_warning('Aborted')
break break
elif return_code: elif return_code:
# i.e. not None and not 0 # i.e. True when non-zero
print_standard(' ')
print_standard(' ')
print_error('DDRESCUE PROCESS HALTED')
print_standard(' ')
print_error('Error(s) encountered, see message above.') print_error('Error(s) encountered, see message above.')
break break
else: else: