From 82774a1ae37451ed413ec3ccd796229a0454bbd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20O=2E=20V=C3=A1zquez?= Date: Sun, 15 Oct 2023 15:38:50 -0600 Subject: [PATCH] Rename the partial file to its proper name before writing metadata because, metadata will have '.partial' in it's name; and variety won't be able to find it later --- variety/plugins/downloaders/DefaultDownloader.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/variety/plugins/downloaders/DefaultDownloader.py b/variety/plugins/downloaders/DefaultDownloader.py index d09903b9..27d24f08 100644 --- a/variety/plugins/downloaders/DefaultDownloader.py +++ b/variety/plugins/downloaders/DefaultDownloader.py @@ -248,6 +248,9 @@ def save_locally( Util.safe_unlink(local_filepath_partial) return None + # file rename is an atomic operation, so we should never end up with partial downloads + os.rename(local_filepath_partial, local_filepath) + metadata = { "sourceType": source_type, "sourceName": source_name, @@ -256,9 +259,7 @@ def save_locally( "imageURL": image_url, } metadata.update(extra_metadata or {}) - Util.write_metadata(local_filepath_partial, metadata) + Util.write_metadata(local_filepath, metadata) - # file rename is an atomic operation, so we should never end up with partial downloads - os.rename(local_filepath_partial, local_filepath) logger.info(lambda: "Download complete") return local_filepath