From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: save-buffer: avoid data loss on interrupt Date: Tue, 13 Dec 2011 12:03:23 -0800 Organization: UCLA Computer Science Department Message-ID: <4EE7AF8B.2090303@cs.ucla.edu> References: <87zkf282ht.fsf@rho.meyering.net> <87pqfsqtsj.fsf@rho.meyering.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1323806620 30249 80.91.229.12 (13 Dec 2011 20:03:40 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 13 Dec 2011 20:03:40 +0000 (UTC) Cc: Emacs development discussions To: Jim Meyering Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 13 21:03:36 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RaYZb-0007r2-Ho for ged-emacs-devel@m.gmane.org; Tue, 13 Dec 2011 21:03:35 +0100 Original-Received: from localhost ([::1]:40638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaYZa-0000Ky-JX for ged-emacs-devel@m.gmane.org; Tue, 13 Dec 2011 15:03:34 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:59893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaYZX-0000Kp-Hd for emacs-devel@gnu.org; Tue, 13 Dec 2011 15:03:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaYZW-0007xm-Eb for emacs-devel@gnu.org; Tue, 13 Dec 2011 15:03:31 -0500 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:42404) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaYZW-0007xg-3m for emacs-devel@gnu.org; Tue, 13 Dec 2011 15:03:30 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 0115639E800B; Tue, 13 Dec 2011 12:03:25 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gPwAoacCHEfD; Tue, 13 Dec 2011 12:03:24 -0800 (PST) Original-Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id BB09539E8006; Tue, 13 Dec 2011 12:03:23 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111115 Thunderbird/8.0 In-Reply-To: <87pqfsqtsj.fsf@rho.meyering.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:146695 Archived-At: On 12/13/11 09:13, Jim Meyering wrote: > - (if (or (and file-precious-flag dir-writable) > + (if (or (and dir-writable > + (or file-precious-flag > + (= (file-nlinks buffer-file-name) 1))) I like the general idea, but this solution seems a bit aggressive, as it will cause the file's ownership to change if the file's link count is 1, and often that isn't what is wanted. Instead, how about extending the semantics of break-hardlink-on-save, with something like the following (untested) patch? --- lisp/files.el 2011-12-04 08:02:42 +0000 +++ lisp/files.el 2011-12-13 19:46:33 +0000 @@ -4469,8 +4469,11 @@ Before and after saving the buffer, this (dir-writable (file-writable-p dir))) (if (or (and file-precious-flag dir-writable) (and break-hardlink-on-save - (file-exists-p buffer-file-name) - (> (file-nlinks buffer-file-name) 1) + (let ((nlinks (file-nlinks buffer-file-name))) + (and nlinks + (> nlinks (if (numberp break-hardlink-on-save) + break-hardlink-on-save + 1)))) (or dir-writable (error (concat (format "Directory %s write-protected; " dir) That way, you can set break-hardlink-on-save to -1 to get the behavior that you want. While we're on the subject, break-hardlink-on-save is not documented; I wonder why not? Also, the current code does not work if the directory is sticky and writable and the file is owned by someone else (a common situation in /tmp); this should get fixed too.