| 90 | } |
| 91 | |
| 92 | void AtomicFile::Commit() |
| 93 | { |
| 94 | flush(); |
| 95 | |
| 96 | auto h ((*this)->handle()); |
| 97 | |
| 98 | #ifdef _WIN32 |
| 99 | if (!FlushFileBuffers(h)) { |
| 100 | auto err (GetLastError()); |
| 101 | |
| 102 | BOOST_THROW_EXCEPTION(win32_error() |
| 103 | << boost::errinfo_api_function("FlushFileBuffers") |
| 104 | << errinfo_win32_error(err) |
| 105 | << boost::errinfo_file_name(m_TempFilename)); |
| 106 | } |
| 107 | #else /* _WIN32 */ |
| 108 | if (fsync(h)) { |
| 109 | auto err (errno); |
| 110 | |
| 111 | BOOST_THROW_EXCEPTION(posix_error() |
| 112 | << boost::errinfo_api_function("fsync") |
| 113 | << boost::errinfo_errno(err) |
| 114 | << boost::errinfo_file_name(m_TempFilename)); |
| 115 | } |
| 116 | #endif /* _WIN32 */ |
| 117 | |
| 118 | close(); |
| 119 | (void)::close(m_Fd); |
| 120 | m_Fd = -1; |
| 121 | |
| 122 | Utility::RenameFile(m_TempFilename, m_Path); |
| 123 | m_TempFilename = ""; |
| 124 | } |
no test coverage detected