| 168 | } |
| 169 | |
| 170 | void ChangeLog::Segment::copyTo(const PathName& filename) const |
| 171 | { |
| 172 | fb_assert(m_header != &m_builtinHeader); |
| 173 | |
| 174 | if (os_utils::lseek(m_handle, 0, SEEK_SET) != 0) |
| 175 | raiseIOError("seek", m_filename.c_str(), ERRNO); |
| 176 | |
| 177 | const auto totalLength = m_header->hdr_length; |
| 178 | fb_assert(totalLength > sizeof(SegmentHeader)); |
| 179 | |
| 180 | const auto dstHandle = os_utils::openCreateSharedFile(filename.c_str(), O_TRUNC | O_BINARY); |
| 181 | |
| 182 | AutoFile dstFile(dstHandle); |
| 183 | |
| 184 | Vector<UCHAR, COPY_BLOCK_SIZE> buffer; |
| 185 | const auto data = buffer.begin(); |
| 186 | |
| 187 | for (FB_UINT64 offset = 0; offset < totalLength; offset += COPY_BLOCK_SIZE) |
| 188 | { |
| 189 | const auto remaining = totalLength - offset; |
| 190 | const SINT64 length = MIN(remaining, COPY_BLOCK_SIZE); |
| 191 | |
| 192 | if (::read(m_handle, data, length) != length) |
| 193 | { |
| 194 | const ISC_STATUS errcode = ERRNO; |
| 195 | |
| 196 | dstFile.release(); |
| 197 | unlink(filename.c_str()); |
| 198 | raiseIOError("read", m_filename.c_str(), errcode); |
| 199 | } |
| 200 | |
| 201 | if (::write(dstFile, data, length) != length) |
| 202 | { |
| 203 | const ISC_STATUS errcode = ERRNO; |
| 204 | |
| 205 | dstFile.release(); |
| 206 | unlink(filename.c_str()); |
| 207 | raiseIOError("write", filename.c_str(), errcode); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | flushFile(dstHandle); |
| 212 | } |
| 213 | |
| 214 | void ChangeLog::Segment::append(ULONG length, const UCHAR* data) |
| 215 | { |
no test coverage detected