diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-12-28 21:22:46 +0100 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-12-28 21:22:46 +0100 |
| commit | 0b593eb7d0e6907b19cdbb605caf1becae351004 (patch) | |
| tree | adb88b74827b597880b5655444d041bae917ea85 | |
| parent | ea0a23645f03a42252ab1ce8df45ae4076ebae75 (diff) | |
fixed left-over recovery files
* It was possible to provoke left-over recovery files even if the editor does *not* crash:
1. If you dirtified the buffer (state = TECO_BUFFER_DIRTY), it would be dumped to a
recovery file (TECO_BUFFER_DIRTY_DUMPED).
2. If you dirtify the buffer again, the state will become TECO_BUFFER_DIRTY again,
so it's up for dumping in the next cycle.
3. If you now save and exit (e.g. `:EX`) the recovery file is not deleted since
the state is not TECO_BUFFER_DIRTY_DUMPED.
* A buffer can have a recovery file both for TECO_BUFFER_DIRTY and TECO_BUFFER_DIRTY_DUMPED,
so we must clean up afterwards in both states.
* Of course, it may __not__ yet have a recovery file in the TECO_BUFFER_DIRTY state.
The g_unlink() might therefore be superfluous on those files.
Moreover, if you disable recovery files, SciTECO will now still try to unlink the
recovery file.
These operations could only be avoided by adding yet another state, e.g.
TECO_BUFFER_DIRTY_OUTDATED_DUMP, so that after the first dump you will never switch
back into TECO_BUFFER_DIRTY.
| -rw-r--r-- | src/ring.c | 6 | ||||
| -rw-r--r-- | src/ring.h | 3 |
2 files changed, 5 insertions, 4 deletions
@@ -118,7 +118,7 @@ teco_buffer_save(teco_buffer_t *ctx, const gchar *filename, GError **error) */ if (ctx == teco_ring_current && !teco_qreg_current) undo__teco_interface_info_update_buffer(ctx); - if (ctx->state == TECO_BUFFER_DIRTY_DUMPED) { + if (ctx->state >= TECO_BUFFER_DIRTY) { g_autofree gchar *filename_recovery = teco_buffer_get_recovery(ctx); g_unlink(filename_recovery); /* on rubout, we do not restore the recovery file */ @@ -143,7 +143,7 @@ teco_buffer_save(teco_buffer_t *ctx, const gchar *filename, GError **error) static inline void teco_buffer_free(teco_buffer_t *ctx) { - if (ctx->state == TECO_BUFFER_DIRTY_DUMPED) { + if (ctx->state >= TECO_BUFFER_DIRTY) { g_autofree gchar *filename_recovery = teco_buffer_get_recovery(ctx); g_unlink(filename_recovery); } @@ -244,7 +244,7 @@ teco_ring_find_by_id(teco_int_t id) static void teco_ring_undirtify(void) { - if (teco_ring_current->state == TECO_BUFFER_DIRTY_DUMPED) { + if (teco_ring_current->state >= TECO_BUFFER_DIRTY) { g_autofree gchar *filename_recovery = teco_buffer_get_recovery(teco_ring_current); g_unlink(filename_recovery); } @@ -26,8 +26,9 @@ #include "list.h" typedef enum { + /** buffer is freshly opened or saved */ TECO_BUFFER_CLEAN = 0, - /** buffer modified */ + /** buffer modified - if a recovery file already exists, it is outdated */ TECO_BUFFER_DIRTY, /** buffer modified and recovery file already written */ TECO_BUFFER_DIRTY_DUMPED |
