Mercurial > hg > orthanc-webviewer
comparison Orthanc/Core/Toolbox.cpp @ 125:145e654112d6
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 28 Jan 2016 17:08:44 +0100 |
parents | 3809121c3290 |
children | e8cfda4c8a2f |
comparison
equal
deleted
inserted
replaced
124:f395dddfbf16 | 125:145e654112d6 |
---|---|
125 { | 125 { |
126 finish = true; | 126 finish = true; |
127 } | 127 } |
128 #endif | 128 #endif |
129 | 129 |
130 | |
130 void Toolbox::USleep(uint64_t microSeconds) | 131 void Toolbox::USleep(uint64_t microSeconds) |
131 { | 132 { |
132 #if defined(_WIN32) | 133 #if defined(_WIN32) |
133 ::Sleep(static_cast<DWORD>(microSeconds / static_cast<uint64_t>(1000))); | 134 ::Sleep(static_cast<DWORD>(microSeconds / static_cast<uint64_t>(1000))); |
134 #elif defined(__linux) || defined(__APPLE__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) | 135 #elif defined(__linux) || defined(__APPLE__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) |
206 | 207 |
207 | 208 |
208 void Toolbox::ReadFile(std::string& content, | 209 void Toolbox::ReadFile(std::string& content, |
209 const std::string& path) | 210 const std::string& path) |
210 { | 211 { |
211 if (!boost::filesystem::is_regular_file(path)) | 212 if (!IsRegularFile(path)) |
212 { | 213 { |
213 LOG(ERROR) << std::string("The path does not point to a regular file: ") << path; | 214 LOG(ERROR) << std::string("The path does not point to a regular file: ") << path; |
214 throw OrthancException(ErrorCode_RegularFileExpected); | 215 throw OrthancException(ErrorCode_RegularFileExpected); |
215 } | 216 } |
216 | 217 |
266 | 267 |
267 void Toolbox::RemoveFile(const std::string& path) | 268 void Toolbox::RemoveFile(const std::string& path) |
268 { | 269 { |
269 if (boost::filesystem::exists(path)) | 270 if (boost::filesystem::exists(path)) |
270 { | 271 { |
271 if (boost::filesystem::is_regular_file(path)) | 272 if (IsRegularFile(path)) |
272 { | 273 { |
273 boost::filesystem::remove(path); | 274 boost::filesystem::remove(path); |
274 } | 275 } |
275 else | 276 else |
276 { | 277 { |
1380 return static_cast<int>(_getpid()); | 1381 return static_cast<int>(_getpid()); |
1381 #else | 1382 #else |
1382 return static_cast<int>(getpid()); | 1383 return static_cast<int>(getpid()); |
1383 #endif | 1384 #endif |
1384 } | 1385 } |
1386 | |
1387 | |
1388 bool Toolbox::IsRegularFile(const std::string& path) | |
1389 { | |
1390 namespace fs = boost::filesystem; | |
1391 | |
1392 try | |
1393 { | |
1394 if (fs::exists(path)) | |
1395 { | |
1396 fs::file_status status = fs::status(path); | |
1397 return (status.type() == boost::filesystem::regular_file || | |
1398 status.type() == boost::filesystem::reparse_file); // Fix BitBucket issue #11 | |
1399 } | |
1400 } | |
1401 catch (fs::filesystem_error&) | |
1402 { | |
1403 } | |
1404 | |
1405 return false; | |
1406 } | |
1385 } | 1407 } |
1386 | 1408 |