Mercurial > hg > orthanc
comparison Core/FileStorage.cpp @ 50:a15e90e5d6fc
rename in code
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 Sep 2012 15:50:12 +0200 |
parents | 3959d33612cc |
children | c996319e90bc |
comparison
equal
deleted
inserted
replaced
49:e1a3ae0dadf3 | 50:a15e90e5d6fc |
---|---|
1 /** | 1 /** |
2 * Palantir - A Lightweight, RESTful DICOM Store | 2 * Palanthir - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
4 * Belgium | 4 * Belgium |
5 * | 5 * |
6 * This program is free software: you can redistribute it and/or | 6 * This program is free software: you can redistribute it and/or |
7 * modify it under the terms of the GNU General Public License as | 7 * modify it under the terms of the GNU General Public License as |
21 #include "FileStorage.h" | 21 #include "FileStorage.h" |
22 | 22 |
23 // http://stackoverflow.com/questions/1576272/storing-large-number-of-files-in-file-system | 23 // http://stackoverflow.com/questions/1576272/storing-large-number-of-files-in-file-system |
24 // http://stackoverflow.com/questions/446358/storing-a-large-number-of-images | 24 // http://stackoverflow.com/questions/446358/storing-a-large-number-of-images |
25 | 25 |
26 #include "PalantirException.h" | 26 #include "PalanthirException.h" |
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 namespace Palantir | 32 namespace Palanthir |
33 { | 33 { |
34 boost::filesystem::path FileStorage::GetPath(const std::string& uuid) const | 34 boost::filesystem::path FileStorage::GetPath(const std::string& uuid) const |
35 { | 35 { |
36 namespace fs = boost::filesystem; | 36 namespace fs = boost::filesystem; |
37 | 37 |
38 if (!Toolbox::IsUuid(uuid)) | 38 if (!Toolbox::IsUuid(uuid)) |
39 { | 39 { |
40 throw PalantirException(ErrorCode_ParameterOutOfRange); | 40 throw PalanthirException(ErrorCode_ParameterOutOfRange); |
41 } | 41 } |
42 | 42 |
43 fs::path path = root_; | 43 fs::path path = root_; |
44 | 44 |
45 path /= std::string(&uuid[0], &uuid[2]); | 45 path /= std::string(&uuid[0], &uuid[2]); |
58 | 58 |
59 if (fs::exists(root)) | 59 if (fs::exists(root)) |
60 { | 60 { |
61 if (!fs::is_directory(root)) | 61 if (!fs::is_directory(root)) |
62 { | 62 { |
63 throw PalantirException("The file storage root directory is a file"); | 63 throw PalanthirException("The file storage root directory is a file"); |
64 } | 64 } |
65 } | 65 } |
66 else | 66 else |
67 { | 67 { |
68 if (!fs::create_directories(root)) | 68 if (!fs::create_directories(root)) |
69 { | 69 { |
70 throw PalantirException("Unable to create the file storage root directory"); | 70 throw PalanthirException("Unable to create the file storage root directory"); |
71 } | 71 } |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 std::string FileStorage::CreateFileWithoutCompression(const void* content, size_t size) | 75 std::string FileStorage::CreateFileWithoutCompression(const void* content, size_t size) |
94 | 94 |
95 if (boost::filesystem::exists(path.parent_path())) | 95 if (boost::filesystem::exists(path.parent_path())) |
96 { | 96 { |
97 if (!boost::filesystem::is_directory(path.parent_path())) | 97 if (!boost::filesystem::is_directory(path.parent_path())) |
98 { | 98 { |
99 throw PalantirException("The subdirectory to be created is already occupied by a regular file"); | 99 throw PalanthirException("The subdirectory to be created is already occupied by a regular file"); |
100 } | 100 } |
101 } | 101 } |
102 else | 102 else |
103 { | 103 { |
104 if (!boost::filesystem::create_directories(path.parent_path())) | 104 if (!boost::filesystem::create_directories(path.parent_path())) |
105 { | 105 { |
106 throw PalantirException("Unable to create a subdirectory in the file storage"); | 106 throw PalanthirException("Unable to create a subdirectory in the file storage"); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 boost::filesystem::ofstream f; | 110 boost::filesystem::ofstream f; |
111 f.open(path, std::ofstream::out | std::ios::binary); | 111 f.open(path, std::ofstream::out | std::ios::binary); |
112 if (!f.good()) | 112 if (!f.good()) |
113 { | 113 { |
114 throw PalantirException("Unable to create a new file in the file storage"); | 114 throw PalanthirException("Unable to create a new file in the file storage"); |
115 } | 115 } |
116 | 116 |
117 if (size != 0) | 117 if (size != 0) |
118 { | 118 { |
119 f.write(static_cast<const char*>(content), size); | 119 f.write(static_cast<const char*>(content), size); |
120 if (!f.good()) | 120 if (!f.good()) |
121 { | 121 { |
122 f.close(); | 122 f.close(); |
123 throw PalantirException("Unable to write to the new file in the file storage"); | 123 throw PalanthirException("Unable to write to the new file in the file storage"); |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 f.close(); | 127 f.close(); |
128 | 128 |