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

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

Re: Quitting `save-buffer' loses backup file


From: Sven Joachim
Subject: Re: Quitting `save-buffer' loses backup file
Date: Fri, 30 Dec 2005 17:04:39 +0100
User-agent: Mozilla Thunderbird 1.0.7 (X11/20051017)

I wrote:

Here is a summary of what Emacs does in the scenario:

(a) Before saving bar, Emacs renames bar to bar~, overwriting the old
    backup in the process, and sets `buffer-backed-up' to t.  This is
    documented in the manual.

(b) Emacs tries to save bar but fails to do so, because the user quits.
    To reduce harm, Emacs renames bar~ back to bar.  But -- and this is
    probably wrong -- Emacs does not set `buffer-backed-up' back to nil.

Actually, (b) is coded and documented in the function
basic-save-buffer-2, near the end:

,----
|           ;; If we get an error writing the new file, and we made
|           ;; the backup by renaming, undo the backing-up.
|           (and setmodes (not success)
|                (rename-file (cdr setmodes) buffer-file-name))))))
`----

What do you think of the following patch which sets `buffer-backed-up'
back to nil here?

*** files.el~   2005-12-16 16:41:21.000000000 +0100
--- files.el    2005-12-30 16:36:26.000000000 +0100
***************
*** 3468,3474 ****
            ;; If we get an error writing the new file, and we made
            ;; the backup by renaming, undo the backing-up.
            (and setmodes (not success)
!                (rename-file (cdr setmodes) buffer-file-name))))))
      setmodes))

  (defun diff-buffer-with-file (&optional buffer)
--- 3468,3476 ----
            ;; If we get an error writing the new file, and we made
            ;; the backup by renaming, undo the backing-up.
            (and setmodes (not success)
!                (progn
!                  (rename-file (cdr setmodes) buffer-file-name)
!                  (setq buffer-backed-up nil)))))))
      setmodes))

  (defun diff-buffer-with-file (&optional buffer)


By the way, there is another possibility of an error here.  The file
may be written incompletely due to insufficient disk space.  In this
case, the renaming of the backup back to the original fails, but I
think it shouldn't.  So here is a better patch:

*** files.el~   2005-12-16 16:41:21.000000000 +0100
--- files.el    2005-12-30 16:57:39.000000000 +0100
***************
*** 3468,3474 ****
            ;; If we get an error writing the new file, and we made
            ;; the backup by renaming, undo the backing-up.
            (and setmodes (not success)
!                (rename-file (cdr setmodes) buffer-file-name))))))
      setmodes))

  (defun diff-buffer-with-file (&optional buffer)
--- 3468,3476 ----
            ;; If we get an error writing the new file, and we made
            ;; the backup by renaming, undo the backing-up.
            (and setmodes (not success)
!                (progn
!                  (rename-file (cdr setmodes) buffer-file-name t)
!                  (setq buffer-backed-up nil)))))))
      setmodes))

  (defun diff-buffer-with-file (&optional buffer)


Regards,

Sven









reply via email to

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