Phase 2.9 complete
This commit is contained in:
@@ -92,6 +92,24 @@ def move_file_index(file_index, new_stored_path, kind=None):
|
||||
return file_index
|
||||
|
||||
|
||||
def refresh_file_index(file_index):
|
||||
"""Recompute size + md5 from the stored file. Needed after an in-place
|
||||
rewrite (e.g. injection of animationframework metadata) so downloads keep
|
||||
a correct Content-Length."""
|
||||
if not file_index.stored_path or not default_storage.exists(file_index.stored_path):
|
||||
return file_index
|
||||
with default_storage.open(file_index.stored_path, 'rb') as src:
|
||||
md5 = hashlib.md5()
|
||||
size = 0
|
||||
for chunk in iter(lambda: src.read(1024 * 1024), b''):
|
||||
md5.update(chunk)
|
||||
size += len(chunk)
|
||||
file_index.size = size
|
||||
file_index.md5 = md5.hexdigest()
|
||||
file_index.save(update_fields=['size', 'md5'])
|
||||
return file_index
|
||||
|
||||
|
||||
def delete_file_index(file_index):
|
||||
"""Remove an indexed file from disk and DB (safe no-op when None)."""
|
||||
if file_index is None:
|
||||
|
||||
Reference in New Issue
Block a user