Skip to content

Commit

Permalink
fixed rubbing out file open with glob patterns
Browse files Browse the repository at this point in the history
* This would crash if <EB> opened more than one file, e.g. EB*.c$.
  The reason is that teco_current_doc_undo_edit() must be called before every teco_ring_edit().
* Unfortunately, this is not reproduceable with
  sciteco --no-profile --fake-cmdline '@eb"foo*.txt"{HK}'
  since the crashes actually happen when printing messages in interactive mode.
  That's why no test case has been added.
  • Loading branch information
rhaberkorn committed Dec 8, 2024
1 parent bd87ff4 commit 3f6572c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,23 +441,22 @@ teco_state_edit_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GE
return &teco_state_start;
}

if (!teco_current_doc_undo_edit(error))
return NULL;

g_autofree gchar *filename = teco_file_expand_path(str->data);
if (teco_globber_is_pattern(filename)) {
g_auto(teco_globber_t) globber;
teco_globber_init(&globber, filename, G_FILE_TEST_IS_REGULAR);

gchar *globbed_filename;
while ((globbed_filename = teco_globber_next(&globber))) {
gboolean rc = teco_ring_edit(globbed_filename, error);
gboolean rc = teco_current_doc_undo_edit(error) &&
teco_ring_edit(globbed_filename, error);
g_free(globbed_filename);
if (!rc)
return NULL;
}
} else {
if (!teco_ring_edit_by_name(*filename ? filename : NULL, error))
if (!teco_current_doc_undo_edit(error) ||
!teco_ring_edit_by_name(*filename ? filename : NULL, error))
return NULL;
}

Expand Down

0 comments on commit 3f6572c

Please sign in to comment.