From 25c532881e3927835c02e41ae5b835a7c0d586f8 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 23 Jan 2020 18:56:11 -0700 Subject: [PATCH 1/2] Allow custom temp file suffixes --- scripts/wk/os/linux.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/wk/os/linux.py b/scripts/wk/os/linux.py index 3a8c346d..060279d1 100644 --- a/scripts/wk/os/linux.py +++ b/scripts/wk/os/linux.py @@ -56,9 +56,12 @@ def get_user_name(): return user -def make_temp_file(): +def make_temp_file(suffix=None): """Make temporary file, returns pathlib.Path() obj.""" - proc = run_program(['mktemp'], check=False) + cmd = ['mktemp'] + if suffix: + cmd.append(f'--suffix={suffix}') + proc = run_program(cmd) return pathlib.Path(proc.stdout.strip()) From 9c95dcbd5c6f1f8214e190d9eb522ce7fad107ec Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 23 Jan 2020 18:56:27 -0700 Subject: [PATCH 2/2] Fixed CoreStorage scanning * Dropped use of mktemp since sudo was interferrring * Fixed crash if timeout occurred --- scripts/wk/os/linux.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/wk/os/linux.py b/scripts/wk/os/linux.py index 060279d1..7c38a03f 100644 --- a/scripts/wk/os/linux.py +++ b/scripts/wk/os/linux.py @@ -10,6 +10,7 @@ import subprocess from wk import std from wk.exe import popen_program, run_program from wk.hw.obj import Disk +from wk.log import format_log_path # STATIC VARIABLES @@ -181,7 +182,7 @@ def scan_corestorage_container(container, timeout=300): # TODO: Test Scanning CoreStorage containers detected_volumes = {} inner_volumes = [] - log_path = make_temp_file() + log_path = format_log_path(log_name=f'{container.path.name}_testdisk') # Run scan via TestDisk cmd = [ @@ -191,12 +192,12 @@ def scan_corestorage_container(container, timeout=300): '/log', '/cmd', container.path, 'partition_none,analyze', ] - proc = popen_program(cmd) + proc = popen_program(cmd, pipe=True) try: proc.wait(timeout=timeout) except subprocess.TimeoutExpired: # Failed to find any volumes, stop scan - run_program(['sudo', 'kill', proc.pid], check=False) + run_program(['sudo', 'kill', str(proc.pid)], check=False) # Check results if proc.returncode == 0 and log_path.exists():