| 50 | } |
| 51 | |
| 52 | Future<Void> flush(int size) { |
| 53 | // Avoid empty write |
| 54 | if (size == 0) { |
| 55 | return Void(); |
| 56 | } |
| 57 | |
| 58 | ASSERT(size <= m_buffer.size()); |
| 59 | |
| 60 | // Keep a reference to the old buffer |
| 61 | Standalone<VectorRef<uint8_t>> old = m_buffer; |
| 62 | // Make a new buffer, initialized with the excess bytes over the block size from the old buffer |
| 63 | m_buffer = Standalone<VectorRef<uint8_t>>(old.slice(size, old.size())); |
| 64 | |
| 65 | // Write the old buffer to the underlying file and update the write offset |
| 66 | Future<Void> r = uncancellable(holdWhile(old, m_file->write(old.begin(), size, m_writeOffset))); |
| 67 | m_writeOffset += size; |
| 68 | |
| 69 | return r; |
| 70 | } |
| 71 | |
| 72 | ACTOR static Future<Void> finish_impl(Reference<BackupFile> f) { |
| 73 | wait(f->flush(f->m_buffer.size())); |
no test coverage detected