Skip to content

Commit

Permalink
fix(playout): remove empty file when the download request failed (#2864)
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Jan 1, 2024
1 parent 72268ad commit 2facbfa
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions playout/libretime_playout/player/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ def copy_file(self, file_event: FileEvent):
file_event.local_filepath,
)
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)
for chunk in response.iter_content(chunk_size=8192):
file_fd.write(chunk)

except requests.exceptions.HTTPError as exception:
raise RuntimeError(
f"could not download file {file_event.id}"
) from exception
except requests.exceptions.HTTPError as exception:
file_event.local_filepath.unlink(missing_ok=True)

raise RuntimeError(
f"could not download file {file_event.id}"
) from exception

# make file world readable and owner writable
file_event.local_filepath.chmod(0o644)
Expand Down

0 comments on commit 2facbfa

Please sign in to comment.