From e80b9d0e47fd2078630a6a77836ecc29988ab6e7 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Mon, 25 Nov 2024 09:31:15 -0700 Subject: [PATCH] Less collision-prone file names for downloads --- manimlib/utils/file_ops.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/manimlib/utils/file_ops.py b/manimlib/utils/file_ops.py index e1419e91..0e436b68 100644 --- a/manimlib/utils/file_ops.py +++ b/manimlib/utils/file_ops.py @@ -1,6 +1,8 @@ from __future__ import annotations import os +from pathlib import Path +import hashlib import numpy as np import validators @@ -35,9 +37,11 @@ def find_file( if validators.url(file_name): import urllib.request from manimlib.utils.directories import get_downloads_dir - stem, name = os.path.split(file_name) + suffix = Path(file_name).suffix + file_hash = hashlib.sha256(file_name.encode('utf-8')).hexdigest()[:32] folder = get_downloads_dir() - path = os.path.join(folder, name) + + path = Path(folder, file_hash).with_suffix(suffix) urllib.request.urlretrieve(file_name, path) return path