From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ulrich Mueller Newsgroups: gmane.emacs.bugs Subject: Re: backup-buffer-copy loops if old backup can't be deleted Date: Wed, 22 Aug 2007 11:51:52 +0200 Message-ID: <18124.1848.964776.264332@a1ihome1.kph.uni-mainz.de> References: <46CAD810.3050904@gmx.net> <46CAF8AC.9070809@gmx.at> <46CAFBEF.2040606@gmx.net> <46CB529F.7010008@gmx.at> <46CB6586.9050005@gmx.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1187776335 7411 80.91.229.12 (22 Aug 2007 09:52:15 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 22 Aug 2007 09:52:15 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org To: Martin von Gagern Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Aug 22 11:52:14 2007 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1INmsl-00078S-Tv for geb-bug-gnu-emacs@m.gmane.org; Wed, 22 Aug 2007 11:52:12 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1INmsk-0002iL-Fk for geb-bug-gnu-emacs@m.gmane.org; Wed, 22 Aug 2007 05:52:11 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1INmse-0002gm-PB for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2007 05:52:05 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1INmsd-0002gT-Tf for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2007 05:52:04 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1INmsd-0002g6-5m for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2007 05:52:03 -0400 Original-Received: from mail.kph.uni-mainz.de ([134.93.132.3]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1INmsZ-0007Qo-KD; Wed, 22 Aug 2007 05:52:00 -0400 Original-Received: from a1ihome1.kph.uni-mainz.de (a1ihome1.kph.uni-mainz.de [134.93.134.75]) by mail.kph.uni-mainz.de (8.12.9p2/8.12.9) with ESMTP id l7M9pr0E028902; Wed, 22 Aug 2007 11:51:53 +0200 (CEST) (envelope-from ulm@kph.uni-mainz.de) Original-Received: from a1ihome1.kph.uni-mainz.de (localhost [127.0.0.1]) by a1ihome1.kph.uni-mainz.de (8.13.8/8.13.4) with ESMTP id l7M9pr7M012590; Wed, 22 Aug 2007 11:51:53 +0200 Original-Received: (from ulm@localhost) by a1ihome1.kph.uni-mainz.de (8.14.1/8.14.1/Submit) id l7M9pr67012584; Wed, 22 Aug 2007 11:51:53 +0200 In-Reply-To: <46CB6586.9050005@gmx.net> X-Mailer: VM 8.0.1-465 under Emacs 22.1.1 (i686-pc-linux-gnu) X-Detected-Kernel: FreeBSD 4.6-4.9 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:16420 Archived-At: >>>>> On Wed, 22 Aug 2007, Martin von Gagern wrote: > I can think of at least two scenarios where this could be a problem: > 1. The dir is not writable, but the backup file is. Here the current > behaviour will loop and even with the suggested fix it will fall > back to ~/%backup%~ unnecessarily. > [...] > I originally assumed that emacs would try backup-buffer-copy only > after figuring out that it could not write to the existing backup > file, but it seems I was wrong there, at least if I read > backup-buffer correctly. It seems that your assumption is the intended behaviour. At least the problem was noticed and a fix was installed in March 2005: However, it no longer works due to the introduction of the loop in backup-buffer-copy one month later (this change was in CVS revision 1.757 of files.el). The relevant part is: (defun backup-buffer-copy (from-name to-name modes) - (condition-case () - (copy-file from-name to-name t t) - (file-error - ;; If copying fails because file TO-NAME - ;; is not writable, delete that file and try again. - (if (and (file-exists-p to-name) - (not (file-writable-p to-name))) - (delete-file to-name)) - (copy-file from-name to-name t t))) + (let ((umask (default-file-modes))) + (unwind-protect + (progn + ;; Create temp files with strict access rights. It's easy to + ;; loosen them later, whereas it's impossible to close the + ;; time-window of loose permissions otherwise. + (set-default-file-modes ?\700) + (while (condition-case () + (progn + (condition-case nil + (delete-file to-name) + (file-error nil)) + (write-region "" nil to-name nil 'silent nil 'excl) + nil) + (file-already-exists t)) + ;; the file was somehow created by someone else between + ;; `make-temp-name' and `write-region', let's try again. + nil) + (copy-file from-name to-name t t 'excl)) + ;; Reset the umask. + (set-default-file-modes umask))) (and modes (set-file-modes to-name (logand modes #o1777)))) with the following ChangeLog entry: 2005-04-23 Richard M. Stallman * files.el [...] (backup-buffer-copy, basic-save-buffer-2): Take care against writing thru an unexpected existing symlink. [...] There should be easier ways to achieve protection against writing through symlinks. Ulrich