diff --git a/playout/libretime_playout/player/file.py b/playout/libretime_playout/player/file.py index 98fa779ca..c947289c5 100644 --- a/playout/libretime_playout/player/file.py +++ b/playout/libretime_playout/player/file.py @@ -50,16 +50,18 @@ class PypoFile(Thread): 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)