From d6c32bba5d3d91f6917b2c856f571964fb725323 Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Thu, 15 Feb 2024 10:37:54 +0100 Subject: fs: check if ntfsresize actually succeded to shrink filesystem According to ntfsresize.c, this retuns 0 in case nothing needs to be done. It should be safe to check for non-zero error and bail out in that case. --- src/utils/fs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/utils') diff --git a/src/utils/fs.py b/src/utils/fs.py index 651801c..4fd431e 100644 --- a/src/utils/fs.py +++ b/src/utils/fs.py @@ -260,7 +260,10 @@ def _reduce_ntfsresize(partdev): if new_size < size: cmd_resize = shlex.split(f'ntfsresize -fs {new_size:.0f} {partdev}') with open('/tmp/command.log', 'ab', 0) as logfile: - subprocess.run(cmd_resize, input='y', stderr=STDOUT, encoding='utf-8') + proc_resize = subprocess.run(cmd_resize, input='y', stderr=STDOUT, encoding='utf-8') + if proc_resize.returncode != 0: + logging.error(f'ntfsresize on {partdev} with {new_size:.0f} failed with {proc_resize.returncode}') + return -1 return 0 -- cgit v1.2.3-18-g5258