diff options
Diffstat (limited to 'src/utils/fs.py')
-rw-r--r-- | src/utils/fs.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/utils/fs.py b/src/utils/fs.py index c030e68..fbbbd3c 100644 --- a/src/utils/fs.py +++ b/src/utils/fs.py @@ -100,13 +100,14 @@ def ogReduceFs(disk, part): umount(partdev) if fstype == 'ext4': - _reduce_resize2fs(partdev) + ret = _reduce_resize2fs(partdev) elif fstype == 'ntfs': - _reduce_ntfsresize(partdev) + ret = _reduce_ntfsresize(partdev) else: logging.warn(f'Unable to shrink filesystem at {partdev}. ' f'Unsupported filesystem "{fstype}".') + return ret def ogExtendFs(disk, part): """ @@ -202,9 +203,13 @@ def get_filesystem_type(partdev): def _reduce_resize2fs(partdev): + ret = -1 cmd = shlex.split(f'resize2fs -fpM {partdev}') with open('/tmp/command.log', 'ab', 0) as logfile: - subprocess.run(cmd, stdout=logfile, stderr=STDOUT) + proc = subprocess.run(cmd, stdout=logfile, stderr=STDOUT) + ret = proc.returncode + + return 0 if ret == 0 else -1 def _reduce_ntfsresize(partdev): @@ -212,6 +217,14 @@ def _reduce_ntfsresize(partdev): proc_info = subprocess.run(cmd_info, stdout=subprocess.PIPE, encoding='utf-8') out_info = proc_info.stdout.strip() + if out_info.find('ERROR: NTFS is inconsistent. Run chkdsk') != -1: + logging.error('NTFS is inconsistent. Run chkdsk /f on Windows then reboot TWICE!') + return -1 + + if proc_info.returncode != 0: + logging.error(f'nfsresize {partdev} has failed with return code {proc_info.returncode}') + return -1 + # Process ntfsresize output directly. # The first split operation leaves the wanted data at the second element of # the split ([1]). Finally do a second split with ' ' to get the data but @@ -241,6 +254,7 @@ def _reduce_ntfsresize(partdev): with open('/tmp/command.log', 'ab', 0) as logfile: subprocess.run(cmd_resize, input='y', stderr=STDOUT, encoding='utf-8') + return 0 def _extend_resize2fs(partdev): cmd = shlex.split(f'resize2fs -f {partdev}') |