comparison Core/FileStorage.cpp @ 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 c996319e90bc
children fe180eae201d
comparison
equal deleted inserted replaced
109:8c0a5666b05f 110:fd7b0a3e6260
27 #include "Toolbox.h" 27 #include "Toolbox.h"
28 #include "Uuid.h" 28 #include "Uuid.h"
29 29
30 #include <boost/filesystem/fstream.hpp> 30 #include <boost/filesystem/fstream.hpp>
31 31
32 static std::string ToString(const boost::filesystem::path& p)
33 {
34 #if BOOST_HAS_FILESYSTEM_V3 == 1
35 return p.filename().string();
36 #else
37 return p.filename();
38 #endif
39 }
40
41
32 namespace Orthanc 42 namespace Orthanc
33 { 43 {
34 boost::filesystem::path FileStorage::GetPath(const std::string& uuid) const 44 boost::filesystem::path FileStorage::GetPath(const std::string& uuid) const
35 { 45 {
36 namespace fs = boost::filesystem; 46 namespace fs = boost::filesystem;
43 fs::path path = root_; 53 fs::path path = root_;
44 54
45 path /= std::string(&uuid[0], &uuid[2]); 55 path /= std::string(&uuid[0], &uuid[2]);
46 path /= std::string(&uuid[2], &uuid[4]); 56 path /= std::string(&uuid[2], &uuid[4]);
47 path /= uuid; 57 path /= uuid;
58
59 #if BOOST_HAS_FILESYSTEM_V3 == 1
48 path.make_preferred(); 60 path.make_preferred();
61 #endif
49 62
50 return path; 63 return path;
51 } 64 }
52 65
53 FileStorage::FileStorage(std::string root) 66 FileStorage::FileStorage(std::string root)
54 { 67 {
55 namespace fs = boost::filesystem; 68 namespace fs = boost::filesystem;
56 69
57 root_ = fs::absolute(root); 70 //root_ = boost::filesystem::absolute(root).string();
71 root_ = root;
58 72
59 if (fs::exists(root)) 73 if (fs::exists(root))
60 { 74 {
61 if (!fs::is_directory(root)) 75 if (!fs::is_directory(root))
62 { 76 {
168 content.clear(); 182 content.clear();
169 183
170 if (HasBufferCompressor()) 184 if (HasBufferCompressor())
171 { 185 {
172 std::string compressed; 186 std::string compressed;
173 Toolbox::ReadFile(compressed, GetPath(uuid).string()); 187 Toolbox::ReadFile(compressed, ToString(GetPath(uuid)));
174 188
175 if (compressed.size() != 0) 189 if (compressed.size() != 0)
176 { 190 {
177 compressor_->Uncompress(content, compressed); 191 compressor_->Uncompress(content, compressed);
178 } 192 }
205 if (fs::is_regular_file(current->status())) 219 if (fs::is_regular_file(current->status()))
206 { 220 {
207 try 221 try
208 { 222 {
209 fs::path d = current->path(); 223 fs::path d = current->path();
210 std::string uuid = d.filename().string(); 224 std::string uuid = ToString(d);
211 if (Toolbox::IsUuid(uuid)) 225 if (Toolbox::IsUuid(uuid))
212 { 226 {
213 fs::path p0 = d.parent_path().parent_path().parent_path(); 227 fs::path p0 = d.parent_path().parent_path().parent_path();
214 std::string p1 = d.parent_path().parent_path().filename().string(); 228 std::string p1 = ToString(d.parent_path().parent_path());
215 std::string p2 = d.parent_path().filename().string(); 229 std::string p2 = ToString(d.parent_path());
216 if (p1.length() == 2 && 230 if (p1.length() == 2 &&
217 p2.length() == 2 && 231 p2.length() == 2 &&
218 p1 == uuid.substr(0, 2) && 232 p1 == uuid.substr(0, 2) &&
219 p2 == uuid.substr(2, 2) && 233 p2 == uuid.substr(2, 2) &&
220 p0 == root_) 234 p0 == root_)
254 fs::path p = GetPath(uuid); 268 fs::path p = GetPath(uuid);
255 fs::remove(p); 269 fs::remove(p);
256 270
257 // Remove the two parent directories, ignoring the error code if 271 // Remove the two parent directories, ignoring the error code if
258 // these directories are not empty 272 // these directories are not empty
273
274 #if BOOST_HAS_FILESYSTEM_V3 == 1
259 boost::system::error_code err; 275 boost::system::error_code err;
260 fs::remove(p.parent_path(), err); 276 fs::remove(p.parent_path(), err);
261 fs::remove(p.parent_path().parent_path(), err); 277 fs::remove(p.parent_path().parent_path(), err);
278 #else
279 fs::remove(p.parent_path());
280 fs::remove(p.parent_path().parent_path());
281 #endif
262 } 282 }
263 283
264 284
265 uintmax_t FileStorage::GetCapacity() const 285 uintmax_t FileStorage::GetCapacity() const
266 { 286 {