diff --git a/Framework/Kernel/inc/MantidKernel/LibraryManager.h b/Framework/Kernel/inc/MantidKernel/LibraryManager.h index c85000ef2f55..7ed40f95a41a 100644 --- a/Framework/Kernel/inc/MantidKernel/LibraryManager.h +++ b/Framework/Kernel/inc/MantidKernel/LibraryManager.h @@ -9,6 +9,7 @@ //---------------------------------------------------------------------- // Includes //---------------------------------------------------------------------- +#include #include #include #include @@ -17,11 +18,6 @@ #include "MantidKernel/LibraryWrapper.h" #include "MantidKernel/SingletonHolder.h" -namespace Poco { -class File; -class Path; -} // namespace Poco - namespace Mantid { namespace Kernel { /** @@ -48,7 +44,7 @@ class MANTID_KERNEL_DLL LibraryManagerImpl { /// Load libraries from the given Poco::File path /// Private so Poco::File doesn't leak to the public interface - int openLibraries(const Poco::File &libpath, LoadLibraries loadingBehaviour, + int openLibraries(const std::filesystem::path &libpath, LoadLibraries loadingBehaviour, const std::vector &excludes); /// Check if the library should be loaded bool shouldBeLoaded(const std::string &filename, const std::vector &excludes) const; @@ -57,7 +53,7 @@ class MANTID_KERNEL_DLL LibraryManagerImpl { /// Returns true if the library has been requested to be excluded bool isExcluded(const std::string &filename, const std::vector &excludes) const; /// Load a given library - int openLibrary(const Poco::File &filepath, const std::string &cacheKey); + int openLibrary(const std::filesystem::path &filepath, const std::string &cacheKey); /// Storage for the LibraryWrappers. std::unordered_map m_openedLibs; diff --git a/Framework/Kernel/src/DllOpen.cpp b/Framework/Kernel/src/DllOpen.cpp index f229719f6360..cda55fc6dddb 100644 --- a/Framework/Kernel/src/DllOpen.cpp +++ b/Framework/Kernel/src/DllOpen.cpp @@ -13,8 +13,6 @@ #include #endif -#include - #include namespace Mantid::Kernel { @@ -36,7 +34,7 @@ const std::string LIB_SUFFIX = ".dll"; * @param filename The file name of the library * @return True if it matches the expected format, false otherwise */ -bool DllOpen::isValidFilename(const std::string &filename) { return boost::ends_with(filename, LIB_SUFFIX); } +bool DllOpen::isValidFilename(const std::string &filename) { return filename.ends_with(LIB_SUFFIX); } /* Opens the Windows .dll file. * @param filePath :: Filepath of the library. @@ -86,7 +84,7 @@ const std::string LIB_SUFFIX = ".dylib"; * @return True if it matches the expected format, false otherwise */ bool DllOpen::isValidFilename(const std::string &filename) { - return boost::starts_with(filename, LIB_PREFIX) && boost::ends_with(filename, LIB_SUFFIX); + return filename.starts_with(LIB_PREFIX) && filename.ends_with(LIB_SUFFIX); } /* Opens the Linux .so file diff --git a/Framework/Kernel/src/LibraryManager.cpp b/Framework/Kernel/src/LibraryManager.cpp index 62d550778723..d757e4827b22 100644 --- a/Framework/Kernel/src/LibraryManager.cpp +++ b/Framework/Kernel/src/LibraryManager.cpp @@ -10,10 +10,7 @@ #include "MantidKernel/LibraryWrapper.h" #include "MantidKernel/Logger.h" -#include -#include -#include -#include +#include namespace Mantid::Kernel { namespace { @@ -37,7 +34,7 @@ int LibraryManagerImpl::openLibraries(const std::string &filepath, LoadLibraries const std::vector &excludes) { g_log.debug("Opening all libraries in " + filepath + "\n"); try { - return openLibraries(Poco::File(filepath), loadingBehaviour, excludes); + return openLibraries(std::filesystem::path(filepath), loadingBehaviour, excludes); } catch (std::exception &exc) { g_log.debug() << "Error occurred while opening libraries: " << exc.what() << "\n"; return 0; @@ -52,7 +49,7 @@ int LibraryManagerImpl::openLibraries(const std::string &filepath, LoadLibraries //------------------------------------------------------------------------- /** * Opens suitable DLLs on a given path. - * @param libpath A Poco::File object pointing to a directory where the + * @param libpath An std::filesystem::path object pointing to a directory where the * libraries are. * @param loadingBehaviour Control how libraries are searched for * @param excludes If not empty then each string is considered as a substring @@ -60,26 +57,26 @@ int LibraryManagerImpl::openLibraries(const std::string &filepath, LoadLibraries * the library is not opened. * @return The number of libraries opened. */ -int LibraryManagerImpl::openLibraries(const Poco::File &libpath, LibraryManagerImpl::LoadLibraries loadingBehaviour, +int LibraryManagerImpl::openLibraries(const std::filesystem::path &libpath, + LibraryManagerImpl::LoadLibraries loadingBehaviour, const std::vector &excludes) { int libCount(0); - if (libpath.exists() && libpath.isDirectory()) { + if (std::filesystem::exists(libpath) && std::filesystem::is_directory(libpath)) { // Iterate over the available files - Poco::DirectoryIterator end_itr; - for (Poco::DirectoryIterator itr(libpath); itr != end_itr; ++itr) { - const Poco::File &item = *itr; - if (item.isFile()) { - if (shouldBeLoaded(itr.path().getFileName(), excludes)) - libCount += openLibrary(itr.path(), itr.path().getFileName()); + for (const auto &file : std::filesystem::directory_iterator(libpath)) { + const auto &path = file.path(); + if (std::filesystem::is_regular_file(path)) { + if (shouldBeLoaded(path.filename().string(), excludes)) + libCount += openLibrary(path.string(), path.filename().string()); else continue; } else if (loadingBehaviour == LoadLibraries::Recursive) { // it must be a directory - libCount += openLibraries(item, LoadLibraries::Recursive, excludes); + libCount += openLibraries(path, LoadLibraries::Recursive, excludes); } } } else { - g_log.error("In OpenAllLibraries: " + libpath.path() + " must be a directory."); + g_log.error("In OpenAllLibraries: " + libpath.string() + " must be a directory."); } return libCount; } @@ -122,18 +119,18 @@ bool LibraryManagerImpl::isExcluded(const std::string &filename, const std::vect /** * Load a library - * @param filepath :: A Poco::File The full path to a library as a string + * @param filepath :: An std::filesystem::path The full path to a library as a string * @param cacheKey :: An identifier for the cache if loading is successful * @return 1 if the file loaded successfully, 0 otherwise */ -int LibraryManagerImpl::openLibrary(const Poco::File &filepath, const std::string &cacheKey) { +int LibraryManagerImpl::openLibrary(const std::filesystem::path &filepath, const std::string &cacheKey) { // Try to open the library. The wrapper will unload the library when it // is deleted LibraryWrapper dlwrap; - if (dlwrap.openLibrary(filepath.path())) { + if (dlwrap.openLibrary(filepath.string())) { // Successfully opened, so add to map if (g_log.is(Poco::Message::PRIO_DEBUG)) { - g_log.debug("Opened library: " + filepath.path() + ".\n"); + g_log.debug("Opened library: " + filepath.string() + ".\n"); } m_openedLibs.emplace(cacheKey, std::move(dlwrap)); return 1;