summaryrefslogtreecommitdiffstats
path: root/compress.c
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2016-11-13 20:02:35 -0800
committerKevin McCarthy <kevin@8t8.us>2016-11-13 20:02:35 -0800
commitd3705ea8b23de24a63a4b659ead18a0cf6fb756a (patch)
tree3d506dfe6056d7c085402c2b848a1fc0862120b5 /compress.c
parentf46e648f568c38b57ada874cea87e561e3a235c7 (diff)
Create mx_ops.sync operation. Refactor compress to use the mx_ops.sync.
Change compress.sync_mailbox() to lock the compressed mailbox around both the tempfile sync and compress operations. This will prevent changes made inbetween the two syncs from being overwritten. Thanks to Damien Riegel for his original patch refactoring mx_ops.sync, which this patch is partially based upon.
Diffstat (limited to 'compress.c')
-rw-r--r--compress.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/compress.c b/compress.c
index 681fffcf..b7fb06ed 100644
--- a/compress.c
+++ b/compress.c
@@ -816,18 +816,18 @@ mutt_comp_can_read (const char *path)
}
/**
- * mutt_comp_sync - Save changes to the compressed mailbox file
+ * sync_mailbox - Save changes to the compressed mailbox file
* @ctx: Mailbox to sync
*
- * Changes in Mutt only affect the tmp file. Calling mutt_comp_sync()
+ * Changes in Mutt only affect the tmp file. Calling sync_mailbox()
* will commit them to the compressed file.
*
* Returns:
* 0: Success
* -1: Failure
*/
-int
-mutt_comp_sync (CONTEXT *ctx)
+static int
+sync_mailbox (CONTEXT *ctx, int *index_hint)
{
if (!ctx)
return -1;
@@ -842,22 +842,36 @@ mutt_comp_sync (CONTEXT *ctx)
return -1;
}
- /* TODO: need to refactor sync so we can lock around the
- * path sync as well as the compress operation */
+ struct mx_ops *ops = ci->child_ops;
+ if (!ops)
+ return -1;
+
if (!lock_realpath (ctx, 1))
{
mutt_error (_("Unable to lock mailbox!"));
return -1;
}
- int rc = execute_command (ctx, ci->close, _("Compressing %s"));
+ /* TODO: check if mailbox changed first! */
+
+ int rc = ops->sync (ctx, index_hint);
+ if (rc != 0)
+ {
+ unlock_realpath (ctx);
+ return rc;
+ }
+
+ rc = execute_command (ctx, ci->close, _("Compressing %s"));
if (rc == 0)
+ {
+ unlock_realpath (ctx);
return -1;
-
- unlock_realpath (ctx);
+ }
store_size (ctx);
+ unlock_realpath (ctx);
+
return 0;
}
@@ -894,6 +908,7 @@ struct mx_ops mx_comp_ops =
.open_append = open_append_mailbox,
.close = close_mailbox,
.check = check_mailbox,
+ .sync = sync_mailbox,
.open_msg = open_message,
.close_msg = close_message,
.commit_msg = commit_message,