qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject svn commit: r1430554 - in /qpid/branches/0.20/qpid/cpp/src: CMakeLists.txt Makefile.am qpid/Modules.cpp qpid/Modules.h qpid/client/LoadPlugins.cpp qpid/sys/FileSysDir.h qpid/sys/posix/FileSysDir.cpp qpid/sys/windows/FileSysDir.cpp qpidd.cpp
Date Tue, 08 Jan 2013 21:43:43 GMT
Author: astitcher
Date: Tue Jan  8 21:43:42 2013
New Revision: 1430554

URL: http://svn.apache.org/viewvc?rev=1430554&view=rev
Log:
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

[Cherry picked from trunk@1424247]

Modified:
    qpid/branches/0.20/qpid/cpp/src/CMakeLists.txt
    qpid/branches/0.20/qpid/cpp/src/Makefile.am
    qpid/branches/0.20/qpid/cpp/src/qpid/Modules.cpp
    qpid/branches/0.20/qpid/cpp/src/qpid/Modules.h
    qpid/branches/0.20/qpid/cpp/src/qpid/client/LoadPlugins.cpp
    qpid/branches/0.20/qpid/cpp/src/qpid/sys/FileSysDir.h
    qpid/branches/0.20/qpid/cpp/src/qpid/sys/posix/FileSysDir.cpp
    qpid/branches/0.20/qpid/cpp/src/qpid/sys/windows/FileSysDir.cpp
    qpid/branches/0.20/qpid/cpp/src/qpidd.cpp

Modified: qpid/branches/0.20/qpid/cpp/src/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/branches/0.20/qpid/cpp/src/CMakeLists.txt?rev=1430554&r1=1430553&r2=1430554&view=diff
==============================================================================
--- qpid/branches/0.20/qpid/cpp/src/CMakeLists.txt (original)
+++ qpid/branches/0.20/qpid/cpp/src/CMakeLists.txt Tue Jan  8 21:43:42 2013
@@ -1470,8 +1470,6 @@ install_pdb (qmfconsole ${QPID_COMPONENT
 # 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)

Modified: qpid/branches/0.20/qpid/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/qpid/branches/0.20/qpid/cpp/src/Makefile.am?rev=1430554&r1=1430553&r2=1430554&view=diff
==============================================================================
--- qpid/branches/0.20/qpid/cpp/src/Makefile.am (original)
+++ qpid/branches/0.20/qpid/cpp/src/Makefile.am Tue Jan  8 21:43:42 2013
@@ -138,8 +138,6 @@ qpidtest_SCRIPTS =
 tmoduleexecdir = $(libdir)/qpid/tests
 tmoduleexec_LTLIBRARIES=
 
-AM_CXXFLAGS += -DBOOST_FILESYSTEM_VERSION=2
-
 ## Automake macros to build libraries and executables.
 qpidd_CXXFLAGS = $(AM_CXXFLAGS) -DQPIDD_MODULE_DIR=\"$(dmoduleexecdir)\" -DQPIDD_CONF_FILE=\"$(sysconfdir)/qpidd.conf\"
-DQPIDC_CONF_FILE=\"$(confdir)/qpidc.conf\"
 libqpidclient_la_CXXFLAGS = $(AM_CXXFLAGS) -DQPIDC_MODULE_DIR=\"$(cmoduleexecdir)\" -DQPIDC_CONF_FILE=\"$(confdir)/qpidc.conf\"

Modified: qpid/branches/0.20/qpid/cpp/src/qpid/Modules.cpp
URL: http://svn.apache.org/viewvc/qpid/branches/0.20/qpid/cpp/src/qpid/Modules.cpp?rev=1430554&r1=1430553&r2=1430554&view=diff
==============================================================================
--- qpid/branches/0.20/qpid/cpp/src/qpid/Modules.cpp (original)
+++ qpid/branches/0.20/qpid/cpp/src/qpid/Modules.cpp Tue Jan  8 21:43:42 2013
@@ -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::
         ("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

Modified: qpid/branches/0.20/qpid/cpp/src/qpid/Modules.h
URL: http://svn.apache.org/viewvc/qpid/branches/0.20/qpid/cpp/src/qpid/Modules.h?rev=1430554&r1=1430553&r2=1430554&view=diff
==============================================================================
--- qpid/branches/0.20/qpid/cpp/src/qpid/Modules.h (original)
+++ qpid/branches/0.20/qpid/cpp/src/qpid/Modules.h Tue Jan  8 21:43:42 2013
@@ -36,7 +36,7 @@ struct ModuleOptions : public qpid::Opti
     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

Modified: qpid/branches/0.20/qpid/cpp/src/qpid/client/LoadPlugins.cpp
URL: http://svn.apache.org/viewvc/qpid/branches/0.20/qpid/cpp/src/qpid/client/LoadPlugins.cpp?rev=1430554&r1=1430553&r2=1430554&view=diff
==============================================================================
--- qpid/branches/0.20/qpid/cpp/src/qpid/client/LoadPlugins.cpp (original)
+++ qpid/branches/0.20/qpid/cpp/src/qpid/client/LoadPlugins.cpp Tue Jan  8 21:43:42 2013
@@ -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;

Modified: qpid/branches/0.20/qpid/cpp/src/qpid/sys/FileSysDir.h
URL: http://svn.apache.org/viewvc/qpid/branches/0.20/qpid/cpp/src/qpid/sys/FileSysDir.h?rev=1430554&r1=1430553&r2=1430554&view=diff
==============================================================================
--- qpid/branches/0.20/qpid/cpp/src/qpid/sys/FileSysDir.h (original)
+++ qpid/branches/0.20/qpid/cpp/src/qpid/sys/FileSysDir.h Tue Jan  8 21:43:42 2013
@@ -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; }
 };
  

Modified: qpid/branches/0.20/qpid/cpp/src/qpid/sys/posix/FileSysDir.cpp
URL: http://svn.apache.org/viewvc/qpid/branches/0.20/qpid/cpp/src/qpid/sys/posix/FileSysDir.cpp?rev=1430554&r1=1430553&r2=1430554&view=diff
==============================================================================
--- qpid/branches/0.20/qpid/cpp/src/qpid/sys/posix/FileSysDir.cpp (original)
+++ qpid/branches/0.20/qpid/cpp/src/qpid/sys/posix/FileSysDir.cpp Tue Jan  8 21:43:42 2013
@@ -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

Modified: qpid/branches/0.20/qpid/cpp/src/qpid/sys/windows/FileSysDir.cpp
URL: http://svn.apache.org/viewvc/qpid/branches/0.20/qpid/cpp/src/qpid/sys/windows/FileSysDir.cpp?rev=1430554&r1=1430553&r2=1430554&view=diff
==============================================================================
--- qpid/branches/0.20/qpid/cpp/src/qpid/sys/windows/FileSysDir.cpp (original)
+++ qpid/branches/0.20/qpid/cpp/src/qpid/sys/windows/FileSysDir.cpp Tue Jan  8 21:43:42 2013
@@ -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

Modified: qpid/branches/0.20/qpid/cpp/src/qpidd.cpp
URL: http://svn.apache.org/viewvc/qpid/branches/0.20/qpid/cpp/src/qpidd.cpp?rev=1430554&r1=1430553&r2=1430554&view=diff
==============================================================================
--- qpid/branches/0.20/qpid/cpp/src/qpidd.cpp (original)
+++ qpid/branches/0.20/qpid/cpp/src/qpidd.cpp Tue Jan  8 21:43:42 2013
@@ -75,7 +75,7 @@ int run_broker(int argc, char *argv[], b
         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;



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message