static void mailbox_repack_abort(struct mailbox_repack **repackptr)
{
    struct mailbox_repack *repack = *repackptr;
    int i;

    if (!repack) return; /* safe against double-free */

    seqset_free(&repack->seqset);

    /* close and remove index */
    xclose(repack->newmailbox.index_fd);
    unlink(mailbox_meta_newfname(repack->mailbox, META_INDEX));

    /* close and remove all new caches */
    for (i = 0; i < repack->caches.count; i++) {
        struct mappedfile *cachefile = ptrarray_nth(&repack->caches, i);
        char *fname = xstrdup(mappedfile_fname(cachefile));
        mappedfile_commit(cachefile);  /* gotta commit to clear the dirty flag.  Alternative would be an unlink function */
        mappedfile_unlock(cachefile);
        mappedfile_close(&cachefile);
        unlink(fname);
        free(fname);
    }
    ptrarray_fini(&repack->caches);

    // drop the map if we've mapped in the newmailbox index separately
    if (repack->newmailbox.index_base != repack->mailbox->index_base) {
        map_free(&repack->newmailbox.index_base, &repack->newmailbox.index_len);
    }

    mailbox_abort(repack->mailbox);

    free(repack->userid);
    free(repack);
    *repackptr = NULL;

    return;
}
static void mailbox_repack_abort(struct mailbox_repack **repackptr)
{
    struct mailbox_repack *repack = *repackptr;
    int i;

    if (!repack) return;  

    seqset_free(&repack->seqset);

     
    xclose(repack->newmailbox.index_fd);
    unlink(mailbox_meta_newfname(repack->mailbox, META_INDEX));

     
    for (i = 0; i < repack->caches.count; i++) {
        struct mappedfile *cachefile = ptrarray_nth(&repack->caches, i);
        char *fname = xstrdup(mappedfile_fname(cachefile));
        mappedfile_commit(cachefile);   
        mappedfile_unlock(cachefile);
        mappedfile_close(&cachefile);
        unlink(fname);
        free(fname);
    }
    ptrarray_fini(&repack->caches);

     
    if (repack->newmailbox.index_base != repack->mailbox->index_base) {
        map_free(&repack->newmailbox.index_base, &repack->newmailbox.index_len);
    }

    mailbox_abort(repack->mailbox);

    free(repack->userid);
    free(repack);
    *repackptr = NULL;

    return;
}