on master help sign in
[fix] add plugin sha sum check to be able to copy updated resources
7b93d11Adam Tauber
searx/plugins/__init__.py+8−1
@@ -15,6 +15,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
15(C) 2015 by Adam Tauber, <asciimoo@gmail.com>
15(C) 2015 by Adam Tauber, <asciimoo@gmail.com>
16'''
16'''
17
17
18+from hashlib import sha256
18from importlib import import_module
19from importlib import import_module
19from os.path import abspath, basename, dirname, exists, join
20from os.path import abspath, basename, dirname, exists, join
20from shutil import copyfile
21from shutil import copyfile
@@ -109,7 +110,7 @@ def check_resource(base_path, resource_path, name, dir_prefix):
109 file_name = basename(dep_path)
110 file_name = basename(dep_path)
110 resource_name = '{0}_{1}'.format('_'.join(name.split()), file_name)
111 resource_name = '{0}_{1}'.format('_'.join(name.split()), file_name)
111 resource_path = join(static_path, 'plugins', dir_prefix, resource_name)
112 resource_path = join(static_path, 'plugins', dir_prefix, resource_name)
112− if not exists(resource_path):
113+ if not exists(resource_path) or sha_sum(dep_path) != sha_sum(resource_path):
113 try:
114 try:
114 copyfile(dep_path, resource_path)
115 copyfile(dep_path, resource_path)
115 except:
116 except:
@@ -133,6 +134,12 @@ def fix_package_resources(pkg, name):
133 ])
134 ])
134
135
135
136
137+def sha_sum(filename):
138+ with open(filename,"rb") as f:
139+ bytes = f.read() # read entire file as bytes
140+ return sha256(bytes).hexdigest()
141+
142+
136plugins = PluginStore()
143plugins = PluginStore()
137plugins.register(oa_doi_rewrite)
144plugins.register(oa_doi_rewrite)
138plugins.register(https_rewrite)
145plugins.register(https_rewrite)