mirror of https://git.48k.eu/ogclient
fs: disentagle dry-run ntfsresize loop to probe for best shrink size
Revisit 5056b8f0d5
("fs: validate ntfsresize dry-run output") that has
introduced a possible infinity loop.
Disentangle this loop while at it: iterate until best smallest size is
found by probing.
master
parent
0fc7f8f33e
commit
0f30b1349d
|
@ -235,19 +235,27 @@ def _reduce_ntfsresize(partdev):
|
|||
size = int(out_info.split('device size: ')[1].split(' ')[0])
|
||||
new_size = int(int(out_info.split('resize at ')[1].split(' ')[0])*1.1+1024)
|
||||
|
||||
# Dry-run loop to test if resizing is actually possible. This is required by ntfsresize.
|
||||
returncode = 1
|
||||
while new_size < size and returncode != 0:
|
||||
# Run ntfsresize with -n to to probe for the smallest size, this loop is
|
||||
# intentional. Acumulate size until ntfsresize in dry-run mode fails, then
|
||||
# use such size.
|
||||
while new_size < size:
|
||||
cmd_resize_dryrun = shlex.split(f'ntfsresize -Pfns {new_size:.0f} {partdev}')
|
||||
proc_resize_dryrun = subprocess.run(cmd_resize_dryrun, stdout=subprocess.PIPE, encoding='utf-8')
|
||||
returncode = proc_resize_dryrun.returncode
|
||||
|
||||
# valid new size found, stop probing
|
||||
if proc_resize_dryrun.returncode == 0:
|
||||
break
|
||||
|
||||
out_resize_dryrun = proc_resize_dryrun.stdout.strip()
|
||||
if 'Nothing to do: NTFS volume size is already OK.' in out_resize_dryrun:
|
||||
logging.warn('ntfsresize reports nothing to do. Is the target filesystem already shrunken?')
|
||||
logging.info('ntfsresize reports nothing to do. Is the target filesystem already shrunken?')
|
||||
break
|
||||
if out_resize_dryrun.find('Needed relocations : ') != -1:
|
||||
extra_size = int(out_resize_dryrun.split('Needed relocations : ')[1].split(' ')[0])*1.1+1024
|
||||
new_size += int(extra_size)
|
||||
|
||||
if out_resize_dryrun.find('Needed relocations : ') == -1:
|
||||
break
|
||||
|
||||
extra_size = int(out_resize_dryrun.split('Needed relocations : ')[1].split(' ')[0])*1.1+1024
|
||||
new_size += int(extra_size)
|
||||
|
||||
if new_size < size:
|
||||
cmd_resize = shlex.split(f'ntfsresize -fs {new_size:.0f} {partdev}')
|
||||
|
|
Loading…
Reference in New Issue