mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-20 13:50:12 +01:00
Check sha256 sums via hashlib
This commit is contained in:
parent
ca7cea37f8
commit
6daeb625ab
@ -4,6 +4,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
import hashlib
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
def vagrant(params, cwd=None, printout=False):
|
def vagrant(params, cwd=None, printout=False):
|
||||||
@ -98,16 +99,26 @@ else:
|
|||||||
'http://dl.google.com/android/ndk/android-ndk-r9b-linux-x86-legacy-toolchains.tar.bz2',
|
'http://dl.google.com/android/ndk/android-ndk-r9b-linux-x86-legacy-toolchains.tar.bz2',
|
||||||
'606aadf815ae28cc7b0154996247c70d609f111b14e44bcbcd6cad4c87fefb6f')])
|
'606aadf815ae28cc7b0154996247c70d609f111b14e44bcbcd6cad4c87fefb6f')])
|
||||||
wanted = []
|
wanted = []
|
||||||
|
|
||||||
|
def sha256_for_file(path):
|
||||||
|
with open(path, 'r') as f:
|
||||||
|
s = hashlib.sha256()
|
||||||
|
while True:
|
||||||
|
data = f.read(4096)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
s.update(data)
|
||||||
|
return s.hexdigest()
|
||||||
|
|
||||||
for f, src, shasum in cachefiles:
|
for f, src, shasum in cachefiles:
|
||||||
if not os.path.exists(os.path.join(cachedir, f)):
|
relpath = os.path.join(cachedir, f)
|
||||||
|
if not os.path.exists(relpath):
|
||||||
print "Downloading " + f + " to cache"
|
print "Downloading " + f + " to cache"
|
||||||
if subprocess.call(['wget', src], cwd=cachedir) != 0:
|
if subprocess.call(['wget', src], cwd=cachedir) != 0:
|
||||||
print "...download of " + f + " failed."
|
print "...download of " + f + " failed."
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if shasum:
|
if shasum:
|
||||||
p = subprocess.Popen(['shasum', '-a', '256', os.path.join(cachedir, f)],
|
v = sha256_for_file(relpath)
|
||||||
stdout=subprocess.PIPE)
|
|
||||||
v = p.communicate()[0].split(' ')[0]
|
|
||||||
if v != shasum:
|
if v != shasum:
|
||||||
print "Invalid shasum of '" + v + "' detected for " + f
|
print "Invalid shasum of '" + v + "' detected for " + f
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user