diff options
| author | Andrew Stitcher <astitcher@apache.org> | 2012-12-20 00:35:54 +0000 |
|---|---|---|
| committer | Andrew Stitcher <astitcher@apache.org> | 2012-12-20 00:35:54 +0000 |
| commit | 4a0452844f85edc5b0be0edcf877e6b5d33302ed (patch) | |
| tree | a1e5f62f65fb9cf767c393bda9020f6e1b63a187 /cpp/src/qpid/Modules.cpp | |
| parent | 24e9d70d7bcefae3a68d3cc4b19e684440776a05 (diff) | |
| download | qpid-python-4a0452844f85edc5b0be0edcf877e6b5d33302ed.tar.gz | |
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
Diffstat (limited to 'cpp/src/qpid/Modules.cpp')
| -rw-r--r-- | cpp/src/qpid/Modules.cpp | 49 |
1 files changed, 23 insertions, 26 deletions
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 <boost/filesystem/operations.hpp> -#include <boost/filesystem/path.hpp> - -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 |
