Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive '**' matches non-existent directories. #79382

Closed
daniel mannequin opened this issue Nov 9, 2018 · 4 comments
Closed

Recursive '**' matches non-existent directories. #79382

daniel mannequin opened this issue Nov 9, 2018 · 4 comments
Assignees
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@daniel
Copy link
Mannequin

daniel mannequin commented Nov 9, 2018

BPO 35201
Nosy @serhiy-storchaka

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2018-11-09.16:54:51.725>
labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
title = "Recursive '**' matches non-existent directories."
updated_at = <Date 2021-12-01.22:35:42.687>
user = 'https://bugs.python.org/daniel'

bugs.python.org fields:

activity = <Date 2021-12-01.22:35:42.687>
actor = 'iritkatriel'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2018-11-09.16:54:51.725>
creator = 'daniel'
dependencies = []
files = []
hgrepos = []
issue_num = 35201
keywords = []
message_count = 3.0
messages = ['329537', '329539', '329703']
nosy_count = 2.0
nosy_names = ['serhiy.storchaka', 'daniel']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue35201'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

Linked PRs

@daniel
Copy link
Mannequin Author

daniel mannequin commented Nov 9, 2018

In the following case, when there is no file or directory 'a', glob will still return it:

>>> glob.glob("a/**", recursive=True)
[ 'a/' ]

Note that this is inconsistent with the '*' pattern:

>>> glob.glob("a/*", recursive=True)
[]

@daniel daniel mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 9, 2018
@serhiy-storchaka
Copy link
Member

This is expected behavior, and it matches the behavior of Bash.

$ mkdir empty
$ shopt -s globstar failglob
$ echo empty/*
bash: no match: empty/*
$ echo empty/**
empty/

"**" matches zero or more path components. In this case case it matches zero.

@Windsooon Windsooon mannequin added 3.7 (EOL) end of life 3.8 only security fixes labels Nov 10, 2018
@daniel
Copy link
Mannequin Author

daniel mannequin commented Nov 12, 2018

In the Bash example, you created the directory empty/. This bug is specifically when the directory in question does not exist.

@iritkatriel iritkatriel added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes and removed 3.7 (EOL) end of life 3.8 only security fixes invalid labels Dec 1, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@LuckyDams
Copy link

Similar issue with existing file returned as directory:

$ touch file
$ shopt -s globstar failglob
$ echo file/*
-bash: no match: file/*
$ echo file/**
-bash: no match: file/**
>>> glob.glob('file/*', recursive=True)
[]

>>> glob.glob('file/**', recursive=True)
['file/']

@serhiy-storchaka serhiy-storchaka added the 3.12 bugs and security fixes label May 25, 2022
@serhiy-storchaka serhiy-storchaka self-assigned this May 25, 2022
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Feb 7, 2024
Trailing "**" no longer allows to match files and non-existing paths in
recursive glob().
serhiy-storchaka added a commit that referenced this issue Feb 11, 2024
Trailing "**" no longer allows to match files and non-existing paths in
recursive glob().
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 11, 2024
)

Trailing "**" no longer allows to match files and non-existing paths in
recursive glob().
(cherry picked from commit aeffc7f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 11, 2024
)

Trailing "**" no longer allows to match files and non-existing paths in
recursive glob().
(cherry picked from commit aeffc7f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Feb 11, 2024
…H-115290)

Trailing "**" no longer allows to match files and non-existing paths in
recursive glob().
(cherry picked from commit aeffc7f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Feb 11, 2024
…H-115291)

Trailing "**" no longer allows to match files and non-existing paths in
recursive glob().
(cherry picked from commit aeffc7f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this issue Feb 14, 2024
)

Trailing "**" no longer allows to match files and non-existing paths in
recursive glob().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
Development

No branches or pull requests

3 participants