It is just stupid to have to do ``<ESC>!rm -f %'' to write a file you own.

So lets stop that nonsense and allow `w!' to do something useful.

Submitted by:	green
This commit is contained in:
David E. O'Brien 2001-07-09 04:11:33 +00:00
parent bf3009895e
commit fbd7787b32
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=79444

View File

@ -837,10 +837,39 @@ file_write(sp, fm, tm, name, flags)
SIGBLOCK;
if ((fd = open(name, oflags,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) < 0) {
if (errno == EACCES && LF_ISSET(FS_FORCE)) {
/*
* If the user owns the file but does not
* have write permission on it, grant it
* automatically for the duration of the
* opening of the file, if possible.
*/
struct stat sb;
mode_t fmode;
if (stat(name, &sb) != 0)
goto fail_open;
fmode = sb.st_mode;
if (!(sb.st_mode & S_IWUSR) && sb.st_uid == getuid())
fmode |= S_IWUSR;
else
goto fail_open;
if (chmod(name, fmode) != 0)
goto fail_open;
fd = open(name, oflags, S_IRUSR | S_IWUSR |
S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (fd == -1)
goto fail_open;
(void)fchmod(fd, sb.st_mode);
goto success_open;
fail_open:
errno = EACCES;
}
msgq_str(sp, M_SYSERR, name, "%s");
SIGUNBLOCK;
return (1);
}
success_open:
SIGUNBLOCK;
/* Try and get a lock. */