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 19, 2025
1 parent 5bf9848 commit d39f00d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
8 changes: 6 additions & 2 deletions cli/filelister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ static std::string addFiles2(std::list<FileWithDetails>&files, const std::string
} else {
// Directory
if (recursive) {
if (!ignored.match(fname)) {
// 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(fname + '/')) {
std::list<FileWithDetails> filesSorted;

std::string err = addFiles2(filesSorted, fname, extra, recursive, ignored);
Expand Down Expand Up @@ -240,7 +242,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, cwd=str(tmp_path))
4 changes: 2 additions & 2 deletions test/cli/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ def cppcheck(*args, **kwargs):
return return_code, stdout, stderr


def assert_cppcheck(args, ec_exp=None, out_exp=None, err_exp=None, env=None):
exitcode, stdout, stderr = cppcheck(args, env)
def assert_cppcheck(args, ec_exp=None, out_exp=None, err_exp=None, env=None, cwd=None):
exitcode, stdout, stderr = cppcheck(args, env=env, cwd=cwd)
if ec_exp is not None:
assert exitcode == ec_exp, stdout
if out_exp is not None:
Expand Down

0 comments on commit d39f00d

Please sign in to comment.