| 153 | } |
| 154 | |
| 155 | FileIndexedIO::StreamFile::~StreamFile() |
| 156 | { |
| 157 | if ( m_openmode == IndexedIO::Write || m_openmode == IndexedIO::Append ) |
| 158 | { |
| 159 | std::fstream *f = static_cast< std::fstream * >( m_stream ); |
| 160 | |
| 161 | f->seekg( 0, std::ios::end ); |
| 162 | uint64_t fileEnd = f->tellg(); |
| 163 | |
| 164 | // .. and the length of that file extends beyond the end of the index |
| 165 | if ( fileEnd > m_endPosition ) |
| 166 | { |
| 167 | /// Close the file before truncation |
| 168 | delete m_stream; |
| 169 | m_stream = nullptr; |
| 170 | |
| 171 | /// Truncate the file at the end of the index |
| 172 | fs::resize_file( m_filename, m_endPosition ); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | bool FileIndexedIO::StreamFile::canRead( const std::string &path ) |
| 178 | { |