From 6eaf5c2bc2e6424eec769113eefa96995524f53e Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Fri, 3 Jan 2020 17:25:12 -0700 Subject: [PATCH] Get accurate size from ddrescuelog * Reported size is off by one sector in some cases --- scripts/wk/hw/ddrescue.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/wk/hw/ddrescue.py b/scripts/wk/hw/ddrescue.py index a1abd2f0..b3a599b0 100644 --- a/scripts/wk/hw/ddrescue.py +++ b/scripts/wk/hw/ddrescue.py @@ -53,7 +53,8 @@ CLONE_SETTINGS = { DDRESCUE_LOG_REGEX = re.compile( r'^\s*(?P\S+):\s+' r'(?P\d+)\s+' - r'(?P[PTGMKB]i?B?)', + r'(?P[PTGMKB]i?B?)' + r'.*\(\s*(?P\d+\.?\d*)%\)$', re.IGNORECASE, ) REGEX_REMAINING_TIME = re.compile( @@ -187,9 +188,13 @@ class BlockPair(): for line in proc.stdout.splitlines(): _r = DDRESCUE_LOG_REGEX.search(line) if _r: - data[_r.group('key')] = std.string_to_bytes( - f'{_r.group("size")} {_r.group("unit")}', - ) + if _r.group('key') == 'rescued' and _r.group('percent') == '100': + # Fix rounding errors from ddrescuelog output + data['rescued'] = self.size + else: + data[_r.group('key')] = std.string_to_bytes( + f'{_r.group("size")} {_r.group("unit")}', + ) data['pass completed'] = 'current status: finished' in line.lower() # Check if 100% done @@ -1302,6 +1307,7 @@ def format_status_string(status, width): status_str = f'{percent:{width-2}.2f} %' if '100.00' in status_str and percent < 100: # Always round down to 99.99% + LOG.warning('Rounding down to 99.99 from %s', percent) status_str = f'{"99.99 %":>{width}}' else: # Text