From 4a0452844f85edc5b0be0edcf877e6b5d33302ed Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Thu, 20 Dec 2012 00:35:54 +0000 Subject: QPID-4095: Move the directory iteration into FileSysDir: - For Posix implement with direct calls - For windows implement with v2/v3 boost::filesystem to be replaced later git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1424247 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/Modules.cpp | 49 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) (limited to 'cpp/src/qpid/Modules.cpp') diff --git a/cpp/src/qpid/Modules.cpp b/cpp/src/qpid/Modules.cpp index 727e05d212..049ededaa7 100644 --- a/cpp/src/qpid/Modules.cpp +++ b/cpp/src/qpid/Modules.cpp @@ -24,11 +24,7 @@ #include "qpid/Exception.h" #include "qpid/log/Statement.h" #include "qpid/sys/Shlib.h" - -#include -#include - -namespace fs=boost::filesystem; +#include "qpid/sys/FileSysDir.h" namespace { @@ -43,7 +39,7 @@ inline std::string& suffix() { } bool isShlibName(const std::string& name) { - return name.find (suffix()) == name.length() - suffix().length(); + return name.substr(name.size()-suffix().size()) == suffix(); } } @@ -59,39 +55,40 @@ ModuleOptions::ModuleOptions(const std::string& defaultModuleDir) ("no-module-dir", optValue(noLoad), "Don't load modules from module directory"); } -void tryShlib(const char* libname_, bool noThrow) { - std::string libname(libname_); - if (!isShlibName(libname)) libname += suffix(); +void tryShlib(const std::string& libname) { + sys::Shlib shlib( isShlibName(libname) ? libname : (libname + suffix())); +} + +namespace { + +void tryOnlyShlib(const std::string& libname) throw() { try { - sys::Shlib shlib(libname); + if (isShlibName(libname)) sys::Shlib shlib( libname ); } catch (const std::exception& /*e*/) { - if (!noThrow) - throw; } } +} + void loadModuleDir (std::string dirname, bool isDefault) { - fs::path dirPath (dirname, fs::native); - if (!fs::exists (dirPath)) + sys::FileSysDir dirPath (dirname); + + bool exists; + try { - if (isDefault) - return; - throw Exception ("Directory not found: " + dirname); + exists = dirPath.exists(); + } catch (Exception& e) { + throw Exception ("Invalid value for module-dir: " + e.getMessage()); } - if (!fs::is_directory(dirPath)) - { - throw Exception ("Invalid value for module-dir: " + dirname + " is not a directory"); + if (!exists) { + if (isDefault) return; + throw Exception ("Directory not found: " + dirname); } - fs::directory_iterator endItr; - for (fs::directory_iterator itr (dirPath); itr != endItr; ++itr) - { - if (!fs::is_directory(*itr) && isShlibName(itr->string())) - tryShlib (itr->string().data(), true); - } + dirPath.forEachFile(&tryOnlyShlib); } } // namespace qpid -- cgit v1.2.1