From 081cc4bf0570f872c967491243a041be804458b1 Mon Sep 17 00:00:00 2001 From: nhumrich Date: Tue, 5 May 2015 10:58:19 -0700 Subject: [PATCH] Fix for non recursive symlinks Currently RecursionError is thrown even on sideways symlinks. This fix checks for recursive links versus sideways links. --- pathspec/util.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pathspec/util.py b/pathspec/util.py index 3d14249..e8fe448 100644 --- a/pathspec/util.py +++ b/pathspec/util.py @@ -42,11 +42,18 @@ def iter_tree(root): for parent, _dirs, files in os.walk(root, followlinks=True): # Get parent path relative to root path. parent = os.path.relpath(parent, root) - + # Check for recursion. real = os.path.realpath(parent) if real in memo: - raise RecursionError(real_path=real, first_path=memo[real], second_path=parent) + abspath = os.path.abspath(parent) + if real != abspath and real in abspath: + # if real is a parent of current parent + raise RecursionError(real_path=real, first_path=memo[real], second_path=parent) + else: + # not recursion, just a sideways link + continue + memo[real] = parent # Yield files.