Replace SHA1 with hex(length) + sha512
This commit is contained in:
@@ -220,7 +220,7 @@ class bam_session:
|
|||||||
paths_remove = {}
|
paths_remove = {}
|
||||||
paths_modified = {}
|
paths_modified = {}
|
||||||
|
|
||||||
from bam_utils.system import sha1_from_file
|
from bam_utils.system import uuid_from_file
|
||||||
|
|
||||||
session_rootdir = os.path.abspath(session_rootdir)
|
session_rootdir = os.path.abspath(session_rootdir)
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ class bam_session:
|
|||||||
for f_rel, sha1 in paths_uuid.items():
|
for f_rel, sha1 in paths_uuid.items():
|
||||||
f_abs = os.path.join(session_rootdir, f_rel)
|
f_abs = os.path.join(session_rootdir, f_rel)
|
||||||
if os.path.exists(f_abs):
|
if os.path.exists(f_abs):
|
||||||
sha1_modified = sha1_from_file(f_abs)
|
sha1_modified = uuid_from_file(f_abs)
|
||||||
if sha1_modified != sha1:
|
if sha1_modified != sha1:
|
||||||
paths_modified[f_rel] = f_abs
|
paths_modified[f_rel] = f_abs
|
||||||
if paths_uuid_update is not None:
|
if paths_uuid_update is not None:
|
||||||
@@ -272,7 +272,7 @@ class bam_session:
|
|||||||
paths_add[f_rel] = f_abs
|
paths_add[f_rel] = f_abs
|
||||||
|
|
||||||
if paths_uuid_update is not None:
|
if paths_uuid_update is not None:
|
||||||
paths_uuid_update[f_rel] = sha1_from_file(f_abs)
|
paths_uuid_update[f_rel] = uuid_from_file(f_abs)
|
||||||
|
|
||||||
return paths_add, paths_remove, paths_modified
|
return paths_add, paths_remove, paths_modified
|
||||||
|
|
||||||
|
@@ -45,13 +45,27 @@ else:
|
|||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
||||||
def sha1_from_file(fn, block_size=1 << 20):
|
def uuid_from_file(fn, block_size=1 << 20):
|
||||||
|
"""
|
||||||
|
Returns an arbitrary sized unique ASCII string based on the file contents.
|
||||||
|
(exact hashing method may change).
|
||||||
|
"""
|
||||||
with open(fn, 'rb') as f:
|
with open(fn, 'rb') as f:
|
||||||
|
# first get the size
|
||||||
|
import os
|
||||||
|
f.seek(0, os.SEEK_END)
|
||||||
|
size = f.tell()
|
||||||
|
f.seek(0, os.SEEK_SET)
|
||||||
|
del os
|
||||||
|
# done!
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
sha1 = hashlib.new('sha1')
|
sha1 = hashlib.new('sha512')
|
||||||
while True:
|
while True:
|
||||||
data = f.read(block_size)
|
data = f.read(block_size)
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
sha1.update(data)
|
sha1.update(data)
|
||||||
return sha1.hexdigest()
|
# skip the '0x'
|
||||||
|
return hex(size)[2:] + sha1.hexdigest()
|
||||||
|
|
||||||
|
@@ -270,23 +270,23 @@ def pack(
|
|||||||
del relbase
|
del relbase
|
||||||
|
|
||||||
if paths_uuid is not None:
|
if paths_uuid is not None:
|
||||||
from bam_utils.system import sha1_from_file
|
from bam_utils.system import uuid_from_file
|
||||||
|
|
||||||
for src, dst in path_copy_files:
|
for src, dst in path_copy_files:
|
||||||
paths_uuid[os.path.relpath(dst, base_dir_dst).decode('utf-8')] = sha1_from_file(src)
|
paths_uuid[os.path.relpath(dst, base_dir_dst).decode('utf-8')] = uuid_from_file(src)
|
||||||
# XXX, better way to store temp target
|
# XXX, better way to store temp target
|
||||||
blendfile_dst_tmp = temp_remap_cb(blendfile_src, base_dir_src)
|
blendfile_dst_tmp = temp_remap_cb(blendfile_src, base_dir_src)
|
||||||
paths_uuid[os.path.basename(blendfile_src).decode('utf-8')] = sha1_from_file(blendfile_dst_tmp)
|
paths_uuid[os.path.basename(blendfile_src).decode('utf-8')] = uuid_from_file(blendfile_dst_tmp)
|
||||||
|
|
||||||
# blend libs
|
# blend libs
|
||||||
for dst in path_temp_files:
|
for dst in path_temp_files:
|
||||||
k = os.path.relpath(dst[:-len(TEMP_SUFFIX)], base_dir_dst_temp).decode('utf-8')
|
k = os.path.relpath(dst[:-len(TEMP_SUFFIX)], base_dir_dst_temp).decode('utf-8')
|
||||||
if k not in paths_uuid:
|
if k not in paths_uuid:
|
||||||
paths_uuid[k] = sha1_from_file(dst)
|
paths_uuid[k] = uuid_from_file(dst)
|
||||||
del k
|
del k
|
||||||
|
|
||||||
del blendfile_dst_tmp
|
del blendfile_dst_tmp
|
||||||
del sha1_from_file
|
del uuid_from_file
|
||||||
|
|
||||||
# --------------------
|
# --------------------
|
||||||
# Handle File Copy/Zip
|
# Handle File Copy/Zip
|
||||||
|
@@ -375,9 +375,9 @@ class FileAPI(Resource):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# non blend-file
|
# non blend-file
|
||||||
from bam_utils.system import sha1_from_file
|
from bam_utils.system import uuid_from_file
|
||||||
paths_uuid[os.path.basename(filepath)] = sha1_from_file(filepath)
|
paths_uuid[os.path.basename(filepath)] = uuid_from_file(filepath)
|
||||||
del sha1_from_file
|
del uuid_from_file
|
||||||
|
|
||||||
import zipfile
|
import zipfile
|
||||||
with zipfile.ZipFile(filepath_zip, 'w', zipfile.ZIP_DEFLATED) as zip_handle:
|
with zipfile.ZipFile(filepath_zip, 'w', zipfile.ZIP_DEFLATED) as zip_handle:
|
||||||
|
Reference in New Issue
Block a user