Skip to content

Commit ce99cd4

Browse files
committed
Fix #10057: Failed to scan documents on the root directory
get_matching_files() incorrectly drops the first character of each path on scanning documents. It will help users to exclude paths via exclude_patterns setting. Note: Users need to configure `exclude_patterns` to put their document on the root directory. This does not help to avoid recursive symlinks (ex. /proc, /sys)
1 parent 87eda92 commit ce99cd4

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Bugs fixed
6767
at info-field-list
6868
* #9390: texinfo: Do not emit labels inside footnotes
6969
* #9979: Error level messages were displayed as warning messages
70+
* #10057: Failed to scan documents if the project is placed onto the root
71+
directory
7072

7173
Testing
7274
--------

sphinx/util/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ def get_matching_files(dirname: str,
7272
"""
7373
# dirname is a normalized absolute path.
7474
dirname = path.normpath(path.abspath(dirname))
75-
dirlen = len(dirname) + 1 # exclude final os.path.sep
7675

7776
for root, dirs, files in os.walk(dirname, followlinks=True):
78-
relativeroot = root[dirlen:]
77+
relativeroot = path.relpath(root, dirname)
78+
if relativeroot == ".":
79+
relativeroot = "" # suppress dirname for files on the target dir
7980

8081
qdirs = enumerate(path_stabilize(path.join(relativeroot, dn))
8182
for dn in dirs) # type: Iterable[Tuple[int, str]]

0 commit comments

Comments
 (0)