lib.ExecContext, lib.FileContext: Fix temp file leak and log messages #86

Merged
Jan Lindemann merged 3 commits from jan/fix/20260905-lib-execcontext-lib-filecontext-fix-temp-file-leak-and-log-messages into master 2026-09-05 19:45:29 +02:00 AGit
2 changed files with 3 additions and 3 deletions

View file

@ -553,14 +553,14 @@ class ExecContext(Base):
for cmd in cmds: for cmd in cmds:
log(DEBUG, f'{self.log_name}: Running {pretty_cmd(cmd.cmd, wd)}') log(DEBUG, f'{self.log_name}: Running {pretty_cmd(cmd.cmd, wd)}')
ret = await __run(cmd.cmd, cmd_input = cmd.cmd_input) ret = await __run(cmd.cmd, cmd_input = cmd.cmd_input)
tmp_file = None # Has been successfully moved at this point tmp_file = None # All commands, including the final mv, succeeded
return ret return ret
finally: finally:
if tmp_file is not None: if tmp_file is not None:
await self.erase(tmp_file) await self.erase(tmp_file)
await self.close() await self.close()
except Exception as e: except Exception as e:
msg = f'Failed to get {path} from {self.root} ({str(e)})' msg = f'Failed to put content to {path} on {self.root} ({str(e)})'
if throw: if throw:
raise Exception(msg) raise Exception(msg)
log(ERR, msg) log(ERR, msg)

View file

@ -287,7 +287,7 @@ class FileContext(abc.ABC):
DEBUG, DEBUG,
( (
f"{self.log_name} doesn't implement stat(), judging by trailing " f"{self.log_name} doesn't implement stat(), judging by trailing "
'slash if {path} is a directory' f'slash if {path} is a directory'
), ),
) )
return path[-1] == '/' return path[-1] == '/'