fix(playout): remove empty file when the download request failed (#2864)

This commit is contained in:
Jonas L 2024-01-01 13:16:13 +01:00 committed by GitHub
parent 72268ad9bb
commit 2facbfaff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -50,16 +50,18 @@ class PypoFile(Thread):
file_event.local_filepath, file_event.local_filepath,
) )
try: try:
with file_event.local_filepath.open("wb") as file_fd: try:
try: with file_event.local_filepath.open("wb") as file_fd:
response = self.api_client.download_file(file_event.id, stream=True) response = self.api_client.download_file(file_event.id, stream=True)
for chunk in response.iter_content(chunk_size=8192): for chunk in response.iter_content(chunk_size=8192):
file_fd.write(chunk) file_fd.write(chunk)
except requests.exceptions.HTTPError as exception: except requests.exceptions.HTTPError as exception:
raise RuntimeError( file_event.local_filepath.unlink(missing_ok=True)
f"could not download file {file_event.id}"
) from exception raise RuntimeError(
f"could not download file {file_event.id}"
) from exception
# make file world readable and owner writable # make file world readable and owner writable
file_event.local_filepath.chmod(0o644) file_event.local_filepath.chmod(0o644)