unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Martin von Gagern <Martin.vGagern@gmx.net>
Cc: bug-gnu-emacs@gnu.org, rms@gnu.org
Subject: Re: backup-buffer-copy loops if old backup can't be deleted
Date: Fri, 24 Aug 2007 11:10:35 +0200	[thread overview]
Message-ID: <46CEA08B.6080907@gmx.at> (raw)
In-Reply-To: <46CE8501.9040307@gmx.net>

[-- Attachment #1: Type: text/plain, Size: 840 bytes --]

>>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.


[-- Attachment #2: files.patch --]
[-- Type: text/plain, Size: 2219 bytes --]

*** 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

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

_______________________________________________
bug-gnu-emacs mailing list
bug-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs

  reply	other threads:[~2007-08-24  9:10 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.5018.1187641790.32220.bug-gnu-emacs@gnu.org>
2007-08-20 22:01 ` backup-buffer-copy loops if old backup can't be deleted Martin von Gagern
     [not found] ` <mailman.5021.1187647310.32220.bug-gnu-emacs@gnu.org>
2007-08-21 12:18   ` Martin von Gagern
2007-08-21 14:37     ` martin rudalics
2007-08-21 14:51       ` Martin von Gagern
2007-08-21 15:28         ` martin rudalics
2007-08-21 19:35         ` Glenn Morris
2007-08-21 21:01           ` martin rudalics
2007-08-21 21:50             ` Glenn Morris
2007-08-22  9:13               ` Martin von Gagern
2007-08-22  9:44                 ` martin rudalics
2007-08-22  9:48                   ` Martin von Gagern
2007-08-22 12:40                     ` martin rudalics
2007-08-22 21:37                     ` Michael Schierl
2007-08-21 22:21             ` Martin von Gagern
2007-08-22  9:51               ` Ulrich Mueller
2007-08-23 20:59     ` Richard Stallman
2007-08-24  7:13       ` Martin von Gagern
2007-08-24  9:10         ` martin rudalics [this message]
2007-08-25  4:07           ` Richard Stallman
2007-08-25  4:07         ` Richard Stallman
     [not found]     ` <mailman.5219.1187902794.32220.bug-gnu-emacs@gnu.org>
2007-08-24  6:11       ` Ulrich Mueller
2007-08-20 19:58 Martin von Gagern
2007-08-21  6:50 ` martin rudalics

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46CEA08B.6080907@gmx.at \
    --to=rudalics@gmx.at \
    --cc=Martin.vGagern@gmx.net \
    --cc=bug-gnu-emacs@gnu.org \
    --cc=rms@gnu.org \
    /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.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).