mutt stable branch with some hacks

Compress: fix check_mailbox and sync_mailbox.

Change check_mailbox to delegate to the child_ops->check_mailbox if
the compressed mailbox has changed. This allows the mailbox to
properly recover if both the decompressed mailbox and compressed file
have changed.

Change sync_mailbox to call check_mailbox before attempting to sync.
This will prevent overwriting external changes to the compressed
mailbox.

+23 -26
+23 -26
compress.c
··· 646 646 if (!ci) 647 647 return -1; 648 648 649 + struct mx_ops *ops = ci->child_ops; 650 + if (!ops) 651 + return -1; 652 + 649 653 int size = get_size (ctx->realpath); 650 654 if (size == ci->size) 651 655 return 0; 652 656 653 - /* TODO: this is a copout. We should reopen the compressed mailbox 654 - * and call mutt_reopen_mailbox. */ 655 - if (ctx->changed) 657 + if (!lock_realpath (ctx, 0)) 656 658 { 657 - mutt_free_compress_info (ctx); 658 - mx_fastclose_mailbox (ctx); 659 - mutt_error (_("Mailbox was corrupted!")); 659 + mutt_error (_("Unable to lock mailbox!")); 660 660 return -1; 661 661 } 662 662 663 - /* TODO: this block leaks memory. this is doing it all wrong */ 664 - close_mailbox (ctx); 663 + int rc = execute_command (ctx, ci->open, _("Decompressing %s")); 664 + store_size (ctx); 665 + unlock_realpath (ctx); 666 + if (rc == 0) 667 + return -1; 665 668 666 - const char *path = ctx->path; 667 - ctx->path = NULL; 668 - 669 - mx_open_mailbox (path, 0, ctx); 670 - FREE(&path); 671 - 672 - return MUTT_REOPENED; 669 + return ops->check (ctx, index_hint); 673 670 } 674 671 675 672 ··· 852 849 return -1; 853 850 } 854 851 855 - /* TODO: check if mailbox changed first! */ 852 + int rc = check_mailbox (ctx, index_hint); 853 + if (rc != 0) 854 + goto sync_cleanup; 856 855 857 - int rc = ops->sync (ctx, index_hint); 856 + rc = ops->sync (ctx, index_hint); 858 857 if (rc != 0) 859 - { 860 - unlock_realpath (ctx); 861 - return rc; 862 - } 858 + goto sync_cleanup; 863 859 864 860 rc = execute_command (ctx, ci->close, _("Compressing %s")); 865 861 if (rc == 0) 866 862 { 867 - unlock_realpath (ctx); 868 - return -1; 863 + rc = -1; 864 + goto sync_cleanup; 869 865 } 870 866 867 + rc = 0; 868 + 869 + sync_cleanup: 871 870 store_size (ctx); 872 - 873 871 unlock_realpath (ctx); 874 - 875 - return 0; 872 + return rc; 876 873 } 877 874 878 875 /**