diff --git a/src/python/jw/pkg/lib/ExecContext.py b/src/python/jw/pkg/lib/ExecContext.py index fd08ccd5..32abdf22 100644 --- a/src/python/jw/pkg/lib/ExecContext.py +++ b/src/python/jw/pkg/lib/ExecContext.py @@ -516,13 +516,14 @@ class ExecContext(Base): cmd: list[str] cmd_input: Input = InputMode.NonInteractive + tmp_file: str | None = None if wd is not None: path = wd + '/' + path cmds: list[RemoteCmd] = [] - stdout = (await __run(['mktemp', path + '.XXXXXX'])).stdout_str - if stdout is None: - raise Exception(f'Failed to create tmp-directory on {self.root}') - out = stdout.strip() if atomic else path + out = path + if atomic: + out = (await __run(['mktemp', path + '.XXXXXX'])).stdout_str.strip() + tmp_file = out cmds.append(RemoteCmd( cmd = ['tee', out], cmd_input = content, @@ -552,8 +553,11 @@ class ExecContext(Base): for cmd in cmds: log(DEBUG, f'{self.log_name}: Running {pretty_cmd(cmd.cmd, wd)}') ret = await __run(cmd.cmd) + tmp_file = None # Has been successfully moved at this point return ret finally: + if tmp_file is not None: + await self.erase(tmp_file) await self.close() except Exception as e: msg = f'Failed to get {path} from {self.root} ({str(e)})'