From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7285 invoked from network); 17 Oct 2004 19:50:00 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 17 Oct 2004 19:50:00 -0000 Received: (qmail 53776 invoked from network); 17 Oct 2004 19:49:50 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Oct 2004 19:49:50 -0000 Received: (qmail 8544 invoked by alias); 17 Oct 2004 19:49:46 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 20495 Received: (qmail 8526 invoked from network); 17 Oct 2004 19:49:45 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 17 Oct 2004 19:49:45 -0000 Received: (qmail 53279 invoked from network); 17 Oct 2004 19:48:46 -0000 Received: from dsl3-63-249-88-2.cruzio.com (HELO binome.blorf.net) (63.249.88.2) by a.mx.sunsite.dk with SMTP; 17 Oct 2004 19:48:44 -0000 Received: by binome.blorf.net (Postfix, from userid 1000) id 7359E49C2; Sun, 17 Oct 2004 12:48:42 -0700 (PDT) Date: Sun, 17 Oct 2004 12:48:42 -0700 From: Wayne Davison To: zsh-workers@sunsite.dk Subject: Re: skip rewriting history if exiting due to signal Message-ID: <20041017194842.GA26158@blorf.net> References: <20041001193658.GD26529@blorf.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Dxnq1zWXvFF0Q93v" Content-Disposition: inline In-Reply-To: <20041001193658.GD26529@blorf.net> User-Agent: Mutt/1.5.6+20040722i X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 --Dxnq1zWXvFF0Q93v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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.. --Dxnq1zWXvFF0Q93v Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="hist.patch" --- 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))) { --Dxnq1zWXvFF0Q93v--