unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* VC, read-only buffers for writable files
@ 2002-10-22 13:31 Stefan Monnier
  2002-10-22 14:35 ` Andre Spiegel
  2002-10-23  7:12 ` Richard Stallman
  0 siblings, 2 replies; 7+ messages in thread
From: Stefan Monnier @ 2002-10-22 13:31 UTC (permalink / raw)
  Cc: spiegel


It had been decided to postpone the decision to post-21.1,
so I think it's time to make a decision now.

Currently VC sometimes makes a file read-only because it thinks it's
better that way for the user.  More specifically, it makes it read-only
if the file seems to be locked by another user.

This can cause problems when VC gets the lock's ownership wrong
or when people are purposefully setting up access rights such
that anybody who's part of a particular group should be able to edit
the checked-out file.

It might be able to help the user avert a mistake in a few cases,
but that's only if the file's permissions are setup incorrectly.
If the file's permissions are not setup properly, then the user will
probably encounter many other risks anyway so what should happen in this
case is that the permissions should be fixed.

But Emacs has no way to tell whether the discrepency is because the
user has set things up in a slightly non-standard way, or whether it's
because Emacs is confused, or whether it's indeed because the file should
be read-only.

This special behavior used to apply to SCCS, RCS and CVS under Emacs-20
and was silently changed in Emacs-21 to only apply to RCS and SCCS (it was
changed as a side effect of another change).  Nobody complained about
this change and I think we should go further and remove this hack
altogether so it doesn't aply to RCS and SCCS either.


	Stefan

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

* Re: VC, read-only buffers for writable files
  2002-10-22 13:31 VC, read-only buffers for writable files Stefan Monnier
@ 2002-10-22 14:35 ` Andre Spiegel
  2002-10-22 14:49   ` Stefan Monnier
  2002-10-23  7:12 ` Richard Stallman
  1 sibling, 1 reply; 7+ messages in thread
From: Andre Spiegel @ 2002-10-22 14:35 UTC (permalink / raw)
  Cc: Stefan Monnier

On Tue, 2002-10-22 at 15:31, Stefan Monnier wrote:

> Currently VC sometimes makes a file read-only because it thinks it's
> better that way for the user.  More specifically, it makes it read-only
> if the file seems to be locked by another user.

I have talked this over with Stefan several times, and we have reached
no agreement.  I'll be happy to let the general public (or Richard, for
that matter :-) decide.

> This special behavior used to apply to SCCS, RCS and CVS under Emacs-20
> and was silently changed in Emacs-21 to only apply to RCS and SCCS (it was
> changed as a side effect of another change).  Nobody complained about
> this change and I think we should go further and remove this hack
> altogether so it doesn't aply to RCS and SCCS either.

The behavior wasn't changed accidentally for CVS.  There are no locks
under CVS, and Emacs-21 handles that correctly by not assuming that a
file could be "locked" by anybody.  RCS and SCCS do have locks, and
Emacs-21 deliberately chooses to enforce the locking.  This is not a
"hack".  If people don't want that, so be it, then we'll change it.

Here is the relevant portion of code from vc-hooks.el, since the
comments may make it clearer to everybody.

    ;; If the file is locked by some other user, make
    ;; the buffer read-only.  Like this, even root
    ;; cannot modify a file that someone else has locked.
    (and (equal file (buffer-file-name))
         (stringp (vc-state file))
	 (setq buffer-read-only t))
    ;; If the user is root, and the file is not owner-writable,
    ;; then pretend that we can't write it
    ;; even though we can (because root can write anything).
    ;; This way, even root cannot modify a file that isn't locked.
    (and (equal file (buffer-file-name))
	 (not buffer-read-only)
	 (zerop (user-real-uid))
	 (zerop (logand (file-modes (buffer-file-name)) 128))
	 (setq buffer-read-only t)))

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

* Re: VC, read-only buffers for writable files
  2002-10-22 14:35 ` Andre Spiegel
@ 2002-10-22 14:49   ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2002-10-22 14:49 UTC (permalink / raw)
  Cc: emacs-devel, Stefan Monnier

> > Currently VC sometimes makes a file read-only because it thinks it's
> > better that way for the user.  More specifically, it makes it read-only
> > if the file seems to be locked by another user.
> 
> I have talked this over with Stefan several times, and we have reached
> no agreement.

We did agree to postpone the decision to after 21.1, tho ;-)

> > This special behavior used to apply to SCCS, RCS and CVS under Emacs-20
> > and was silently changed in Emacs-21 to only apply to RCS and SCCS (it was
> > changed as a side effect of another change).  Nobody complained about
> > this change and I think we should go further and remove this hack
> > altogether so it doesn't aply to RCS and SCCS either.
> 
> The behavior wasn't changed accidentally for CVS.  There are no locks

Maybe it wasn't accidentally, but it was changed.  In Emacs-20 you
could end up in CVS with a read-only buffer because the owner of the
locally modified file was different from the current user (or
seemed that way to VC).  That's because VC considered a locally modified
CVS file as "locked by the owner of the file".

> under CVS, and Emacs-21 handles that correctly by not assuming that a
> file could be "locked" by anybody.  RCS and SCCS do have locks, and
> Emacs-21 deliberately chooses to enforce the locking.  This is not a
> "hack".

Sorry for using "hack".  I tried to be somewhat "neutral" in my post,
but my bias took precedence.  The reason why I think it's a hack
is because such things *should* be enforced with file permissions
and are enforced that way on all the systems I've used.

> Here is the relevant portion of code from vc-hooks.el, since the
> comments may make it clearer to everybody.
> 
>     ;; If the file is locked by some other user, make
>     ;; the buffer read-only.  Like this, even root
>     ;; cannot modify a file that someone else has locked.
>     (and (equal file (buffer-file-name))
>          (stringp (vc-state file))
> 	 (setq buffer-read-only t))
>     ;; If the user is root, and the file is not owner-writable,
>     ;; then pretend that we can't write it
>     ;; even though we can (because root can write anything).
>     ;; This way, even root cannot modify a file that isn't locked.
>     (and (equal file (buffer-file-name))
> 	 (not buffer-read-only)
> 	 (zerop (user-real-uid))
> 	 (zerop (logand (file-modes (buffer-file-name)) 128))
> 	 (setq buffer-read-only t)))

Note that I'd gladly remove the second half as well, but I'm mostly
interested in the first half (the behavior of Emacs when run as root
is not of much concern to me).


	Stefan

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

* Re: VC, read-only buffers for writable files
  2002-10-22 13:31 VC, read-only buffers for writable files Stefan Monnier
  2002-10-22 14:35 ` Andre Spiegel
@ 2002-10-23  7:12 ` Richard Stallman
  2002-10-23  7:39   ` Stefan Monnier
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Stallman @ 2002-10-23  7:12 UTC (permalink / raw)
  Cc: emacs-devel, spiegel

    Currently VC sometimes makes a file read-only because it thinks it's
    better that way for the user.  More specifically, it makes it read-only
    if the file seems to be locked by another user.

Under RCS, the file is read-only whenever the file is not locked by you.
I think that is the right way to handle it.

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

* Re: VC, read-only buffers for writable files
  2002-10-23  7:12 ` Richard Stallman
@ 2002-10-23  7:39   ` Stefan Monnier
  2002-10-24 16:54     ` Richard Stallman
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2002-10-23  7:39 UTC (permalink / raw)
  Cc: monnier+gnu/emacs, emacs-devel, spiegel

>     Currently VC sometimes makes a file read-only because it thinks it's
                                     ^^^^
Sorry that should have been `buffer'.

>     better that way for the user.  More specifically, it makes it read-only
>     if the file seems to be locked by another user.
> 
> Under RCS, the file is read-only whenever the file is not locked by you.
> I think that is the right way to handle it.

If the file is indeed read-only, then everything works as expected,
but the VC code also tries to make the buffer read-only when the file
is locked by someone else and yet is writable.  This can happen either
because the user is using group-permissions in unusual ways or because
VC is confused and doesn't realize the the current user and the user
holding the lock are one and the same.


	Stefan

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

* Re: VC, read-only buffers for writable files
  2002-10-23  7:39   ` Stefan Monnier
@ 2002-10-24 16:54     ` Richard Stallman
  2002-10-24 17:03       ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Stallman @ 2002-10-24 16:54 UTC (permalink / raw)
  Cc: monnier+gnu/emacs, emacs-devel, spiegel

    Sorry that should have been `buffer'.

    >     better that way for the user.  More specifically, it makes it read-only
    >     if the file seems to be locked by another user.
    > 
    > Under RCS, the file is read-only whenever the file is not locked by you.
    > I think that is the right way to handle it.

I also meant `buffer'.

    If the file is indeed read-only, then everything works as expected,
    but the VC code also tries to make the buffer read-only when the file
    is locked by someone else and yet is writable.

I think that is correct--and useful.  If VC is mistaken, you can use
C-x C-q to make the buffer writable.

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

* Re: VC, read-only buffers for writable files
  2002-10-24 16:54     ` Richard Stallman
@ 2002-10-24 17:03       ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2002-10-24 17:03 UTC (permalink / raw)
  Cc: monnier+gnu/emacs, emacs-devel, spiegel

>     Sorry that should have been `buffer'.
> 
>     >     better that way for the user.  More specifically, it makes it read-only
>     >     if the file seems to be locked by another user.
>     > 
>     > Under RCS, the file is read-only whenever the file is not locked by you.
>     > I think that is the right way to handle it.
> 
> I also meant `buffer'.
> 
>     If the file is indeed read-only, then everything works as expected,
>     but the VC code also tries to make the buffer read-only when the file
>     is locked by someone else and yet is writable.
> 
> I think that is correct--and useful.  If VC is mistaken, you can use
> C-x C-q to make the buffer writable.

Problem is: it happens very rarely since RCS normally makes sure the file
is not writable by anybody but the true user.  And when it happens it's too
often because VC is confused about the identity of the owner of the lock.
Every few months a user complains about this behavior in VC and it's
difficult to fix.


	Stefan

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

end of thread, other threads:[~2002-10-24 17:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-22 13:31 VC, read-only buffers for writable files Stefan Monnier
2002-10-22 14:35 ` Andre Spiegel
2002-10-22 14:49   ` Stefan Monnier
2002-10-23  7:12 ` Richard Stallman
2002-10-23  7:39   ` Stefan Monnier
2002-10-24 16:54     ` Richard Stallman
2002-10-24 17:03       ` Stefan Monnier

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).