bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: backup-buffer-copy loops if old backup can't be deleted


From: Glenn Morris
Subject: Re: backup-buffer-copy loops if old backup can't be deleted
Date: Tue, 21 Aug 2007 17:50:59 -0400
User-agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/)

martin rudalics wrote:

> Why can't we use
>
> (copy-file from-name to-name t t)
>
> here as in Emacs 21?  What was the rationale for this loop?

I know no more than it says in the comment. rms added the loop
20050423, copied from make-temp-file I think. I think looping makes
more sense in that context, not sure it makes any sense in this
context. I'll ask on emacs-devel. But if what it says in the existing
comment is possible, then I guess we would actually need something
like this:


*** files.el    8 Aug 2007 14:06:01 -0000       1.896.2.15
--- files.el    21 Aug 2007 21:26:02 -0000
***************
*** 3120,3126 ****
            (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
--- 3120,3131 ----
            (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)))
!     ;; Can't delete or create files in a read-only directory.
!     (unless (file-writable-p dir)
!       (signal 'file-error (list "Directory is not writable" dir)))
      (unwind-protect
        (progn
          ;; Create temp files with strict access rights.  It's easy to
***************
*** 3129,3134 ****
--- 3134,3144 ----
          (set-default-file-modes ?\700)
          (while (condition-case ()
                     (progn
+                        ;; If we allow for the possibility of something
+                        ;; creating the file between delete and copy
+                        ;; (below), we must also allow for the
+                        ;; possibility of something deleting it between
+                        ;; a file-exists-p check and a delete.
                         (condition-case nil
                           (delete-file to-name)
                           (file-error nil))
***************
*** 3137,3142 ****
--- 3147,3154 ----
                   (file-already-exists t))
            ;; The file was somehow created by someone else between
            ;; `delete-file' and `copy-file', so let's try again.
+           ;; FIXME does that every actually happen in practice?
+           ;; This is a potential infloop, which seems bad...
            nil))
        ;; Reset the umask.
        (set-default-file-modes umask)))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]