From 83b3dc8fbe429cdcf7d737eebb06a1410dbf5436 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Mon, 7 Nov 2016 23:39:04 +0100 Subject: [PATCH] Autodownload optional pattern check to separate function to allow plugins --- src/Content/ContentManager.py | 10 +++++----- src/Site/Site.py | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Content/ContentManager.py b/src/Content/ContentManager.py index 5da9d340..cb9db3af 100644 --- a/src/Content/ContentManager.py +++ b/src/Content/ContentManager.py @@ -96,9 +96,9 @@ class ContentManager(object): if old_content and old_content.get("files_optional", {}).get(relative_path): # We have the file in the old content old_hash = old_content["files_optional"][relative_path].get("sha512") - if old_hash != new_hash and self.site.settings.get("autodownloadoptional"): - changed.append(content_inner_dir + relative_path) # Download new file - elif old_hash != new_hash and not self.site.settings.get("own"): + if old_hash != new_hash and self.site.isDownloadable(file_inner_path): + changed.append(file_inner_path) # Download new file + elif old_hash != new_hash and self.hashfield.hasHash(old_hash) and not self.site.settings.get("own"): try: self.optionalRemove(file_inner_path, old_hash, old_content["files_optional"][relative_path]["size"]) self.site.storage.delete(file_inner_path) @@ -106,8 +106,8 @@ class ContentManager(object): except Exception, err: self.log.debug("Error deleting file %s: %s" % (file_inner_path, err)) else: # The file is not in the old content - if self.site.settings.get("autodownloadoptional"): - changed.append(content_inner_dir + relative_path) # Download new file + if self.site.isDownloadable(file_inner_path): + changed.append(file_inner_path) # Download new file # Check deleted if old_content: diff --git a/src/Site/Site.py b/src/Site/Site.py index c3e48a84..bf131efd 100644 --- a/src/Site/Site.py +++ b/src/Site/Site.py @@ -939,6 +939,10 @@ class Site(object): self.log.debug("Queried hashfield from %s peers" % queried) return queried + # Returns if the optional file is need to be downloaded or not + def isDownloadable(self, inner_path): + return self.settings.get("autodownloadoptional") + def delete(self): self.settings["serving"] = False self.saveSettings()