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
Showing only changes of commit e07c52eda8 - Show all commits

lib.ExecContext: Clean up temp file in _put()

_put() writes the content into a temporary file with tee and, when
atomic is set, moves it to the target path with a final mv. The loop
over the command list sets tmp_file to None after each command, on the
assumption stated in the comment that the file has been moved at that
point - which is only true for the last command. When a chown, chmod,
or mv after the tee fails, the finally block finds tmp_file is None
and leaves the temporary file behind.

Reset tmp_file only after all commands have completed, so that the
finally block erases the temporary file whenever a step fails.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
Jan Lindemann 2026-08-16 06:57:57 +02:00
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -553,7 +553,7 @@ class ExecContext(Base):
for cmd in cmds:
log(DEBUG, f'{self.log_name}: Running {pretty_cmd(cmd.cmd, wd)}')
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
finally:
if tmp_file is not None: