Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save YoungerDryas89/38091454accc60a3e0e8456e7a9ca2d0 to your computer and use it in GitHub Desktop.
Save YoungerDryas89/38091454accc60a3e0e8456e7a9ca2d0 to your computer and use it in GitHub Desktop.
variety-0.8.10 patches
diff --git a/variety/Util.py b/variety/Util.py
index a610f32..47f0f1f 100644
--- a/variety/Util.py
+++ b/variety/Util.py
@@ -558,6 +558,10 @@ class Util:
except Exception as e:
# could not read metadata inside file, try reading json metadata instead
try:
+ # Accommodate for this bug: https://github.com/varietywalls/variety/pull/650
+ if os.path.exists(filename + ".partial.metadata.json"):
+ filename += ".partial"
+
with open(filename + ".metadata.json", encoding="utf8") as f:
return json.loads(f.read())
diff --git a/variety/plugins/downloaders/DefaultDownloader.py b/variety/plugins/downloaders/DefaultDownloader.py
index 27d24f0..d09903b 100644
--- a/variety/plugins/downloaders/DefaultDownloader.py
+++ b/variety/plugins/downloaders/DefaultDownloader.py
@@ -248,9 +248,6 @@ class DefaultDownloader(Downloader, metaclass=abc.ABCMeta):
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,
@@ -259,7 +256,9 @@ class DefaultDownloader(Downloader, metaclass=abc.ABCMeta):
"imageURL": image_url,
}
metadata.update(extra_metadata or {})
- Util.write_metadata(local_filepath, metadata)
+ Util.write_metadata(local_filepath_partial, 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment