_artifact: use win32-compatible named temp file

Use a win32-compatible named temporary file when saving public data in _artifact.

This avoids a win32 compatability issue, the 'name' member of tempfile.NamedTemporaryFile cannot be opened on Windows NT or later, as per the Python docs: https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile 734aa378

This fixes an issue experienced by @BenjaminSchubert on WSL.

Add a convenience context manager utils._tempnamedfile_name for when we only need the name of a temporary file. A directory path is required, to avoid security concerns with the system /tmp directory.

Changes proposed in this merge request:

  • _artifact.py: use utils._tempnamedfile_name
  • utils: add _tempnamedfile_name for win32 happiness
  • utils: fix yield type of _tempnamedfile
  • utils: indent 'with' continuation line

Alternatives considered:

  • Try to re-use the existing open file handle for I/O apart from linking

    • Open the temp file as binary, and use an io.TextIOWrapper to write the yaml. Turn off buffering or be sure to flush().
    • Add support to add_object() for a file-like object. This may make it too complicated.
  • Introduce an in-memory buffer, to avoid touching the disk at all. !1382 (closed)

    • This approach would have to be revisited when we integrate buildbox-casd.
    • We would have to modify _yaml in a number of places to be 'file or buffer'-agnostic.
Edited by Angelos Evripiotis

Merge request reports

Loading