From df33e1f12ebeca196a7c88989df6205a78c3a624 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 13 Nov 2016 20:02:35 -0800 Subject: [PATCH] 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. --- compress.c | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/compress.c b/compress.c index b7fb06ed..8ef4525e 100644 --- a/compress.c +++ b/compress.c @@ -646,30 +646,27 @@ check_mailbox (CONTEXT *ctx, int *index_hint) if (!ci) return -1; + struct mx_ops *ops = ci->child_ops; + if (!ops) + return -1; + int size = get_size (ctx->realpath); if (size == ci->size) return 0; - /* TODO: this is a copout. We should reopen the compressed mailbox - * and call mutt_reopen_mailbox. */ - if (ctx->changed) + if (!lock_realpath (ctx, 0)) { - mutt_free_compress_info (ctx); - mx_fastclose_mailbox (ctx); - mutt_error (_("Mailbox was corrupted!")); + mutt_error (_("Unable to lock mailbox!")); return -1; } - /* TODO: this block leaks memory. this is doing it all wrong */ - close_mailbox (ctx); - - const char *path = ctx->path; - ctx->path = NULL; - - mx_open_mailbox (path, 0, ctx); - FREE(&path); + int rc = execute_command (ctx, ci->open, _("Decompressing %s")); + store_size (ctx); + unlock_realpath (ctx); + if (rc == 0) + return -1; - return MUTT_REOPENED; + return ops->check (ctx, index_hint); } @@ -852,27 +849,27 @@ sync_mailbox (CONTEXT *ctx, int *index_hint) return -1; } - /* TODO: check if mailbox changed first! */ + int rc = check_mailbox (ctx, index_hint); + if (rc != 0) + goto sync_cleanup; - int rc = ops->sync (ctx, index_hint); + rc = ops->sync (ctx, index_hint); if (rc != 0) - { - unlock_realpath (ctx); - return rc; - } + goto sync_cleanup; rc = execute_command (ctx, ci->close, _("Compressing %s")); if (rc == 0) { - unlock_realpath (ctx); - return -1; + rc = -1; + goto sync_cleanup; } - store_size (ctx); + rc = 0; +sync_cleanup: + store_size (ctx); unlock_realpath (ctx); - - return 0; + return rc; } /** -- 2.40.0