Fixed #11395 (Cant exclude file)

This commit is contained in:
Daniel Marjamäki 2022-11-24 13:45:57 +01:00
parent a5c16af16d
commit c26a8fb4ce
2 changed files with 13 additions and 0 deletions

View File

@ -182,6 +182,9 @@ static std::string addFiles2(std::map<std::string, std::size_t> &files,
const PathMatch& ignored const PathMatch& ignored
) )
{ {
if (ignored.match(path))
return "";
struct stat file_stat; struct stat file_stat;
if (stat(path.c_str(), &file_stat) != -1) { if (stat(path.c_str(), &file_stat) != -1) {
if ((file_stat.st_mode & S_IFMT) == S_IFDIR) { if ((file_stat.st_mode & S_IFMT) == S_IFDIR) {

View File

@ -43,6 +43,7 @@ private:
TEST_CASE(isDirectory); TEST_CASE(isDirectory);
TEST_CASE(recursiveAddFiles); TEST_CASE(recursiveAddFiles);
TEST_CASE(excludeFile);
TEST_CASE(fileExists); TEST_CASE(fileExists);
} }
@ -78,6 +79,15 @@ private:
ASSERT(files.find("lib/tokenize.h") == files.end()); ASSERT(files.find("lib/tokenize.h") == files.end());
} }
void excludeFile() const {
std::map<std::string, std::size_t> files;
std::vector<std::string> ignored{"lib/token.cpp"};
PathMatch matcher(ignored);
std::string err = FileLister::recursiveAddFiles(files, "lib/token.cpp", matcher);
ASSERT(err.empty());
ASSERT(files.empty());
}
void fileExists() const { void fileExists() const {
ASSERT_EQUALS(false, FileLister::fileExists("lib")); ASSERT_EQUALS(false, FileLister::fileExists("lib"));
ASSERT_EQUALS(true, FileLister::fileExists("readme.txt")); ASSERT_EQUALS(true, FileLister::fileExists("readme.txt"));