diff options
author | vng <viktor.govako@gmail.com> | 2012-05-08 14:11:13 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:38:06 +0300 |
commit | 8d3730c562ebc893931a784927f71d4065da54ec (patch) | |
tree | 8ceea721736f9ae7a4221680df6fb8930c458636 /coding/file_container.cpp | |
parent | d84d08fc223e025da56265e167a515500b5782ad (diff) |
Add "delete_section" to generator_tool.
Diffstat (limited to 'coding/file_container.cpp')
-rw-r--r-- | coding/file_container.cpp | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/coding/file_container.cpp b/coding/file_container.cpp index 623b83cf5d..a14e493730 100644 --- a/coding/file_container.cpp +++ b/coding/file_container.cpp @@ -137,6 +137,28 @@ uint64_t FilesContainerW::SaveCurrentSize() return curr; } +void FilesContainerW::DeleteSection(Tag const & tag) +{ + { + // rewrite files on disk + FilesContainerR contR(m_name); + FilesContainerW contW(m_name + ".tmp"); + + for (size_t i = 0; i < m_info.size(); ++i) + { + if (m_info[i].m_tag != tag) + contW.Write(contR.GetReader(m_info[i].m_tag), m_info[i].m_tag); + } + } + + // swap files + if (!my::DeleteFileX(m_name) || !my::RenameFileX(m_name + ".tmp", m_name)) + MYTHROW(RootException, ("Can't rename file", m_name, "Sharing violation or disk error!")); + + // do open to update m_info + Open(FileWriter::OP_WRITE_EXISTING); +} + FileWriter FilesContainerW::GetWriter(Tag const & tag) { ASSERT(!m_bFinished, ()); @@ -155,22 +177,7 @@ FileWriter FilesContainerW::GetWriter(Tag const & tag) } else { - { - FilesContainerR contR(m_name); - FilesContainerW contW(m_name + ".tmp"); - - for (size_t i = 0; i < m_info.size(); ++i) - { - if (m_info[i].m_tag != it->m_tag) - contW.Write(contR.GetReader(m_info[i].m_tag), m_info[i].m_tag); - } - } - - my::DeleteFileX(m_name); - if (!my::RenameFileX(m_name + ".tmp", m_name)) - MYTHROW(RootException, ("Can't rename file", m_name, "Sharing violation or disk error!")); - - Open(FileWriter::OP_WRITE_EXISTING); + DeleteSection(it->m_tag); } } @@ -201,22 +208,10 @@ void FilesContainerW::Write(string const & fPath, Tag const & tag) void FilesContainerW::Write(ModelReaderPtr reader, Tag const & tag) { - uint64_t const bufferSize = 4*1024; - char buffer[bufferSize]; - ReaderSource<ModelReaderPtr> src(reader); FileWriter writer = GetWriter(tag); - uint64_t size = reader.Size(); - while (size > 0) - { - size_t const curr = static_cast<size_t>(min(bufferSize, size)); - - src.Read(&buffer[0], curr); - writer.Write(&buffer[0], curr); - - size -= curr; - } + rw::ReadAndWrite(src, writer, 4*1024); } void FilesContainerW::Write(vector<char> const & buffer, Tag const & tag) |