unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#7289: Tramp changes ownership of remote file when saving
@ 2010-10-27 10:46 Jo Vermeulen
  2010-10-27 13:53 ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Jo Vermeulen @ 2010-10-27 10:46 UTC (permalink / raw)
  To: 7289

Package: emacs
Version: 23.1
Severity: important

When editing a remote file over SSH using tramp, emacs changes the ownership
of the file. I was logged in as root, and the file had ownership svn:svn.
After saving, however, emacs changed the ownership to root:root. The backup
file (filename~) did have the user/group settings however.

This behavior is quite annoying, as one often doesn't realize the ownership
has changed. This might result in services that are unable to read their
basic configuration files after they have been edited remotely with emacs.

P.S.: my apologies for double-posting, I first thought the package name
should be tramp instead of emacs.

Here's more information about my specific version of Emacs (running on
Ubuntu 10.10):

In GNU Emacs 23.1.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0)
 of 2010-03-29 on rothera, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.10900000
configured using `configure  '--build=i486-linux-gnu'
'--host=i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib'
'--libexecdir=/usr/lib' '--localstatedir=/var/lib'
'--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes'
'--enable-locallisppath=/etc/emacs23:/etc/emacs:/usr/local/share/emacs/23.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.1/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/23.1/leim'
'--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars'
'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g
-O2' 'LDFLAGS=-g' 'CPPFLAGS=''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.utf8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default-enable-multibyte-characters: t

Major mode: Help

Minor modes in effect:
  tooltip-mode: t
  tool-bar-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  global-auto-composition-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t
  view-mode: t

Recent input:
C-x C-d <backspace> <backspace> / u s r <tab> s h <tab>
e m <tab> a <tab> / <tab> <tab> 2 3 <tab> e <tab> p
r <backspace> <S-backspace> P R <tab> <return> C-x
o C-x o C-x o C-x 1 <down> <return> <right> <return>
<return> <up> <down> M-x d i r e <tab> - <tab> m <tab>
<backspace> <tab> <backspace> o <tab> d <tab> <backspace>
<backspace> <backspace> <backspace> <backspace> <backspace>
<backspace> <backspace> <backspace> w d i r <tab> <backspace>
<backspace> <backspace> <backspace> <backspace> <backspace>
<backspace> <backspace> <backspace> <backspace> <backspace>
<backspace> <backspace> <backspace> <backspace> <backspace>
<backspace> <backspace> <backspace> <backspace> <backspace>
<backspace> <backspace> <backspace> <backspace> <backspace>
<backspace> <backspace> d i r e d - m <tab> <tab> <backspace>
<backspace> <backspace> <return> <return> <down> <down>
<down> <down> <down> <down> <down> <down> <down> <down>
<down> <down> <down> <down> <down> <down> <down> <down>
<down> <down> <down> <down> C-s P R O B L E M <return>
<return> <down> <down> <down> <down> <down> <down>
<down> <down> <down> <down> <down> <down> <down> <down>
<down> <down> <down> <up> <up> <up> <up> <up> <down>
<end> <down> <down> <down> <down> <down> <down> <down>
<down> <down> <down> <down> <down> C-s t r a m p C-s
<backspace> <backspace> <backspace> <backspace> <backspace>
<backspace> r e m o t e C-s C-s C-s s s <backspace>
<backspace> C-s C-s C-s C-s C-s C-s C-s C-s C-s C-s
C-s C-x k <return> C-x k <return> M-x r e p o r t -
e m a c s <tab> <return>

Recent messages:
Loading /etc/emacs/site-start.d/50org-mode.el (source)...done
Loading /etc/emacs/site-start.d/50psvn.el (source)...done
Loading /etc/emacs/site-start.d/50w3m-el.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
Making completion list... [2 times]
help-follow: No cross-reference here [3 times]
Making completion list... [2 times]
Mark saved where search started
Note: file is write protected
Mark saved where search started





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7289: Tramp changes ownership of remote file when saving
  2010-10-27 10:46 bug#7289: Tramp changes ownership of remote file when saving Jo Vermeulen
@ 2010-10-27 13:53 ` Stefan Monnier
  2010-10-27 15:21   ` Jo Vermeulen
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2010-10-27 13:53 UTC (permalink / raw)
  To: Jo Vermeulen; +Cc: 7289

> When editing a remote file over SSH using tramp, emacs changes the ownership
> of the file. I was logged in as root, and the file had ownership svn:svn.
> After saving, however, emacs changed the ownership to root:root. The backup
> file (filename~) did have the user/group settings however.

What are your settings for backup-by-copying and
backup-by-copying-when-mismatch?


        Stefan





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7289: Tramp changes ownership of remote file when saving
  2010-10-27 13:53 ` Stefan Monnier
@ 2010-10-27 15:21   ` Jo Vermeulen
  2010-10-28 12:37     ` Michael Albinus
  0 siblings, 1 reply; 10+ messages in thread
From: Jo Vermeulen @ 2010-10-27 15:21 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 7289

On Wed, Oct 27, 2010 at 3:53 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> When editing a remote file over SSH using tramp, emacs changes the ownership
>> of the file. I was logged in as root, and the file had ownership svn:svn.
>> After saving, however, emacs changed the ownership to root:root. The backup
>> file (filename~) did have the user/group settings however.
>
> What are your settings for backup-by-copying and
> backup-by-copying-when-mismatch?

C-h-v backup-by-coping gives me:

"backup-by-copying's value is nil"

Which, I assume, means that Emacs might use renaming for backups.

And C-h-v backup-by-coping-when-mismatch results in:

"backup-by-copying-when-mismatch's value is nil"

I guess if this value would be non-nil, my problem would be solved?

Additionally, C-h-v backup-by-copying-when-privileged-mismatch gives me:

"backup-by-copying-when-privileged-mismatch's value is 200"

I just toggled backup-by-copying-when-mismatch and tried it again, and
indeed, it does work now.

I'm just wondering if this means that the default behavior is broken?
It seems Emacs automatically sets backup-by-copying-when-mismatch to t
when it is run by the superuser (root) to overcome this problem
(source: http://www.delorie.com/gnu/docs/emacs/emacs_117.html).

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?

Thanks for your help!

Cheers,

-- Jo





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7289: Tramp changes ownership of remote file when saving
  2010-10-27 15:21   ` Jo Vermeulen
@ 2010-10-28 12:37     ` Michael Albinus
  2010-10-29 10:42       ` Jo Vermeulen
  2010-10-31 19:15       ` Stefan Monnier
  0 siblings, 2 replies; 10+ messages in thread
From: Michael Albinus @ 2010-10-28 12:37 UTC (permalink / raw)
  To: Jo Vermeulen; +Cc: 7289

Jo Vermeulen <jo.vermeulen@gmail.com> 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.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7289: Tramp changes ownership of remote file when saving
  2010-10-28 12:37     ` Michael Albinus
@ 2010-10-29 10:42       ` Jo Vermeulen
  2010-10-29 11:25         ` Michael Albinus
  2010-10-31 19:15       ` Stefan Monnier
  1 sibling, 1 reply; 10+ messages in thread
From: Jo Vermeulen @ 2010-10-29 10:42 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 7289

On Thu, Oct 28, 2010 at 2:37 PM, Michael Albinus <michael.albinus@gmx.de> wrote:
> Jo Vermeulen <jo.vermeulen@gmail.com> 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---

To which function does this patch apply? Couldn't immediately find it,
but my code might be different from the current Emacs 23 branch ...

Thanks!

-- Jo

-- Jo





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7289: Tramp changes ownership of remote file when saving
  2010-10-29 10:42       ` Jo Vermeulen
@ 2010-10-29 11:25         ` Michael Albinus
  2010-10-29 13:28           ` Jo Vermeulen
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Albinus @ 2010-10-29 11:25 UTC (permalink / raw)
  To: Jo Vermeulen; +Cc: 7289

Jo Vermeulen <jo.vermeulen@gmail.com> writes:

> To which function does this patch apply? Couldn't immediately find it,
> but my code might be different from the current Emacs 23 branch ...

tramp-handle-insert-file-contents

If you are using Emacs' trunk, it would be another file / another function.

> Thanks!
>
> -- Jo

Best regards, Michael.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7289: Tramp changes ownership of remote file when saving
  2010-10-29 11:25         ` Michael Albinus
@ 2010-10-29 13:28           ` Jo Vermeulen
  2010-10-29 19:31             ` Michael Albinus
  0 siblings, 1 reply; 10+ messages in thread
From: Jo Vermeulen @ 2010-10-29 13:28 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 7289

On Fri, Oct 29, 2010 at 1:25 PM, Michael Albinus <michael.albinus@gmx.de> wrote:
> Jo Vermeulen <jo.vermeulen@gmail.com> writes:
>
>> To which function does this patch apply? Couldn't immediately find it,
>> but my code might be different from the current Emacs 23 branch ...
>
> tramp-handle-insert-file-contents
>
> If you are using Emacs' trunk, it would be another file / another function.

I changed it, and it seems to work now. However, I get this error (in
*Messages*):

apply: Symbol's value as variable is void: local-copy

My tramp.el file can be found @
http://research.edm.uhasselt.be/~jvermeulen/tmp/emacs/tramp.el

Cheers,

-- Jo





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7289: Tramp changes ownership of remote file when saving
  2010-10-29 13:28           ` Jo Vermeulen
@ 2010-10-29 19:31             ` Michael Albinus
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Albinus @ 2010-10-29 19:31 UTC (permalink / raw)
  To: Jo Vermeulen; +Cc: 7289-done

Jo Vermeulen <jo.vermeulen@gmail.com> writes:

> I changed it, and it seems to work now. However, I get this error (in
> *Messages*):
>
> apply: Symbol's value as variable is void: local-copy

I see. The lines

	  (when (and (stringp local-copy)
		     (or remote-copy (null tramp-temp-buffer-file-name)))
	    (delete-file local-copy))

were added later as with Emacs 23.1, you can discard them.

Thanks for testing, I'll commit the patch (and close the bug).

> Cheers,
>
> -- Jo

Best regards, Miochael.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7289: Tramp changes ownership of remote file when saving
  2010-10-28 12:37     ` Michael Albinus
  2010-10-29 10:42       ` Jo Vermeulen
@ 2010-10-31 19:15       ` Stefan Monnier
  2010-11-01  7:33         ` Michael Albinus
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2010-10-31 19:15 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 7289, Jo Vermeulen

> ! 	    ;; 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)))

2 problems with this patch:
- (put <var> 'permanent-local t) should *never* be in such a function.
  It's a top-level operation that has global effects and belongs right
  next to the var's defvar.
- This makes it impossible to choose backup-by-copying-when-mismatch=nil
  when accessing such remote files, whereas for local files accessed by
  root a (setq backup-by-copying-when-mismatch nil) in the .emacs will
  do the trick.

A simpler solution would be to change the default value of
backup-by-copying-when-mismatch to t for everyone rather than just
for root.  I don't know what would the objections to this.


        Stefan





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#7289: Tramp changes ownership of remote file when saving
  2010-10-31 19:15       ` Stefan Monnier
@ 2010-11-01  7:33         ` Michael Albinus
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Albinus @ 2010-11-01  7:33 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 7289, Jo Vermeulen

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> 2 problems with this patch:
> - (put <var> 'permanent-local t) should *never* be in such a function.
>   It's a top-level operation that has global effects and belongs right
>   next to the var's defvar.

I want to have `backup-by-copying-when-mismatch' buffer local. If I set
it in `insert-file-contents' (via `make-local-variable'), it is not kept
buffer local in that buffer. How could I achieve this otherwise?

> - This makes it impossible to choose backup-by-copying-when-mismatch=nil
>   when accessing such remote files, whereas for local files accessed by
>   root a (setq backup-by-copying-when-mismatch nil) in the .emacs will
>   do the trick.

D'accord. We would need another way for the user to express his
wish. Maybe there shall be also other values but only than nil and t.

> A simpler solution would be to change the default value of
> backup-by-copying-when-mismatch to t for everyone rather than just
> for root.  I don't know what would the objections to this.

From my pov it would be acceptable, but I don't know how people see
it. And we should check what it does mean for remote files, because they
tend to "mismatch" more often.

>         Stefan

Best regards, Michael.





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-11-01  7:33 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-27 10:46 bug#7289: Tramp changes ownership of remote file when saving Jo Vermeulen
2010-10-27 13:53 ` Stefan Monnier
2010-10-27 15:21   ` Jo Vermeulen
2010-10-28 12:37     ` Michael Albinus
2010-10-29 10:42       ` Jo Vermeulen
2010-10-29 11:25         ` Michael Albinus
2010-10-29 13:28           ` Jo Vermeulen
2010-10-29 19:31             ` Michael Albinus
2010-10-31 19:15       ` Stefan Monnier
2010-11-01  7:33         ` Michael Albinus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).