Skip to content

Commit

Permalink
FileLister: ignore directories as a whole instead of its contents ind…
Browse files Browse the repository at this point in the history
…ividually
  • Loading branch information
firewave committed Feb 16, 2025
1 parent 96d8ff9 commit 283095d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cli/filelister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ static std::string addFiles2(std::list<FileWithDetails> &files,
#endif
if (path_is_directory) {
if (recursive) {
if (!ignored.match(new_path)) {
// append a slash if it is a directory since that is what we are doing for mIgnoredPaths directory entries.
// otherwise we would ignore all its contents individually instead as a whole.
if (!ignored.match(new_path + '/')) {
std::string err = addFiles2(files, new_path, extra, recursive, ignored, debug);
if (!err.empty()) {
return err;
Expand Down
27 changes: 26 additions & 1 deletion test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3140,4 +3140,29 @@ def test_debug_valueflow_xml(tmp_path): # #13606
assert 'floatvalue' in value_elem[1].attrib
assert value_elem[1].attrib['floatvalue'] == '1e-07'
assert 'floatvalue' in value_elem[2].attrib
assert value_elem[2].attrib['floatvalue'] == '1e-07'
assert value_elem[2].attrib['floatvalue'] == '1e-07'


def test_dir_ignore(tmp_path):
test_file = tmp_path / 'test.cpp'
with open(test_file, 'wt'):
pass

lib_dir = tmp_path / 'lib'
os.mkdir(lib_dir)
lib_test_file = lib_dir / 'test.cpp'
with open(lib_test_file, 'wt'):
pass

args = [
'-ilib',
'--debug-ignore',
str(tmp_path)
]
# make sure the whole directory is being ignored instead of each of its contents individually
out_lines = [
'ignored path: {}'.format(lib_dir),
'Checking {} ...'.format(test_file)
]

assert_cppcheck(args, ec_exp=0, err_exp=[], out_exp=out_lines)

0 comments on commit 283095d

Please sign in to comment.