diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-11-02 06:18:40 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-11-02 06:18:40 -0700 |
commit | a836c24de4d2488c4740c1143f252bc086a5ffbe (patch) | |
tree | d078a14acd4236619c2a53d16f1ff8153ee5d62c /parser.c | |
parent | 1cf6c607eb35525d2329651e1d75f21b3a8e82b2 (diff) | |
download | txr-a836c24de4d2488c4740c1143f252bc086a5ffbe.tar.gz txr-a836c24de4d2488c4740c1143f252bc086a5ffbe.tar.bz2 txr-a836c24de4d2488c4740c1143f252bc086a5ffbe.zip |
listener: use temp file when saving history.
We don't want ot overwrite the history file in-place; if
something goes wrong, we will lose half of it.
* parser.c (repl): Save the history to a .tmp file, and
then rename that to the target name, if the write is
successful.
Diffstat (limited to 'parser.c')
-rw-r--r-- | parser.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -1376,8 +1376,14 @@ val repl(val bindings, val in_stream, val out_stream) dyn_env = saved_dyn_env; - if (histfile_w) - lino_hist_save(ls, histfile_w); + if (histfile_w) { + val histfile_tmp = format(nil, lit("~a/.txr_history.tmp"), home, nao); + if (lino_hist_save(ls, c_str(histfile_tmp)) == 0) + rename_path(histfile_tmp, histfile); + else + put_line(lit("** unable to save history file"), out_stream); + gc_hint(histfile_tmp); + } free(line_w); lino_free(ls); |