Skip to content

Commit

Permalink
fix find-filename-conflicts (#1430)
Browse files Browse the repository at this point in the history
* check all trees for conflicts

Make sure to merge all specified subtrees when searching for conflicts,
instead of separately in each one.

Signed-off-by: Taylor Yu <[email protected]>

* rename existing conflicted filenames

Signed-off-by: Taylor Yu <[email protected]>

---------

Signed-off-by: Taylor Yu <[email protected]>
  • Loading branch information
tlyu authored May 28, 2024
1 parent d895acf commit cd0c386
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions bin/find-filename-conflicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,24 @@
If no conflict is found, the script just prints its status message and exits
with zero."""

from itertools import chain
import os
import re
import sys

cpp_regex = re.compile('.*\.cpp')
suffixes = re.compile(r'\.c(?:pp)?$')


def find_duplicates(root):
def find_duplicates(roots):
"""Search for files with the same basename, but in different directories in
the tree under <root>. Prints a message for each conflict found, and
the trees under <roots>. Prints a message for each conflict found, and
returns a count of the number of non-unique basenames."""

# Search the specified tree for matching basenames:
basenames = {}
for dir_path, dirs, files in os.walk(root):
for file_name in files:
if cpp_regex.match(file_name):
if file_name not in basenames:
basenames[file_name] = []
basenames[file_name].append(dir_path)
for dir_path, dirs, files in chain.from_iterable(map(os.walk, roots)):
for file_name in filter(suffixes.search, files):
basenames.setdefault(file_name, []).append(dir_path)

conflict_count = 0
for file_name, dirs in basenames.items():
Expand All @@ -84,9 +82,7 @@ def find_duplicates(root):

def main(args):
print('Searching for conflicting filenames...')
exit_code = 0
for path in args:
exit_code += find_duplicates(path)
exit_code = find_duplicates(args)
if exit_code != 0:
sys.exit(exit_code)
print('No filename conflicts found.')
Expand Down

0 comments on commit cd0c386

Please sign in to comment.