duplicate: close file context after read

This commit is contained in:
Alexandre Iooss 2021-12-05 13:38:57 +01:00
parent 989c1803fd
commit 3350dd2f8d

View file

@ -54,7 +54,8 @@ def find_duplicate(gallery):
duplicate = {} duplicate = {}
for photo in gallery.photos.all(): for photo in gallery.photos.all():
h0 = hashlib.sha256(photo.image.read()).digest() with photo.image.open("rb") as f:
h0 = hashlib.sha256(f.read()).digest()
if h0 not in non_duplicate: if h0 not in non_duplicate:
# Photo is not a duplicate # Photo is not a duplicate
non_duplicate[h0] = photo non_duplicate[h0] = photo