]> granicus.if.org Git - neomutt/commitdiff
Compress: fix check_mailbox and sync_mailbox.
authorKevin McCarthy <kevin@8t8.us>
Mon, 14 Nov 2016 04:02:35 +0000 (20:02 -0800)
committerKevin McCarthy <kevin@8t8.us>
Mon, 14 Nov 2016 04:02:35 +0000 (20:02 -0800)
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

index b7fb06eda86da6ca0b1a1578c2aaf4d19ee6e43f..8ef4525e66d76ca5590bec3c8866e973878296e2 100644 (file)
@@ -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;
 }
 
 /**