Added md5 validation to the resource copy

This commit is contained in:
NoHomoBoi 2020-08-08 22:51:19 -05:00
parent 78d5c1b7b6
commit c9fe88e193
1 changed files with 12 additions and 2 deletions

View File

@ -5,6 +5,14 @@ import os
import os.path import os.path
import zipfile import zipfile
from shutil import copyfile from shutil import copyfile
import hashlib
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
if len(sys.argv) < 3: if len(sys.argv) < 3:
print('usage: mkzip <lstfile> <dstpath>') print('usage: mkzip <lstfile> <dstpath>')
@ -21,9 +29,11 @@ with open(sys.argv[1], 'r') as f:
for (fname, aname) in lst: for (fname, aname) in lst:
path = os.path.join(sys.argv[2], aname) path = os.path.join(sys.argv[2], aname)
if not os.path.exists(path): old_md5 = md5(fname);
new_md5 = md5(path);
if not os.path.exists(path) or old_md5 != new_md5:
os.makedirs(os.path.dirname(path), exist_ok=True) os.makedirs(os.path.dirname(path), exist_ok=True)
copyfile(fname, path) copyfile(fname, path)
print("Copying: " + path) print("Copying: " + path)
else: else:
print("Skipping: " + path) print("Skipping: " + path + " - MD5: "+md5(fname))