uint64_t cur_modseq;
int ret;
- if (modseq >= file->sync_highest_modseq) {
+ if (modseq == file->sync_highest_modseq) {
*next_offset_r = file->sync_offset;
return 0;
}
cur_modseq = cache->highest_modseq;
}
- ret = mail_transaction_log_file_map(file, cur_offset,
- file->sync_offset);
+ /* make sure we've read until end of file. this is especially important
+ with non-head logs which might only have been opened without being
+ synced. */
+ ret = mail_transaction_log_file_map(file, cur_offset, (uoff_t)-1);
if (ret <= 0) {
if (ret < 0)
return -1;
return -1;
}
+ /* check sync_highest_modseq again in case sync_offset was updated */
+ if (modseq >= file->sync_highest_modseq) {
+ *next_offset_r = file->sync_offset;
+ return 0;
+ }
+
i_assert(cur_offset >= file->buffer_offset);
while (cur_offset < file->sync_offset) {
if (log_get_synced_record(file, &cur_offset, &hdr) < 0)