aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2025-12-18 02:10:46 +0100
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2025-12-18 02:10:46 +0100
commit714875f3c0c22ed01a8e777755b281c97f2b52b8 (patch)
tree34583103ed487fd4e8695f49c66e9f6e663f6d50 /src
parentdeed71ac895451041359d7b18e58eca0a0972bc3 (diff)
fixup: must not use teco_view_save_to_file() when creating backup/recovery filesHEADmaster-fmsbw-cimaster
* It emits undo tokens which would bring internal datastructures - especially the undo stack - out of sync. * We now document that teco_view_save_to_channel() will always be without undo token emission.
Diffstat (limited to 'src')
-rw-r--r--src/ring.c17
-rw-r--r--src/view.c7
2 files changed, 23 insertions, 1 deletions
diff --git a/src/ring.c b/src/ring.c
index e42ff14..afd6b25 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -334,11 +334,26 @@ teco_ring_backup(void)
continue;
g_autofree gchar *filename_backup = teco_buffer_get_backup(buffer);
+
+ g_autoptr(GIOChannel) channel = g_io_channel_new_file(filename_backup, "w", NULL);
+ if (!channel)
+ continue;
+
/*
+ * teco_view_save_to_channel() expects a buffered and blocking channel.
+ */
+ g_io_channel_set_encoding(channel, NULL, NULL);
+ g_io_channel_set_buffered(channel, TRUE);
+
+ /*
+ * This does not use teco_view_save_to_file() since we must not
+ * emit undo tokens.
+ *
* FIXME: Errors are silently ignored.
* Should we log warnings instead?
*/
- teco_view_save(buffer->view, filename_backup, NULL);
+ if (!teco_view_save_to_channel(buffer->view, channel, NULL))
+ continue;
buffer->state = TECO_BUFFER_DIRTY_BACKEDUP;
}
diff --git a/src/view.c b/src/view.c
index eeb4d3d..d5b5d14 100644
--- a/src/view.c
+++ b/src/view.c
@@ -508,6 +508,13 @@ teco_undo_remove_file_push(const gchar *filename)
strcpy(ctx, filename);
}
+/**
+ * Save the view's document to the given IO channel.
+ *
+ * @note This must not emit undo tokens as it is also used by teco_ring_backup().
+ *
+ * @memberof teco_view_t
+ */
gboolean
teco_view_save_to_channel(teco_view_t *ctx, GIOChannel *channel, GError **error)
{