From fd5babb5dc677d5f6e089dcdb9ef091b12278fee Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Tue, 23 Apr 2019 00:03:19 -0700 Subject: [PATCH 1/2] doc: recursive glob ** follows symlinks to directories The existing note does already warn that "Using the ** pattern in large directory trees may consume an inordinate amount of time", however following symbolic links to directories brings that to entirely new levels; learned the hard way. I initially assumed this was a bug, tentatively fixed with a simple: - if not dironly or entry.is_dir(): + if not dironly or entry.is_dir(follow_symlinks=False): ... in glob.py#_iterdir(dirname, dironly): Later I found https://bugs.python.org/issue13968 in the git log and saw this is working as intended with even a symlink loop test. --- Doc/library/glob.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/glob.rst b/Doc/library/glob.rst index 2a5f0ddc4ef319..822aaec83c5eb3 100644 --- a/Doc/library/glob.rst +++ b/Doc/library/glob.rst @@ -49,8 +49,9 @@ For example, ``'[?]'`` matches the character ``'?'``. single: **; in glob-style wildcards If *recursive* is true, the pattern "``**``" will match any files and zero or - more directories and subdirectories. If the pattern is followed by an - ``os.sep``, only directories and subdirectories match. + more directories, subdirectories and symbolic links to directories. If the + pattern is followed by an ``os.sep`` or ``os.altsep`` then files will not + match. .. note:: Using the "``**``" pattern in large directory trees may consume From fd5eda22341b91604f027ccbb8e447486c1bd8e0 Mon Sep 17 00:00:00 2001 From: Marc Date: Mon, 26 Aug 2019 15:44:20 -0700 Subject: [PATCH 2/2] Update Doc/library/glob.rst - ``os.sep`` or ``os.altsep`` + :data:`os.sep` or :data:`os.altsep` Co-Authored-By: Kyle Stanley --- Doc/library/glob.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/glob.rst b/Doc/library/glob.rst index 822aaec83c5eb3..9f2df6097570ad 100644 --- a/Doc/library/glob.rst +++ b/Doc/library/glob.rst @@ -50,7 +50,7 @@ For example, ``'[?]'`` matches the character ``'?'``. If *recursive* is true, the pattern "``**``" will match any files and zero or more directories, subdirectories and symbolic links to directories. If the - pattern is followed by an ``os.sep`` or ``os.altsep`` then files will not + pattern is followed by an :data:`os.sep` or :data:`os.altsep` then files will not match. .. note::