From e2582ecb3eafd8df20bbb9b616669b71131ecc97 Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Sun, 23 May 2021 12:17:14 +1000 Subject: [PATCH] Catch error with MacOS writing per issue #407 --- bdfr/downloader.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bdfr/downloader.py b/bdfr/downloader.py index 4a13823..a262dae 100644 --- a/bdfr/downloader.py +++ b/bdfr/downloader.py @@ -94,9 +94,13 @@ class RedditDownloader(RedditConnector): f'Hard link made linking {destination} to {self.master_hash_list[resource_hash]}' f' in submission {submission.id}') return - with open(destination, 'wb') as file: - file.write(res.content) - logger.debug(f'Written file to {destination}') + try: + with open(destination, 'wb') as file: + file.write(res.content) + logger.debug(f'Written file to {destination}') + except OSError as e: + logger.exception(e) + logger.error(f'Failed to write file to {destination} in submission {submission.id}: {e}') creation_time = time.mktime(datetime.fromtimestamp(submission.created_utc).timetuple()) os.utime(destination, (creation_time, creation_time)) self.master_hash_list[resource_hash] = destination