From 504ac68b40b211e48a6625a82cefbb149507ede4 Mon Sep 17 00:00:00 2001 From: debanjandhar12 <49021233+debanjandhar12@users.noreply.github.com> Date: Mon, 6 Jun 2022 13:47:22 +0530 Subject: [PATCH] Fix storeMediaFile logic Currently, when `skip` is true and `deleteExisting` is true the `storeMediaFile` will simply delete the media file. However, the intended behavior should be to not touch the media file when both conditions are true. --- plugin/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/__init__.py b/plugin/__init__.py index e51bbeb..93c92d0 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -650,8 +650,6 @@ class AnkiConnect: def storeMediaFile(self, filename, data=None, path=None, url=None, skipHash=None, deleteExisting=True): if not (data or path or url): raise Exception('You must provide a "data", "path", or "url" field.') - if deleteExisting: - self.deleteMediaFile(filename) if data: mediaData = base64.b64decode(data) elif path: @@ -669,6 +667,8 @@ class AnkiConnect: if skip: return None + if deleteExisting: + self.deleteMediaFile(filename) return self.media().writeData(filename, mediaData)