static int mailbox_repack_add(struct mailbox_repack *repack,
                              struct index_record *record)
{
    struct mappedfile *cachefile;
    indexbuffer_t ibuf;
    unsigned char *buf = ibuf.buf;
    int r;
    int n;

    cachefile = repack_cachefile(repack, record);

    /* write out the new cache record - need to clear the cache_offset
     * so it gets reset in the new record */
    record->cache_offset = 0;
    r = cache_append_record(cachefile, record);
    if (r) return r;

    /* write the index record out */
    mailbox_index_record_to_buf(record, repack->newmailbox.i.minor_version, buf);
    n = retry_write(repack->newmailbox.index_fd, buf, repack->newmailbox.i.record_size);
    if (n == -1)
        return IMAP_IOERROR;

    repack->newmailbox.i.num_records++;

    return 0;
}
static int mailbox_repack_add(struct mailbox_repack *repack,
                              struct index_record *record)
{
    struct mappedfile *cachefile;
    indexbuffer_t ibuf;
    unsigned char *buf = ibuf.buf;
    int r;
    int n;

    cachefile = repack_cachefile(repack, record);

     
    record->cache_offset = 0;
    r = cache_append_record(cachefile, record);
    if (r) return r;

     
    mailbox_index_record_to_buf(record, repack->newmailbox.i.minor_version, buf);
    n = retry_write(repack->newmailbox.index_fd, buf, repack->newmailbox.i.record_size);
    if (n == -1)
        return IMAP_IOERROR;

    repack->newmailbox.i.num_records++;

    return 0;
}