changeset 110:fd7b0a3e6260

support of boost 1.42 for debian
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Oct 2012 12:33:31 +0200
parents 8c0a5666b05f
children 0fc3b69c0357
files Core/FileStorage.cpp Core/HttpServer/FilesystemHttpHandler.cpp Core/Toolbox.cpp Core/Uuid.cpp Resources/CMake/BoostConfiguration.cmake
diffstat 5 files changed, 47 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Core/FileStorage.cpp	Thu Oct 04 11:50:44 2012 +0200
+++ b/Core/FileStorage.cpp	Thu Oct 04 12:33:31 2012 +0200
@@ -29,6 +29,16 @@
 
 #include <boost/filesystem/fstream.hpp>
 
+static std::string ToString(const boost::filesystem::path& p)
+{
+#if BOOST_HAS_FILESYSTEM_V3 == 1
+  return p.filename().string();
+#else
+  return p.filename();
+#endif
+}
+
+
 namespace Orthanc
 {
   boost::filesystem::path FileStorage::GetPath(const std::string& uuid) const
@@ -45,7 +55,10 @@
     path /= std::string(&uuid[0], &uuid[2]);
     path /= std::string(&uuid[2], &uuid[4]);
     path /= uuid;
+
+#if BOOST_HAS_FILESYSTEM_V3 == 1
     path.make_preferred();
+#endif
 
     return path;
   }
@@ -54,7 +67,8 @@
   {
     namespace fs = boost::filesystem;
 
-    root_ = fs::absolute(root);
+    //root_ = boost::filesystem::absolute(root).string();
+    root_ = root;
 
     if (fs::exists(root))
     {
@@ -170,7 +184,7 @@
     if (HasBufferCompressor())
     {
       std::string compressed;
-      Toolbox::ReadFile(compressed, GetPath(uuid).string());
+      Toolbox::ReadFile(compressed, ToString(GetPath(uuid)));
 
       if (compressed.size() != 0)
       {
@@ -207,12 +221,12 @@
           try
           {
             fs::path d = current->path();
-            std::string uuid = d.filename().string();
+            std::string uuid = ToString(d);
             if (Toolbox::IsUuid(uuid))
             {
               fs::path p0 = d.parent_path().parent_path().parent_path();
-              std::string p1 = d.parent_path().parent_path().filename().string();
-              std::string p2 = d.parent_path().filename().string();
+              std::string p1 = ToString(d.parent_path().parent_path());
+              std::string p2 = ToString(d.parent_path());
               if (p1.length() == 2 &&
                   p2.length() == 2 &&
                   p1 == uuid.substr(0, 2) &&
@@ -256,9 +270,15 @@
 
     // Remove the two parent directories, ignoring the error code if
     // these directories are not empty
+
+#if BOOST_HAS_FILESYSTEM_V3 == 1
     boost::system::error_code err;
     fs::remove(p.parent_path(), err);
     fs::remove(p.parent_path().parent_path(), err);
+#else
+    fs::remove(p.parent_path());
+    fs::remove(p.parent_path().parent_path());
+#endif
   }
 
 
--- a/Core/HttpServer/FilesystemHttpHandler.cpp	Thu Oct 04 11:50:44 2012 +0200
+++ b/Core/HttpServer/FilesystemHttpHandler.cpp	Thu Oct 04 12:33:31 2012 +0200
@@ -56,7 +56,12 @@
     fs::directory_iterator end;
     for (fs::directory_iterator it(p) ; it != end; ++it)
     {
+#if BOOST_HAS_FILESYSTEM_V3 == 1
       std::string f = it->path().filename().string();
+#else
+      std::string f = it->path().filename();
+#endif
+
       std::string h = Toolbox::FlattenUri(uri) + "/" + f;
       if (fs::is_directory(it->status()))
         output.SendString("<li><a href=\"" + h + "\">" + f + "</a></li>");
@@ -68,7 +73,12 @@
 
     for (fs::directory_iterator it(p) ; it != end; ++it)
     {
+#if BOOST_HAS_FILESYSTEM_V3 == 1
       std::string f = it->path().filename().string();
+#else
+      std::string f = it->path().filename();
+#endif
+
       std::string h = Toolbox::FlattenUri(uri) + "/" + f;
       if (fs::is_regular_file(it->status()))
         output.SendString("<li><a href=\"" + h + "\">" + f + "</a></li>");
--- a/Core/Toolbox.cpp	Thu Oct 04 11:50:44 2012 +0200
+++ b/Core/Toolbox.cpp	Thu Oct 04 12:33:31 2012 +0200
@@ -506,6 +506,4 @@
 
     return result;
   }
-
-
 }
--- a/Core/Uuid.cpp	Thu Oct 04 11:50:44 2012 +0200
+++ b/Core/Uuid.cpp	Thu Oct 04 12:33:31 2012 +0200
@@ -86,10 +86,17 @@
 
     TemporaryFile::TemporaryFile()
     {
+#if BOOST_HAS_FILESYSTEM_V3 == 1
+      boost::filesystem::path tmpDir = boost::filesystem::temp_directory_path();
+#elif defined(__linux__)
+      boost::filesystem::path tmpDir("/tmp");
+#else
+#error Support your platform here
+#endif
+
       // We use UUID to create unique path to temporary files
-      boost::filesystem::path tmp = boost::filesystem::temp_directory_path();
-      tmp /= "Orthanc-" + Orthanc::Toolbox::GenerateUuid();
-      path_ = tmp.string();
+      tmpDir /= "Orthanc-" + Orthanc::Toolbox::GenerateUuid();
+      path_ = tmpDir.string();
     }
 
 
--- a/Resources/CMake/BoostConfiguration.cmake	Thu Oct 04 11:50:44 2012 +0200
+++ b/Resources/CMake/BoostConfiguration.cmake	Thu Oct 04 12:33:31 2012 +0200
@@ -80,6 +80,7 @@
     -DBOOST_SYSTEM_NO_LIB
     -DBOOST_LOCALE_NO_LIB
     -DBOOST_HAS_LOCALE=1
+    -DBOOST_HAS_FILESYSTEM_V3=1
     )
 
   if (${CMAKE_COMPILER_IS_GNUCXX})
@@ -94,5 +95,6 @@
 else()
   add_definitions(
     -DBOOST_HAS_LOCALE=0
+    -DBOOST_HAS_FILESYSTEM_V3=0
     )
 endif()