From 7aa68d0c8a69f70d24ed6119a6dc652e63558b79 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Tue, 6 Jun 2023 13:40:41 +0200 Subject: [PATCH] Fix 'api' command to stream output to avoid running out of memory --- osc/commandline.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index 5a33ede3..cc5ca69d 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -8700,20 +8700,22 @@ Please submit there instead, or use --nodevelproject to force direct submission. data=opts.data, file=opts.file, headers=opts.headers) - out = r.read() if opts.edit: + # to edit the output, we need to read all of it + # it's going to run ouf of memory if the data is too big + out = r.read() text = edit_text(out) r = http_request("PUT", url, data=text, headers=opts.headers) - out = r.read() - if isinstance(out, str): - sys.stdout.write(out) - else: - sys.stdout.buffer.write(out) + while True: + data = r.read(8192) + if not data: + break + sys.stdout.buffer.write(data) @cmdln.option('-b', '--bugowner-only', action='store_true', help='Show only the bugowner')