From c77c413b89a001f0379690a9073d64680fdb8289 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 23 Jun 2022 17:30:40 +0200 Subject: ssh: use tarfile as a context manager --- mdbp/ssh.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mdbp/ssh.py b/mdbp/ssh.py index e53b23f..8445dc7 100644 --- a/mdbp/ssh.py +++ b/mdbp/ssh.py @@ -32,17 +32,17 @@ def produce_request_tar(buildjsonobj: JsonObject, else: sendjsonobj["input"] = sendjsonobj["input"].copy() sendjsonobj["input"]["source_package_path"] = dscpath.name - tar = tarfile.open(mode="w|", fileobj=fileobj) - info = tarfile.TarInfo("build.json") - sendjsonfile = io.BytesIO() - for chunk in json.JSONEncoder().iterencode(sendjsonobj): - sendjsonfile.write(chunk.encode("utf8")) - info.size = sendjsonfile.tell() - sendjsonfile.seek(0) - tar.addfile(info, sendjsonfile) - if dscpath: - for path in [dscpath] + get_dsc_files(dscpath): - tar_add(tar, path) + with tarfile.open(mode="w|", fileobj=fileobj) as tar: + info = tarfile.TarInfo("build.json") + sendjsonfile = io.BytesIO() + for chunk in json.JSONEncoder().iterencode(sendjsonobj): + sendjsonfile.write(chunk.encode("utf8")) + info.size = sendjsonfile.tell() + sendjsonfile.seek(0) + tar.addfile(info, sendjsonfile) + if dscpath: + for path in [dscpath] + get_dsc_files(dscpath): + tar_add(tar, path) def main() -> None: """Entry point for mdbp-ssh backend""" -- cgit v1.2.3