From 80cee500e0ef0cf4de84b8b60b35c25f667e7a34 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 8 May 2022 18:36:32 +0200 Subject: SysCommand now sets working_directory on SysCommandWorker. Also made it so the parent process moves back to the original working directory, leaving the child process in the target working directory. (#1142) --- archinstall/lib/general.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index 174acb8a..cf925de3 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -352,7 +352,6 @@ class SysCommandWorker: # only way to get the traceback without loosing it. self.pid, self.child_fd = pty.fork() - os.chdir(old_dir) # https://stackoverflow.com/questions/4022600/python-pty-fork-how-does-it-work if not self.pid: @@ -371,6 +370,9 @@ class SysCommandWorker: log(f"{self.cmd[0]} does not exist.", level=logging.ERROR, fg="red") self.exit_code = 1 return False + else: + # Only parent process moves back to the original working directory + os.chdir(old_dir) self.started = time.time() self.poll_object.register(self.child_fd, EPOLLIN | EPOLLHUP) @@ -457,7 +459,14 @@ class SysCommand: if self.session: return self.session - with SysCommandWorker(self.cmd, callbacks=self._callbacks, peak_output=self.peak_output, environment_vars=self.environment_vars, remove_vt100_escape_codes_from_lines=self.remove_vt100_escape_codes_from_lines) as session: + with SysCommandWorker( + self.cmd, + callbacks=self._callbacks, + peak_output=self.peak_output, + environment_vars=self.environment_vars, + remove_vt100_escape_codes_from_lines=self.remove_vt100_escape_codes_from_lines, + working_directory=self.working_directory) as session: + if not self.session: self.session = session -- cgit v1.2.3-70-g09d2