diff --git a/client/cli/bam.py b/client/cli/bam.py index 2ddb486..e99b2ff 100755 --- a/client/cli/bam.py +++ b/client/cli/bam.py @@ -220,7 +220,7 @@ class bam_session: paths_remove = {} 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) @@ -237,7 +237,7 @@ class bam_session: for f_rel, sha1 in paths_uuid.items(): f_abs = os.path.join(session_rootdir, f_rel) if os.path.exists(f_abs): - sha1_modified = sha1_from_file(f_abs) + sha1_modified = uuid_from_file(f_abs) if sha1_modified != sha1: paths_modified[f_rel] = f_abs if paths_uuid_update is not None: @@ -272,7 +272,7 @@ class bam_session: paths_add[f_rel] = f_abs 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 diff --git a/modules/bam_utils/system.py b/modules/bam_utils/system.py index 3174a72..7bb1902 100644 --- a/modules/bam_utils/system.py +++ b/modules/bam_utils/system.py @@ -45,13 +45,27 @@ else: 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: + # 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 - sha1 = hashlib.new('sha1') + sha1 = hashlib.new('sha512') while True: data = f.read(block_size) if not data: break sha1.update(data) - return sha1.hexdigest() + # skip the '0x' + return hex(size)[2:] + sha1.hexdigest() + diff --git a/modules/blendfile_pack.py b/modules/blendfile_pack.py index a70c281..2541839 100755 --- a/modules/blendfile_pack.py +++ b/modules/blendfile_pack.py @@ -270,23 +270,23 @@ def pack( del relbase 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: - 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 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 for dst in path_temp_files: k = os.path.relpath(dst[:-len(TEMP_SUFFIX)], base_dir_dst_temp).decode('utf-8') if k not in paths_uuid: - paths_uuid[k] = sha1_from_file(dst) + paths_uuid[k] = uuid_from_file(dst) del k del blendfile_dst_tmp - del sha1_from_file + del uuid_from_file # -------------------- # Handle File Copy/Zip diff --git a/webservice/bam/application/__init__.py b/webservice/bam/application/__init__.py index 2100627..72a7e58 100644 --- a/webservice/bam/application/__init__.py +++ b/webservice/bam/application/__init__.py @@ -375,9 +375,9 @@ class FileAPI(Resource): return else: # non blend-file - from bam_utils.system import sha1_from_file - paths_uuid[os.path.basename(filepath)] = sha1_from_file(filepath) - del sha1_from_file + from bam_utils.system import uuid_from_file + paths_uuid[os.path.basename(filepath)] = uuid_from_file(filepath) + del uuid_from_file import zipfile with zipfile.ZipFile(filepath_zip, 'w', zipfile.ZIP_DEFLATED) as zip_handle: