A community-maintained Python framework for creating mathematical animations.
Fix TOCTOU Race Conditions when creating directories (#4587)
Sacha7efa45492f3e
diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.pyindex d4a7ae42f..812a6b084 100644--- a/manim/mobject/text/text_mobject.py+++ b/manim/mobject/text/text_mobject.py@@ -801,8 +801,7 @@ class Text(SVGMobject):line_spacing /= TEXT2SVG_ADJUSTMENT_FACTORdir_name = config.get_dir("text_dir")- if not dir_name.is_dir():- dir_name.mkdir(parents=True)+ dir_name.mkdir(parents=True, exist_ok=True)hash_name = self._text2hash(color)file_name = dir_name / (hash_name + ".svg")@@ -1349,8 +1348,7 @@ class MarkupText(SVGMobject):line_spacing /= TEXT2SVG_ADJUSTMENT_FACTORdir_name = config.get_dir("text_dir")- if not dir_name.is_dir():- dir_name.mkdir(parents=True)+ dir_name.mkdir(parents=True, exist_ok=True)hash_name = self._text2hash(color)file_name = dir_name / (hash_name + ".svg")diff --git a/manim/utils/file_ops.py b/manim/utils/file_ops.pyindex 5e239be54..1e00c186d 100644--- a/manim/utils/file_ops.py+++ b/manim/utils/file_ops.py@@ -153,15 +153,14 @@ def add_version_before_extension(file_name: Path) -> Path:def guarantee_existence(path: Path) -> Path:- if not path.exists():- path.mkdir(parents=True)+ path.mkdir(parents=True, exist_ok=True)return path.resolve(strict=True)def guarantee_empty_existence(path: Path) -> Path:if path.exists():shutil.rmtree(str(path))- path.mkdir(parents=True)+ path.mkdir(parents=True, exist_ok=True)return path.resolve(strict=True)diff --git a/manim/utils/tex_file_writing.py b/manim/utils/tex_file_writing.pyindex 4c61bf4fa..b7ad1bdc3 100644--- a/manim/utils/tex_file_writing.py+++ b/manim/utils/tex_file_writing.py@@ -103,8 +103,7 @@ def generate_tex_file(output = tex_template.get_texcode_for_expression(expression)tex_dir = config.get_dir("tex_dir")- if not tex_dir.exists():- tex_dir.mkdir()+ tex_dir.mkdir(parents=True, exist_ok=True)result = tex_dir / (tex_hash(output) + ".tex")if not result.exists():