From: Wayne Davison <wayned@users.sourceforge.net>
To: zsh-workers@sunsite.dk
Subject: Re: skip rewriting history if exiting due to signal
Date: Sun, 17 Oct 2004 12:48:42 -0700 [thread overview]
Message-ID: <20041017194842.GA26158@blorf.net> (raw)
In-Reply-To: <20041001193658.GD26529@blorf.net>
[-- Attachment #1: Type: text/plain, Size: 969 bytes --]
On Fri, Oct 01, 2004 at 12:36:58PM -0700, Wayne Davison wrote:
> [non-appending history-file writing] will have to be improved in some
> other manner, possibly by switching over to using a *.new file to
> write out the new history lines
Here's a patch that makes the savehistfile() function use a temporary
file whenever it writes out the whole file from the start (rather than
overwriting the existing file). This could be controversial if someone
out there has a symlink for their history file (since it would get
replaced by the temp file, and thus would no longer remain a symlink).
The naming scheme I chose to use was to write out the history data using
the name $HISTFILE.$$ since this naming idiom is already used for a
temporary file name when acquiring the $HISTFILE.LOCK lock file (there's
also no conflict with that use). If folks think that $HISTFILE.new is a
better choice, it would be easy to change.
Thoughts? Is this a desired change?
..wayne..
[-- Attachment #2: hist.patch --]
[-- Type: text/plain, Size: 1220 bytes --]
--- Src/hist.c 1 Oct 2004 19:48:53 -0000 1.54
+++ Src/hist.c 17 Oct 2004 19:44:20 -0000
@@ -2005,7 +2005,7 @@ readhistfile(char *fn, int err, int read
void
savehistfile(char *fn, int err, int writeflags)
{
- char *t, *start = NULL;
+ char *t, *tmpfile, *start = NULL;
FILE *out;
Histent he;
zlong xcurhist = curhist - !!(histactive & HA_ACTIVE);
@@ -2042,11 +2042,17 @@ savehistfile(char *fn, int err, int writ
extended_history = 1;
}
if (writeflags & HFILE_APPEND) {
+ tmpfile = NULL;
out = fdopen(open(unmeta(fn),
O_CREAT | O_WRONLY | O_APPEND | O_NOCTTY, 0600), "a");
}
else {
- out = fdopen(open(unmeta(fn),
+ char *fnu = unmeta(fn);
+ int len = strlen(fnu);
+ tmpfile = zalloc(len + 10 + 1);
+ sprintf(tmpfile, "%s.%ld", fnu, (long)mypid);
+ unlink(tmpfile);
+ out = fdopen(open(tmpfile,
O_CREAT | O_WRONLY | O_TRUNC | O_NOCTTY, 0600), "w");
}
if (out) {
@@ -2092,6 +2098,10 @@ savehistfile(char *fn, int err, int writ
lasthist.text = ztrdup(start);
}
fclose(out);
+ if (tmpfile) {
+ rename(tmpfile, unmeta(fn));
+ free(tmpfile);
+ }
if (writeflags & HFILE_SKIPOLD
&& !(writeflags & (HFILE_FAST | HFILE_NO_REWRITE))) {
next prev parent reply other threads:[~2004-10-17 19:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-01 19:36 Wayne Davison
2004-10-17 19:48 ` Wayne Davison [this message]
2004-10-18 0:21 ` Bart Schaefer
2004-10-18 5:00 ` Wayne Davison
2004-10-18 19:36 ` Improved HISTFILE locking Wayne Davison
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20041017194842.GA26158@blorf.net \
--to=wayned@users.sourceforge.net \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).