Autodownload optional pattern check to separate function to allow plugins
This commit is contained in:
parent
d1ad7e0850
commit
83b3dc8fbe
2 changed files with 9 additions and 5 deletions
|
@ -96,9 +96,9 @@ class ContentManager(object):
|
||||||
if old_content and old_content.get("files_optional", {}).get(relative_path):
|
if old_content and old_content.get("files_optional", {}).get(relative_path):
|
||||||
# We have the file in the old content
|
# We have the file in the old content
|
||||||
old_hash = old_content["files_optional"][relative_path].get("sha512")
|
old_hash = old_content["files_optional"][relative_path].get("sha512")
|
||||||
if old_hash != new_hash and self.site.settings.get("autodownloadoptional"):
|
if old_hash != new_hash and self.site.isDownloadable(file_inner_path):
|
||||||
changed.append(content_inner_dir + relative_path) # Download new file
|
changed.append(file_inner_path) # Download new file
|
||||||
elif old_hash != new_hash and not self.site.settings.get("own"):
|
elif old_hash != new_hash and self.hashfield.hasHash(old_hash) and not self.site.settings.get("own"):
|
||||||
try:
|
try:
|
||||||
self.optionalRemove(file_inner_path, old_hash, old_content["files_optional"][relative_path]["size"])
|
self.optionalRemove(file_inner_path, old_hash, old_content["files_optional"][relative_path]["size"])
|
||||||
self.site.storage.delete(file_inner_path)
|
self.site.storage.delete(file_inner_path)
|
||||||
|
@ -106,8 +106,8 @@ class ContentManager(object):
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
self.log.debug("Error deleting file %s: %s" % (file_inner_path, err))
|
self.log.debug("Error deleting file %s: %s" % (file_inner_path, err))
|
||||||
else: # The file is not in the old content
|
else: # The file is not in the old content
|
||||||
if self.site.settings.get("autodownloadoptional"):
|
if self.site.isDownloadable(file_inner_path):
|
||||||
changed.append(content_inner_dir + relative_path) # Download new file
|
changed.append(file_inner_path) # Download new file
|
||||||
|
|
||||||
# Check deleted
|
# Check deleted
|
||||||
if old_content:
|
if old_content:
|
||||||
|
|
|
@ -939,6 +939,10 @@ class Site(object):
|
||||||
self.log.debug("Queried hashfield from %s peers" % queried)
|
self.log.debug("Queried hashfield from %s peers" % queried)
|
||||||
return 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):
|
def delete(self):
|
||||||
self.settings["serving"] = False
|
self.settings["serving"] = False
|
||||||
self.saveSettings()
|
self.saveSettings()
|
||||||
|
|
Loading…
Reference in a new issue