diff --git a/io/path.cpp b/io/path.cpp index e35f6c5..68f6548 100644 --- a/io/path.cpp +++ b/io/path.cpp @@ -4,23 +4,6 @@ #include #include #include -#if defined(PLATFORM_UNIX) -#include -#include -#include -#include -#include -#elif defined(PLATFORM_WINDOWS) -#ifdef UNICODE -#undef UNICODE -#endif -#ifdef _UNICODE -#undef _UNICODE -#endif -#include -#else -#error Platform not supported. -#endif using namespace std; @@ -84,39 +67,4 @@ void removeInvalidChars(std::string &fileName) } } -/*! - * \brief Returns the names of the directory entries in the specified \a path with the specified \a types. - * \deprecated This function has FIXMEs. Since it can be replaced by using fs abstraction lib it is a good candidate for being replaced. - */ -std::list directoryEntries(const char *path, DirectoryEntryType types) -{ -#ifdef PLATFORM_UNIX - list entries; - if (auto dir = opendir(path)) { - while (auto dirEntry = readdir(dir)) { - bool filter = false; - switch (dirEntry->d_type) { - case DT_REG: - filter = (types & DirectoryEntryType::File) != DirectoryEntryType::None; - break; - case DT_DIR: - filter = (types & DirectoryEntryType::Directory) != DirectoryEntryType::None; - break; - case DT_LNK: - filter = (types & DirectoryEntryType::Symlink) != DirectoryEntryType::None; - break; - default: - filter = (types & DirectoryEntryType::All) != DirectoryEntryType::None; - } - if (filter) { - entries.emplace_back(dirEntry->d_name); - } - } - closedir(dir); - } - return entries; -#else - return list(); // TODO -#endif -} } // namespace IoUtilities diff --git a/io/path.h b/io/path.h index 332086f..7a2cdef 100644 --- a/io/path.h +++ b/io/path.h @@ -20,30 +20,9 @@ namespace IoUtilities { -/*! - * \brief The DirectoryEntryType enum specifies the type of a directory entry (file, directory or symlink). - */ -enum class DirectoryEntryType : unsigned char { None = 0, File = 1, Directory = 2, Symlink = 4, All = 0xFF }; - -constexpr DirectoryEntryType operator|(DirectoryEntryType lhs, DirectoryEntryType rhs) -{ - return static_cast(static_cast(lhs) | static_cast(rhs)); -} - -inline DirectoryEntryType &operator|=(DirectoryEntryType &lhs, DirectoryEntryType rhs) -{ - return (lhs = static_cast(static_cast(lhs) | static_cast(rhs))); -} - -constexpr DirectoryEntryType operator&(DirectoryEntryType lhs, DirectoryEntryType rhs) -{ - return static_cast(static_cast(lhs) & static_cast(rhs)); -} - CPP_UTILITIES_EXPORT std::string fileName(const std::string &path); CPP_UTILITIES_EXPORT std::string directory(const std::string &path); CPP_UTILITIES_EXPORT void removeInvalidChars(std::string &fileName); -CPP_UTILITIES_EXPORT std::list directoryEntries(const char *path, DirectoryEntryType types = DirectoryEntryType::All); } // namespace IoUtilities #endif // IOUTILITIES_PATHHELPER_H diff --git a/tests/iotests.cpp b/tests/iotests.cpp index f1cf3db..f9f9933 100644 --- a/tests/iotests.cpp +++ b/tests/iotests.cpp @@ -272,22 +272,6 @@ void IoTests::testPathUtilities() string invalidPath("lib/c++uti*lities.so?"); removeInvalidChars(invalidPath); CPPUNIT_ASSERT(invalidPath == "libc++utilities.so"); -#ifdef PLATFORM_UNIX - const string iniFilePath = TestUtilities::testFilePath("test.ini"); - const string testFilesDir = iniFilePath.substr(0, iniFilePath.size() - 9); - auto testFilesDirEntries = directoryEntries(testFilesDir.c_str(), DirectoryEntryType::All); - CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), "test.ini") != testFilesDirEntries.cend()); - CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), ".") != testFilesDirEntries.cend()); - CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), "..") != testFilesDirEntries.cend()); - testFilesDirEntries = directoryEntries(testFilesDir.c_str(), DirectoryEntryType::Directory); - CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), "test.ini") == testFilesDirEntries.cend()); - CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), ".") != testFilesDirEntries.cend()); - CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), "..") != testFilesDirEntries.cend()); - testFilesDirEntries = directoryEntries(testFilesDir.c_str(), DirectoryEntryType::File); - CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), "test.ini") != testFilesDirEntries.cend()); - CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), ".") == testFilesDirEntries.cend()); - CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), "..") == testFilesDirEntries.cend()); -#endif } /*! diff --git a/tests/testutils.cpp b/tests/testutils.cpp index e81adc5..051ae49 100644 --- a/tests/testutils.cpp +++ b/tests/testutils.cpp @@ -552,25 +552,17 @@ string TestApplication::readTestfilePathFromSrcRef() cerr << Phrases::Warning << "The file \"srcdirref\" is empty." << Phrases::EndFlush; return string(); } + srcDirContent += "/testfiles/"; // check whether the referenced source directory contains a "testfiles" directory -#ifdef PLATFORM_UNIX // directoryEntries() is not implemented under Windows so we can only to the check under UNIX - bool hasTestfilesDir = false; - for (const string &dir : directoryEntries(srcDirContent.data(), DirectoryEntryType::Directory)) { - if (dir == "testfiles") { - hasTestfilesDir = true; - break; - } - } - if (!hasTestfilesDir) { + if (!dirExists(srcDirContent)) { cerr << Phrases::Warning << "The source directory referenced by the file \"srcdirref\" does not contain a \"testfiles\" directory or does not exist." << Phrases::End << "Referenced source directory: " << srcDirContent << endl; return string(); } -#endif // PLATFORM_UNIX + return srcDirContent; - return srcDirContent += "/testfiles/"; } catch (const std::ios_base::failure &) { cerr << Phrases::Warning << "The file \"srcdirref\" can not be opened. It likely just doesn't exist in the working directory." << Phrases::EndFlush;