[gnu.emacs.bug] bug in saving files with file-precious-flag==t

steiner@TOPAZ.RUTGERS.EDU (Dave Steiner) (10/11/88)

In GNU Emacs 18.51.22 of Wed Aug 10 1988 on topaz.rutgers.edu (berkeley-unix)

There's a bug when using the file-precious-flag.  If you edit a file
that's actually a link to another file:

	bar
	foo@ -> bar
	xxx@ -> bar

You will get the file (bar) changed, the link is still there (xxx) and
the backup file is for the link you just edited (xxx~), like this:

	% emacs xxx	(file-precious-flag==nil)
=>
	bar	
	foo@ -> bar
	xxx@ -> bar
	xxx~

So far so good, but if you change the file-precious-flag to be true
you get a different behaviour:

	% emacs foo	(file-precious-flag==t)
=>
	bar
	foo
	foo~
	xxx@ -> bar
	xxx~

The file has not changed (bar), the backup file (foo~) is the same as
bar, and foo is no longer a link but the edited file.  The following
patch to files.el fixes the problem.  (The Powers That Be: please let
me know if this is a reasonable fix; I'd like to install this since we
get bit by this a lot but I don't want to make a change like this and
then do something different down the line.  Thanks)

ds

*** files.el.BAK	Tue May 17 18:28:04 1988
--- files.el	Mon Oct 10 19:12:55 1988
***************
*** 696,702
  		       (let ((rename t)
  			     (file (concat buffer-file-name "~")))
  			 (condition-case ()
! 			     (progn (rename-file buffer-file-name file t)
  				    (setq setmodes (file-modes file)))
  			   (file-error (setq rename nil)))
  			 (unwind-protect

--- 696,704 -----
  		       (let ((rename t)
  			     (file (concat buffer-file-name "~")))
  			 (condition-case ()
! 			     (progn (if (file-symlink-p buffer-file-name)
! 					(copy-file buffer-file-name file t t)
! 				      (rename-file buffer-file-name file t))
  				    (setq setmodes (file-modes file)))
  			   (file-error (setq rename nil)))
  			 (unwind-protect