summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
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}')