summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/live/ogOperations.py73
1 files changed, 27 insertions, 46 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index 6703041..cfe05f6 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -190,28 +190,14 @@ class OgLiveOperations:
if not os.path.exists(image_path):
raise RuntimeError(f'Image not found at {image_path} during image restore')
- proc_lzop = subprocess.Popen(cmd_lzop,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- proc_pc = subprocess.Popen(cmd_pc,
- stdin=proc_lzop.stdout,
- stderr=subprocess.PIPE)
-
- pc_stderr = proc_pc.communicate()[1]
- lzop_stderr = proc_lzop.stderr.read()
- proc_lzop.poll() # update returncode
-
with open('/tmp/command.log', 'wb', 0) as logfile:
- logfile.write(lzop_stderr)
- logfile.write(pc_stderr)
-
- if proc_lzop.returncode != 0:
- raise OSError(f'lzop subprocess failed: {lzop_stderr.decode("utf-8")}')
-
- if proc_pc.returncode != 0:
- raise OSError(f'partclone subprocess failed: {pc_stderr.decode("utf-8")}')
-
- logging.info('Image restore successful')
+ proc_lzop = subprocess.Popen(cmd_lzop,
+ stdout=subprocess.PIPE)
+ proc_pc = subprocess.Popen(cmd_pc,
+ stdin=proc_lzop.stdout,
+ stderr=logfile)
+ proc_lzop.stdout.close()
+ proc_pc.communicate()
def _ogbrowser_clear_logs(self):
logfiles = ['/tmp/command.log', '/tmp/session.log']
@@ -465,37 +451,32 @@ class OgLiveOperations:
if ogReduceFs(disk, partition) == -1:
raise ValueError(f'Failed to shrink {fstype} filesystem in {padev}')
+ cmd1 = shlex.split(f'partclone.{fstype} -I -C --clone -s {padev} -O -')
+ cmd2 = shlex.split(f'lzop -1 -fo {image_path}')
+
+ logfile = open('/tmp/command.log', 'wb', 0)
+
if os.path.exists(image_path) and backup:
shutil.move(image_path, f'{image_path}.ant')
+ p1 = Popen(cmd1, stdout=PIPE, stderr=logfile)
+ p2 = Popen(cmd2, stdin=p1.stdout)
+ p1.stdout.close()
+
logging.info(f'Creating image at {image_path} from {padev} using {fstype}')
logging.info('*DO NOT REBOOT OR POWEROFF* the client during this time')
- cmd_pc = shlex.split(f'partclone.{fstype} -I -C --clone -s {padev} -O -')
- cmd_lzop = shlex.split(f'lzop -1 -fo {image_path}')
-
- proc_pc = subprocess.Popen(cmd_pc,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- proc_lzop = subprocess.Popen(cmd_lzop,
- stdin=proc_pc.stdout,
- stderr=subprocess.PIPE)
-
- lzop_stderr = proc_lzop.communicate()[1]
- pc_stderr = proc_pc.stderr.read()
- proc_pc.poll() # update returncode
-
- with open('/tmp/command.log', 'wb', 0) as logfile:
- logfile.write(pc_stderr)
- logfile.write(lzop_stderr)
-
- if proc_pc.returncode != 0:
- raise OSError(f'partclone subprocess failed: {pc_stderr.decode("utf-8")}')
-
- if proc_lzop.returncode != 0:
- raise OSError(f'lzop subprocess failed: {lzop_stderr.decode("utf-8")}')
-
- logging.info('Image creation successful')
+ try:
+ retdata = p2.communicate()
+ except OSError as e:
+ raise OSError(f'Unexpected error when running partclone and lzop commands: {e}') from e
+ finally:
+ logfile.close()
+ p2.terminate()
+ p1.poll()
+
+ logging.info(f'partclone process exited with code {p1.returncode}')
+ logging.info(f'lzop process exited with code {p2.returncode}')
ogExtendFs(disk, partition)