comparison Core/SystemToolbox.cpp @ 3521:793c141be598

added an option not to log ReadFile errors
author Alain Mazy <alain@mazy.be>
date Mon, 23 Sep 2019 17:47:54 +0200
parents c08bb6ac3b7f
children 94f4a18a79cc
comparison
equal deleted inserted replaced
3515:13f9ccf05a8e 3521:793c141be598
210 return size; 210 return size;
211 } 211 }
212 212
213 213
214 void SystemToolbox::ReadFile(std::string& content, 214 void SystemToolbox::ReadFile(std::string& content,
215 const std::string& path) 215 const std::string& path,
216 bool log)
216 { 217 {
217 if (!IsRegularFile(path)) 218 if (!IsRegularFile(path))
218 { 219 {
219 throw OrthancException(ErrorCode_RegularFileExpected, 220 throw OrthancException(ErrorCode_RegularFileExpected,
220 "The path does not point to a regular file: " + path); 221 "The path does not point to a regular file: " + path,
222 log);
221 } 223 }
222 224
223 boost::filesystem::ifstream f; 225 boost::filesystem::ifstream f;
224 f.open(path, std::ifstream::in | std::ifstream::binary); 226 f.open(path, std::ifstream::in | std::ifstream::binary);
225 if (!f.good()) 227 if (!f.good())
226 { 228 {
227 throw OrthancException(ErrorCode_InexistentFile); 229 throw OrthancException(ErrorCode_InexistentFile,
230 "File not found: " + path,
231 log);
228 } 232 }
229 233
230 std::streamsize size = GetStreamSize(f); 234 std::streamsize size = GetStreamSize(f);
231 content.resize(static_cast<size_t>(size)); 235 content.resize(static_cast<size_t>(size));
232 if (size != 0) 236 if (size != 0)