Subject: Re: file-precious-flag overwrites symlinks

From: Max Mikhanosha <[email-masked]>
Date: Fri, 01 Aug 2008 01:04:07 -0400

After playing with it for a little bit, I found that the additional
condition is to have ~/.emacs opened in the buffer, it does not matter
if its modified or not.

So updated steps to reproduce the problem are:

1. Setup ~/.emacs being symlink to real file
2. M-x set-variable backup-by-copying-when-linked to t (this step is not nessesary to reproduce, just to show that his does not fix it)
3. Make sure sure ~/.emacs is not opened in any buffer, customize a variable, and do "Save for future sessions"
4. It saves changes to where file is pointing
5. Now do C-x C-f ~/.emacs
6. Customize variable again, do "Save for future sessions", it now overwrites ~/.emacs link with real file

I can reproduce this with 22.2.1 and with latest emacs from CVS.

Regards,
  Max

At Wed, 30 Jul 2008 18:56:16 -0400,
Chong Yidong wrote:
> 
> > I keep my .emacs file under version control as part of overall
> > collection of config files, and as result ~/.emacs is a symbolic
> > link.
> >
> > `backup-by-copying-when-linked' is set to t, so visiting ~/.emacs
> > and then editing and saving it correctly saves the file that
> > symlink is pointing too.
> >
> > For a long time I was trying to track down why sometimes, my ~/.emacs
> > symbolic link is suddenly overwritten by the actual file.
> >
> > Finally found that this happens when one uses "Save for future
> > session" in customize package, and farther tracked it down to a
> > behavior of `basic-save-buffer-2' when file-precious-flag is set.
> 
> Setting file-precious-flag to t in custom-save-all shouldn't be a
> problem, because the custom file is visited using
> find-file-visit-truename.  I tried to reproduce your problem, without
> success:
> 
> $ touch foo
> $ ln -s foo .emacs
> $ emacs
>   M-x customize-variable RET sentence-end-double-space RET
>   [Click on Toggle]
>   C-x C-s
>   C-x C-c
> $ ls -l foo .emacs
> 
> lrwxrwxrwx 1 cyd cyd   3 2008-07-30 18:54 .emacs -> foo
> -rw-r--r-- 1 cyd cyd 528 2008-07-30 18:55 foo
> 
> Could you provide a recipe that shows this problem?