From 7b93d11d841aee8da7825d7608ac1308944d88d9 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Tue, 14 Jul 2020 21:51:38 +0200 Subject: [PATCH] [fix] add plugin sha sum check to be able to copy updated resources --- searx/plugins/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/searx/plugins/__init__.py b/searx/plugins/__init__.py index 66ff93c2a..8742dc2d6 100644 --- a/searx/plugins/__init__.py +++ b/searx/plugins/__init__.py @@ -15,6 +15,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >. (C) 2015 by Adam Tauber, ''' +from hashlib import sha256 from importlib import import_module from os.path import abspath, basename, dirname, exists, join from shutil import copyfile @@ -109,7 +110,7 @@ def check_resource(base_path, resource_path, name, dir_prefix): file_name = basename(dep_path) resource_name = '{0}_{1}'.format('_'.join(name.split()), file_name) resource_path = join(static_path, 'plugins', dir_prefix, resource_name) - if not exists(resource_path): + if not exists(resource_path) or sha_sum(dep_path) != sha_sum(resource_path): try: copyfile(dep_path, resource_path) except: @@ -133,6 +134,12 @@ def fix_package_resources(pkg, name): ]) +def sha_sum(filename): + with open(filename,"rb") as f: + bytes = f.read() # read entire file as bytes + return sha256(bytes).hexdigest() + + plugins = PluginStore() plugins.register(oa_doi_rewrite) plugins.register(https_rewrite)