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 | 8381984729f7e9858fb5a56f7ca7f4af8cf31b47 (patch) | |
| tree | 963ce71901c5fc4b1500ef8b284b9630b5c248fe /qpid/cpp/src | |
| parent | 0118e13f2f2a18d65b93a38051336e18c53f3220 (diff) | |
| download | qpid-python-8381984729f7e9858fb5a56f7ca7f4af8cf31b47.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@1424247 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src')
| -rw-r--r-- | qpid/cpp/src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | qpid/cpp/src/Makefile.am | 1 | ||||
| -rw-r--r-- | qpid/cpp/src/qpid/Modules.cpp | 49 | ||||
| -rw-r--r-- | qpid/cpp/src/qpid/Modules.h | 2 | ||||
| -rw-r--r-- | qpid/cpp/src/qpid/client/LoadPlugins.cpp | 2 | ||||
| -rwxr-xr-x | qpid/cpp/src/qpid/sys/FileSysDir.h | 9 | ||||
| -rwxr-xr-x | qpid/cpp/src/qpid/sys/posix/FileSysDir.cpp | 26 | ||||
| -rw-r--r-- | qpid/cpp/src/qpid/sys/windows/FileSysDir.cpp | 14 | ||||
| -rw-r--r-- | qpid/cpp/src/qpidd.cpp | 2 |
9 files changed, 75 insertions, 32 deletions
diff --git a/qpid/cpp/src/CMakeLists.txt b/qpid/cpp/src/CMakeLists.txt index 343ca88dd7..c5bf627fc6 100644 --- a/qpid/cpp/src/CMakeLists.txt +++ b/qpid/cpp/src/CMakeLists.txt @@ -1482,8 +1482,6 @@ install_pdb (qmfconsole ${QPID_COMPONENT_QMF}) # file whereas older builds only have config.h on autoconf-generated builds. add_definitions(-DHAVE_CONFIG_H) -add_definitions(-DBOOST_FILESYSTEM_VERSION=2) - # Now create the config file from all the info learned above. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) diff --git a/qpid/cpp/src/Makefile.am b/qpid/cpp/src/Makefile.am index ad2a438c3b..690616853f 100644 --- a/qpid/cpp/src/Makefile.am +++ b/qpid/cpp/src/Makefile.am @@ -138,7 +138,6 @@ qpidtest_SCRIPTS = tmoduleexecdir = $(libdir)/qpid/tests tmoduleexec_LTLIBRARIES= -AM_CXXFLAGS += -DBOOST_FILESYSTEM_VERSION=2 BROKER_CXXFLAGS = -D_IN_QPID_BROKER ## Automake macros to build libraries and executables. diff --git a/qpid/cpp/src/qpid/Modules.cpp b/qpid/cpp/src/qpid/Modules.cpp index 727e05d212..049ededaa7 100644 --- a/qpid/cpp/src/qpid/Modules.cpp +++ b/qpid/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 diff --git a/qpid/cpp/src/qpid/Modules.h b/qpid/cpp/src/qpid/Modules.h index 159dd156c1..9fb91d60eb 100644 --- a/qpid/cpp/src/qpid/Modules.h +++ b/qpid/cpp/src/qpid/Modules.h @@ -36,7 +36,7 @@ struct ModuleOptions : public qpid::Options { QPID_COMMON_EXTERN ModuleOptions(const std::string& defaultModuleDir); }; -QPID_COMMON_EXTERN void tryShlib(const char* libname, bool noThrow); +QPID_COMMON_EXTERN void tryShlib(const std::string& libname); QPID_COMMON_EXTERN void loadModuleDir (std::string dirname, bool isDefault); } // namespace qpid diff --git a/qpid/cpp/src/qpid/client/LoadPlugins.cpp b/qpid/cpp/src/qpid/client/LoadPlugins.cpp index d76e1d458e..c5d8924014 100644 --- a/qpid/cpp/src/qpid/client/LoadPlugins.cpp +++ b/qpid/cpp/src/qpid/client/LoadPlugins.cpp @@ -48,7 +48,7 @@ struct LoadtimeInitialise { for (vector<string>::iterator iter = moduleOptions.load.begin(); iter != moduleOptions.load.end(); iter++) - qpid::tryShlib (iter->data(), false); + qpid::tryShlib (*iter); if (!moduleOptions.noLoad) { bool isDefault = defaultPath == moduleOptions.loadDir; diff --git a/qpid/cpp/src/qpid/sys/FileSysDir.h b/qpid/cpp/src/qpid/sys/FileSysDir.h index ffe7823f0a..7432fe39c9 100755 --- a/qpid/cpp/src/qpid/sys/FileSysDir.h +++ b/qpid/cpp/src/qpid/sys/FileSysDir.h @@ -54,6 +54,15 @@ class FileSysDir void mkdir(void); + typedef void Callback(const std::string&); + + /** + * Call the Callback function for every regular file in the directory + * + * @param cb Callback function that receives the full path to the file + */ + void forEachFile(Callback cb) const; + std::string getPath () { return dirPath; } }; diff --git a/qpid/cpp/src/qpid/sys/posix/FileSysDir.cpp b/qpid/cpp/src/qpid/sys/posix/FileSysDir.cpp index 22dc487e74..cec580164d 100755 --- a/qpid/cpp/src/qpid/sys/posix/FileSysDir.cpp +++ b/qpid/cpp/src/qpid/sys/posix/FileSysDir.cpp @@ -18,6 +18,7 @@ #include "qpid/sys/FileSysDir.h" #include "qpid/sys/StrError.h" +#include "qpid/log/Statement.h" #include "qpid/Exception.h" #include <sys/types.h> @@ -25,6 +26,8 @@ #include <fcntl.h> #include <cerrno> #include <unistd.h> +#include <dirent.h> +#include <stdlib.h> namespace qpid { namespace sys { @@ -51,4 +54,27 @@ void FileSysDir::mkdir(void) throw Exception ("Can't create directory: " + dirPath); } +void FileSysDir::forEachFile(Callback cb) const { + + ::dirent** namelist; + + int n = scandir(dirPath.c_str(), &namelist, 0, alphasort); + if (n == -1) throw Exception (strError(errno) + ": Can't scan directory: " + dirPath); + + for (int i = 0; i<n; ++i) { + std::string fullpath = dirPath + "/" + namelist[i]->d_name; + // Filter out non files/stat problems etc. + struct ::stat s; + // Can't throw here without leaking memory, so just do nothing with + // entries for which stat() fails. + if (!::stat(fullpath.c_str(), &s)) { + if (S_ISREG(s.st_mode)) { + cb(fullpath); + } + } + ::free(namelist[i]); + } + ::free(namelist); +} + }} // namespace qpid::sys diff --git a/qpid/cpp/src/qpid/sys/windows/FileSysDir.cpp b/qpid/cpp/src/qpid/sys/windows/FileSysDir.cpp index 88f1637d48..88a2e62acc 100644 --- a/qpid/cpp/src/qpid/sys/windows/FileSysDir.cpp +++ b/qpid/cpp/src/qpid/sys/windows/FileSysDir.cpp @@ -25,6 +25,11 @@ #include <direct.h> #include <errno.h> +#include <boost/filesystem/operations.hpp> +#include <boost/filesystem/path.hpp> + +namespace fs=boost::filesystem; + namespace qpid { namespace sys { @@ -50,4 +55,13 @@ void FileSysDir::mkdir(void) throw Exception ("Can't create directory: " + dirPath); } +void FileSysDir::forEachFile(Callback cb) const { + fs::directory_iterator dirP(dirPath); + fs::directory_iterator endItr; + for (fs::directory_iterator itr (dirP); itr != endItr; ++itr) + { + cb(itr->path().string()); + } +} + }} // namespace qpid::sys diff --git a/qpid/cpp/src/qpidd.cpp b/qpid/cpp/src/qpidd.cpp index 920009580c..8e0c52f770 100644 --- a/qpid/cpp/src/qpidd.cpp +++ b/qpid/cpp/src/qpidd.cpp @@ -75,7 +75,7 @@ int run_broker(int argc, char *argv[], bool hidden) for (vector<string>::iterator iter = bootOptions.module.load.begin(); iter != bootOptions.module.load.end(); iter++) - qpid::tryShlib (iter->data(), false); + qpid::tryShlib (*iter); if (!bootOptions.module.noLoad) { bool isDefault = defaultPath == bootOptions.module.loadDir; |
