On Oct 10 12:25:39, h...@stare.cz wrote:
> bin/mv has its own copies of cp.c and mv.c.
> Apparently, they are modifications of cp's cp.c and rm's rm.c,
> used when moving as "copy and remove the source".
> 
> In bin/mv/rm.c, the following snippet of rm_file() confuses me:
> 
>       if (S_ISDIR(sb.st_mode)) {
>               warnx("%s: is a directory", f);
>               eval = 1;
>               continue;
>       }
>       if (S_ISDIR(sb.st_mode))
>               rval = rmdir(f);
>       else {
>               rval = unlink(f);
>       }
> 
> If it's a directory, give up.
> And if it's a directory, rmdir();
> 
> Is this intentional? In fact, rm_file() and check()
> are not used anywhere else in bin/mv code.

I mean "not used anywhere", not "not used anywhere else".
Sorry for the bad phrasing.

> Is it there to keep the diff to bin/rm smaller?
> 
>       Jan
> 
> 
> Index: rm.c
> ===================================================================
> RCS file: /cvs/src/bin/mv/rm.c,v
> retrieving revision 1.7
> diff -u -p -r1.7 rm.c
> --- rm.c      27 Nov 2015 17:32:16 -0000      1.7
> +++ rm.c      10 Oct 2016 10:21:01 -0000
> @@ -52,9 +52,7 @@ extern char *__progname;
>  
>  static int eval, stdin_ok;
>  
> -static int   check(char *, char *, struct stat *);
>  static void  checkdot(char **);
> -static void  rm_file(char **);
>  static void  rm_tree(char **);
>  
>  static void __dead
> @@ -79,7 +77,6 @@ rmmain(int argc, char *argv[])
>  
>       if (*argv) {
>               stdin_ok = isatty(STDIN_FILENO);
> -
>               rm_tree(argv);
>       }
>  
> @@ -158,72 +155,6 @@ rm_tree(char **argv)
>       if (errno)
>               err(1, "fts_read");
>       fts_close(fts);
> -}
> -
> -static void
> -rm_file(char **argv)
> -{
> -     struct stat sb;
> -     int rval;
> -     char *f;
> -
> -     /*
> -      * Remove a file.  POSIX 1003.2 states that, by default, attempting
> -      * to remove a directory is an error, so must always stat the file.
> -      */
> -     while ((f = *argv++) != NULL) {
> -             /* Assume if can't stat the file, can't unlink it. */
> -             if (lstat(f, &sb)) {
> -                     if (errno != ENOENT) {
> -                             warn("%s", f);
> -                             eval = 1;
> -                     }
> -                     continue;
> -             }
> -
> -             if (S_ISDIR(sb.st_mode)) {
> -                     warnx("%s: is a directory", f);
> -                     eval = 1;
> -                     continue;
> -             }
> -             if (S_ISDIR(sb.st_mode))
> -                     rval = rmdir(f);
> -             else {
> -                     rval = unlink(f);
> -             }
> -             if (rval && (errno != ENOENT)) {
> -                     warn("%s", f);
> -                     eval = 1;
> -             }
> -     }
> -}
> -
> -static int
> -check(char *path, char *name, struct stat *sp)
> -{
> -     int ch, first;
> -     char modep[15];
> -
> -     /*
> -      * If it's not a symbolic link and it's unwritable and we're
> -      * talking to a terminal, ask.  Symbolic links are excluded
> -      * because their permissions are meaningless.  Check stdin_ok
> -      * first because we may not have stat'ed the file.
> -      */
> -     if (!stdin_ok || S_ISLNK(sp->st_mode) || !access(name, W_OK) ||
> -         errno != EACCES)
> -             return (1);
> -     strmode(sp->st_mode, modep);
> -     (void)fprintf(stderr, "override %s%s%s/%s for %s? ",
> -         modep + 1, modep[9] == ' ' ? "" : " ",
> -         user_from_uid(sp->st_uid, 0),
> -         group_from_gid(sp->st_gid, 0), path);
> -     (void)fflush(stderr);
> -
> -     first = ch = getchar();
> -     while (ch != '\n' && ch != EOF)
> -             ch = getchar();
> -     return (first == 'y' || first == 'Y');
>  }
>  
>  /*
> 

Reply via email to