[ILUG] Emacs saving files edited by root

Niall O Broin niall at magicgoeshere.com
Fri Feb 16 10:53:50 GMT 2007


On 16 Feb 2007, at 09:35, Glenn Strong wrote:

> On Friday, February 16, 2007 at 07:24 +0000, Niall O Broin wrote:
>> I have asked google, but with no great success. Last time I asked,
>> Padraig Brady pointed me to http://www.xemacs.org/Documentation/21.5/
>> html/xemacs_17.html#SEC141 but for the life of me, I can't see why (I
>> just found this now when googling, having found my old question, and
>> I followed Padraig's link)
>
> When emacs saves a file it usually puts the old file aside as a backup
> and saves a new file with the updated contents. There are two ways it
> can do this, and one will change the owner (to reflect the most recent
> user to edit the file). Redhat probably defaulted to the _other_ one.
>
> What's the value of the variable backup-by-copying on your emacs? That
> variable will control the method used. If it's non-nil then the
> copying method will be used when saving files, which should leave the
> ownership untouched.

I felt hopeful at first. But then I checked on a selection of  
emacsen, and backup-by-copying was nil on them all :-( But I'd been  
thrown a bone, and I had something more to google for, and sure  
enough, I found the answer.

There's yet another variable (in fact, there are four which have a  
hand in this) called backup-by-copying-when-mismatch. If THAT  
variable is non-nil, then copying is used if renaming would cause the  
file's owner or group to change.

According to the page where I read about this,
http://www.cs.cmu.edu/cgi-bin/info2www?(emacs)Backup%20Copying,

`backup-by-copying-when-mismatch' is `t' by default if you start Emacs
as the superuser

In fact, on a CentOS 4 box, this variable is 't' by default for any  
user which IMO is A Good Thing - if I'm editing a file as a non root  
user, which has group ownership NOT in my default group, I'd like it  
to preserve that group ownership after an edit, on the basis that it  
probably was that way for a reason.

So, a line with

(setq-default backup-by-copying-when-mismatch t)

has been added to a startup file on all affected systems, and I'm a  
happy bunny.

Thanks Glenn,


Niall





More information about the ILUG mailing list