From e047e53f6042802cb1de98c6da1a9fa1ad517334 Mon Sep 17 00:00:00 2001 From: Muller Tremolo <22122313+mullertremolo@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:46:07 -0700 Subject: [PATCH] Fix infinite loop setting directory date If the directory inside the `rootDir` was a symlink to a path outside the `rootDir`, it would get stuck in a loop adding "/" to the `output` set forever. This fixes that. --- ofscraper/actions/utils/paths/paths.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ofscraper/actions/utils/paths/paths.py b/ofscraper/actions/utils/paths/paths.py index 8d3aa2d35..ee37658ea 100644 --- a/ofscraper/actions/utils/paths/paths.py +++ b/ofscraper/actions/utils/paths/paths.py @@ -73,13 +73,20 @@ def setDirectoriesDate(log=None): output = set() rootDir = pathlib.Path(common_paths.get_save_location()) log.debug(f"Original DirSet {list(common_globals.dirSet)}") - log.debug(f"rooDir {rootDir}") + log.debug(f"rootDir {rootDir}") for ele in common_globals.dirSet: output.add(ele) while not os.path.samefile(ele, rootDir) and not os.path.samefile( ele.parent, rootDir ): + if ele.parent in output: + # We already added all subsequent paths in this tree + break + if not pathlib.PurePath(ele.parent).is_relative_to(rootDir): + # Don't descend if the parent path is outside rootDir such as + # when a symlink was used somewhere in the path + break common_globals.log.debug(f"Setting Dates ele:{ele} rootDir:{rootDir}") output.add(ele.parent) ele = ele.parent