From b5f880d5c69b72dcebd41cd0e5de6a82cdd5bbb2 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Mon, 27 Jun 2022 06:22:29 +0400 Subject: cmFindPackageCommand: Deduplicate code to exclude `.` and `..` dir entries --- Source/cmFindPackageCommand.cxx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 18a12c4..8fcfa22 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -2152,6 +2152,7 @@ public: protected: bool Consider(std::string const& fullPath, cmFileList& listing); + static bool IsIgnoredEntry(const char* fname); private: bool Search(cmFileList&); @@ -2236,6 +2237,12 @@ bool cmFileListGeneratorBase::Consider(std::string const& fullPath, return listing.Visit(fullPath + '/'); } +bool cmFileListGeneratorBase::IsIgnoredEntry(const char* const fname) +{ + assert(fname != nullptr); + return strcmp(fname, ".") == 0 || strcmp(fname, "..") == 0; +} + class cmFileListGeneratorFixed : public cmFileListGeneratorBase { public: @@ -2330,7 +2337,7 @@ private: d.Load(parent); for (unsigned long i = 0; i < d.GetNumberOfFiles(); ++i) { const char* fname = d.GetFile(i); - if (strcmp(fname, ".") == 0 || strcmp(fname, "..") == 0) { + if (this->IsIgnoredEntry(fname)) { continue; } for (std::string const& n : this->Names) { @@ -2386,7 +2393,7 @@ private: d.Load(parent); for (unsigned long i = 0; i < d.GetNumberOfFiles(); ++i) { const char* fname = d.GetFile(i); - if (strcmp(fname, ".") == 0 || strcmp(fname, "..") == 0) { + if (this->IsIgnoredEntry(fname)) { continue; } for (std::string name : this->Names) { @@ -2433,7 +2440,7 @@ private: d.Load(parent); for (unsigned long i = 0; i < d.GetNumberOfFiles(); ++i) { const char* fname = d.GetFile(i); - if (strcmp(fname, ".") == 0 || strcmp(fname, "..") == 0) { + if (this->IsIgnoredEntry(fname)) { continue; } if (cmsysString_strcasecmp(fname, this->String.c_str()) == 0) { -- cgit v0.12