| 368 | } |
| 369 | |
| 370 | std::unique_ptr<FilesContainerWriter> FilesContainerW::GetWriter(Tag const & tag) |
| 371 | { |
| 372 | ASSERT(!m_finished, ()); |
| 373 | |
| 374 | InfoContainer::const_iterator it = find_if(m_info.begin(), m_info.end(), EqualTag(tag)); |
| 375 | if (it != m_info.end()) |
| 376 | { |
| 377 | if (it + 1 == m_info.end()) |
| 378 | { |
| 379 | m_info.pop_back(); |
| 380 | |
| 381 | if (m_info.empty()) |
| 382 | StartNew(); |
| 383 | else |
| 384 | m_needRewrite = true; |
| 385 | } |
| 386 | else |
| 387 | { |
| 388 | DeleteSection(it->m_tag); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | if (m_needRewrite) |
| 393 | { |
| 394 | m_needRewrite = false; |
| 395 | |
| 396 | ASSERT(!m_info.empty(), ()); |
| 397 | |
| 398 | uint64_t const curr = m_info.back().m_offset + m_info.back().m_size; |
| 399 | auto writer = std::make_unique<TruncatingFileWriter>(m_name); |
| 400 | writer->Seek(curr); |
| 401 | writer->WritePaddingByPos(kSectionAlignment); |
| 402 | |
| 403 | m_info.emplace_back(tag, writer->Pos()); |
| 404 | ASSERT_EQUAL(m_info.back().m_offset % kSectionAlignment, 0, ()); |
| 405 | return writer; |
| 406 | } |
| 407 | else |
| 408 | { |
| 409 | SaveCurrentSize(); |
| 410 | |
| 411 | auto writer = std::make_unique<FilesContainerWriter>(m_name, FileWriter::OP_APPEND); |
| 412 | writer->WritePaddingByPos(kSectionAlignment); |
| 413 | |
| 414 | m_info.emplace_back(tag, writer->Pos()); |
| 415 | ASSERT_EQUAL(m_info.back().m_offset % kSectionAlignment, 0, ()); |
| 416 | return writer; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | void FilesContainerW::Write(std::string const & fPath, Tag const & tag) |
| 421 | { |