Skip to content

Conversation

@torcolvin
Copy link
Collaborator

CBG-5065 sgcollect: remove tmpdir

  • Removes tmpdir on any exception. This fixes an accidental regression in d8f6cfe which removed the atexit handling. Using a context manager is more robust than atexit since it will cover SIGTERM exiting as well.
  • Handle removing zipfile in a finally statement earlier if it fails in runner.redact_and_zip or runner.zip

Most changes are whitespace only to indent.

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Copilot AI review requested due to automatic review settings January 5, 2026 18:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a regression in temporary directory cleanup for the sgcollect tool by implementing a context manager pattern for TaskRunner. The key changes ensure that temporary directories are properly cleaned up in all execution paths, including exceptions and SIGTERM signals.

Key Changes:

  • Converted TaskRunner to a context manager with __enter__ and __exit__ methods for automatic cleanup
  • Restructured exception handling in the main flow to ensure zip files are deleted even if zipping or upload operations fail
  • Added comprehensive test coverage to verify temporary directory cleanup across various scenarios

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tools/tasks.py Added context manager implementation to TaskRunner class with cleanup in __exit__
tools/sgcollect.py Changed TaskRunner instantiation to use context manager pattern and restructured exception handling
tools-tests/upload_test.py Added test fixture for temporary workdir and assertions to verify cleanup in all test cases

exit_code = do_upload(zip_filename, upload_url, options.upload_proxy)
sys.exit(exit_code)
finally:
if not options.keep_zip and upload_url:
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition not options.keep_zip and upload_url will prevent zip deletion when upload_url is empty/None, even without the --keep-zip flag. This changes the behavior: previously, zips were deleted in the finally block regardless of upload_url when --keep-zip was not set. Now they're only deleted when an upload URL exists. This could leave zip files behind when no upload is performed. Consider if this behavior change is intended or if the condition should be if not options.keep_zip:.

Suggested change
if not options.keep_zip and upload_url:
if not options.keep_zip:

Copilot uses AI. Check for mistakes.
@RIT3shSapata RIT3shSapata self-assigned this Jan 6, 2026
@torcolvin torcolvin merged commit 00cbdeb into main Jan 6, 2026
43 checks passed
@torcolvin torcolvin deleted the CBG-5065 branch January 6, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants