summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2024-02-15 10:26:26 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-02-15 16:36:28 +0100
commit0f30b1349d430bcb564e9bf736f98de6bc511e65 (patch)
treed852f41d78db3796fc759cfc07bad6c3338d2060 /src/utils
parent0fc7f8f33eecad34976ae14617c736bf78eb3b0e (diff)
fs: disentagle dry-run ntfsresize loop to probe for best shrink size
Revisit 5056b8f0d5ab ("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.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/fs.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/utils/fs.py b/src/utils/fs.py
index fbbbd3c..651801c 100644
--- a/src/utils/fs.py
+++ b/src/utils/fs.py
@@ -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}')