diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-02-14 12:20:46 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-02-14 12:28:28 +0100 |
commit | 478c4447be20380c5b173f8e150d2373cf6d021b (patch) | |
tree | 20a498b81f8dfa0073606388b46161fb2b6983d4 /src/utils/fs.py | |
parent | c1529c5eec2d782a38e07077388e780970788ffe (diff) |
src: improve error check in image_create and image_restore
cover more error cases where exceptions need to be raised.
check return code in the invoked subprocess.
restoreImageCustom has been intentionally left behind, it
is unclear what this custom script returns on success and
error.
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}') |