Subject: Re: bug#7289: Tramp changes ownership of remote file when saving

From: Michael Albinus <[email-masked]>
Date: Thu, 28 Oct 2010 14:37:18 +0200

Jo Vermeulen <[email-masked]> writes:

> I don't think many people will run Emacs as root in this day and age.
> However, they might log in as root on a remote server, or edit a file
> as root (using sudo/su). Maybe Emacs or Tramp should also
> automatically set the backup-by-copying-when-mismatch variable to t in
> those cases?

Could you, please, try the following patch? It is towards the Emacs-23
branch, line numbers might differ with your tramp.el.

--8<---------------cut here---------------start------------->8---
*** /home/albinus/src/emacs-23/lisp/net/tramp.el.~100136~	2010-10-28 14:31:49.730285001 +0200
--- /home/albinus/src/emacs-23/lisp/net/tramp.el	2010-10-28 14:29:40.990285001 +0200
***************
*** 5008,5014 ****
  	    (setq buffer-file-name filename)
  	    (setq buffer-read-only (not (file-writable-p filename)))
  	    (set-visited-file-modtime)
! 	    (set-buffer-modified-p nil))
  	  (when (and (stringp local-copy)
  		     (or remote-copy (null tramp-temp-buffer-file-name)))
  	    (delete-file local-copy))
--- 5008,5018 ----
  	    (setq buffer-file-name filename)
  	    (setq buffer-read-only (not (file-writable-p filename)))
  	    (set-visited-file-modtime)
! 	    (set-buffer-modified-p nil)
! 	    ;; For root, preserve owner and group when editing files.
! 	    (when (string-equal (file-remote-p filename 'user) "root")
! 	      (set (make-local-variable 'backup-by-copying-when-mismatch) t)
! 	      (put 'backup-by-copying-when-mismatch 'permanent-local t)))
  	  (when (and (stringp local-copy)
  		     (or remote-copy (null tramp-temp-buffer-file-name)))
  	    (delete-file local-copy))
--8<---------------cut here---------------end--------------->8---

> Thanks for your help!
> Cheers,
> -- Jo

Best regards, Michael.