[gnu.utils.bug] a slight enhancement to the GNU `mv'

rsm@math.arizona.edu (Robert S. Maier) (10/15/89)

The following is a slight enhancement to the GNU `mv', written by Mike
Parker.

Like the BSD mv (the only one I'm familiar with) the GNU mv asks the
user ``Override mode xxx for filename?'' if access(2) reports no write
access to the target file.  But write access can be denied for reasons
other than bad permission flags.  In particular it can be denied if
the target is on a read-only filesystem, or if the target is a busy
executable.

The following diff uses perror(3) to report such problems.  I have
already found it useful...

-- 
Robert S. Maier   | Internet: rsm@math.arizona.edu	[128.196.128.99]
Dept. of Math.    | UUCP: ..{allegra,cmcl2,hao!noao}!arizona!amethyst!rsm
Univ. of Arizona  | Bitnet: maier@arizrvax
Tucson, AZ  85721 | FAX: +1 602 621 8322
U.S.A.            | Voice: +1 602 621 6893  /  +1 602 621 2617


----------------------------------------------------------------------
224,226c224,226
<       if ((access (to, W_OK) < 0 ||
< 	   (stb.st_mode & ((S_IWRITE>>6)*0111)) == 0)
< 	  && !force )
---
>       if ( (access (to, W_OK) < 0 ||
> 	    (stb.st_mode & ((S_IWRITE>>6)*0111)) == 0)
> 	   && !force )
228,230c228,240
< 	  printf ("Override mode %04o for `%s'? ", stb.st_mode & 0777 ,to);
< 	  if (! yes ())
< 	    return;
---
> 	  if (errno == EACCES || (stb.st_mode & ((S_IWRITE>>6)*0111)) == 0)
> 	    {
> 	      printf ("Override mode %04o for `%s'? ", stb.st_mode & 0777 ,to);
> 	      if (! yes ())
> 		return;
> 	    }
> 	  else			/* RO filesystem, text busy etc. */
> 	    {
> 	      fprintf (stderr, "%s: no write access to `%s': ", 
> 		       pgm, to); 
> 	      perror (0);
> 	      return;
> 	    }