lib.ExecContext, lib.FileContext: Fix temp file leak and log messages #86
Loading…
Reference in a new issue
No description provided.
Delete branch "jan/fix/20260905-lib-execcontext-lib-filecontext-fix-temp-file-leak-and-log-messages"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR adds three independent fixes to the ExecContext and FileContext helpers, each correcting a defect in temp file cleanup, error reporting, or debug logging. All have been found and fixed by AI.
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.
lib.FileContext: Interpolate path in _is_dir()
_is_dir() logs a DEBUG message when _stat() is not implemented and it must guess from the trailing slash whether a path is a directory. The second part of that message is a plain string rather than an f-string, so '{path}' is logged verbatim instead of the path.
Make it an f-string so the path is interpolated.
lib.ExecContext: Fix error message in _put()
_put() catches a failure of the remote command sequence and logs "Failed to get from ", a phrase copied over from the get() path. This path, however, pushes content, so the message describes the wrong operation.
Log a put-oriented message instead.
_is_dir() logs a DEBUG message when _stat() is not implemented and it must guess from the trailing slash whether a path is a directory. The second part of that message is a plain string rather than an f-string, so '{path}' is logged verbatim instead of the path. Make it an f-string so the path is interpolated. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2 Signed-off-by: Jan Lindemann <jan@janware.com>