From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.bugs Subject: Re: backup-buffer-copy loops if old backup can't be deleted Date: Fri, 24 Aug 2007 11:10:35 +0200 Message-ID: <46CEA08B.6080907@gmx.at> References: <46CAD810.3050904@gmx.net> <46CE8501.9040307@gmx.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070806090509010900050707" X-Trace: sea.gmane.org 1187947255 19580 80.91.229.12 (24 Aug 2007 09:20:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 24 Aug 2007 09:20:55 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org, rms@gnu.org To: Martin von Gagern Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Aug 24 11:20:53 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 1IOVLT-0003aK-EM for geb-bug-gnu-emacs@m.gmane.org; Fri, 24 Aug 2007 11:20:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IOVLS-0005x0-M8 for geb-bug-gnu-emacs@m.gmane.org; Fri, 24 Aug 2007 05:20:46 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IOVHg-00037I-Mt for bug-gnu-emacs@gnu.org; Fri, 24 Aug 2007 05:16:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IOVHd-00033o-QD for bug-gnu-emacs@gnu.org; Fri, 24 Aug 2007 05:16:51 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IOVHd-00033S-DD for bug-gnu-emacs@gnu.org; Fri, 24 Aug 2007 05:16:49 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1IOVHb-0002p9-Vz for bug-gnu-emacs@gnu.org; Fri, 24 Aug 2007 05:16:49 -0400 Original-Received: (qmail invoked by alias); 24 Aug 2007 09:16:42 -0000 Original-Received: from N874P025.adsl.highway.telekom.at (EHLO [62.47.53.57]) [62.47.53.57] by mail.gmx.net (mp050) with SMTP; 24 Aug 2007 11:16:42 +0200 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX18iARFLoUUijdopdbh9yMVKq6Yies34eSNEOZgDYz EshyCVb07MtVI/ User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en In-Reply-To: <46CE8501.9040307@gmx.net> X-Y-GMX-Trusted: 0 X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) 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:16435 Archived-At: This is a multi-part message in MIME format. --------------070806090509010900050707 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit >>I think there is no need to explicitly check whether the directory >>is writable. What would be the purpose of that? > > > I didn't write that patch, but I guess there could be a purpose for it. > Namely it could help deleting a file in vain. If there are Filesystems > that let you delete a writable file even though you can't create new > ones in a non-writable dir, then without those lines, emacs would delete > an old backup only to find out that it can't create a new one. > > Most likely these would be cases where the old backup file was writable, > so if you had some logic to write to existing files and only delete them > if they are not writable, then the check whether the directory is > writable should really be superfluous. Otherwise I'm not so sure. Wouldn't it be simpler to try something like the attached patch. --------------070806090509010900050707 Content-Type: text/plain; name="files.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="files.patch" *** files.el Fri Aug 24 07:28:20 2007 --- files.el Fri Aug 24 11:04:42 2007 *************** *** 3172,3198 **** (file-error nil)))))) (defun backup-buffer-copy (from-name to-name modes) ! (let ((umask (default-file-modes)) ! (dir (or (file-name-directory to-name) ! default-directory))) (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 ! (and (file-exists-p to-name) ! (delete-file to-name)) ! (copy-file from-name to-name nil t) ! nil) ! (file-already-exists t)) ! ;; The file was somehow created by someone else between ! ;; `delete-file' and `copy-file', so let's try again. ! ;; rms says "I think there is also a possible race ! ;; condition for making backup files" (emacs-devel 20070821). ! nil)) ;; Reset the umask. (set-default-file-modes umask))) (and modes --- 3172,3200 ---- (file-error nil)))))) (defun backup-buffer-copy (from-name to-name modes) ! (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) ! (when (condition-case nil ! ;; Try to overwrite old backup first. ! (copy-file from-name to-name t t) ! (file-error t)) ! (while (condition-case nil ! (progn ! (when (file-exists-p to-name) ! (delete-file to-name)) ! (copy-file from-name to-name nil t) ! nil) ! (file-already-exists t)) ! ;; The file was somehow created by someone else between ! ;; `delete-file' and `copy-file', so let's try again. ! ;; rms says "I think there is also a possible race ! ;; condition for making backup files" (emacs-devel 20070821). ! nil))) ;; Reset the umask. (set-default-file-modes umask))) (and modes --------------070806090509010900050707 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ bug-gnu-emacs mailing list bug-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs --------------070806090509010900050707--