[Toybox] cp.c

enh enh at google.com
Thu Mar 11 08:30:55 PST 2021


i don't understand this code in cp.c, specifically the marked line. because
of the `errno = EXDEV` on the first line of this snippet, and the absence
of any `errno = 0` in between, what was the `if (errno &&` for?

    errno = EXDEV;
    if (CFG_MV && toys.which->name[0] == 'm') {
      int force = FLAG(f), no_clobber = FLAG(n);

      if (!force || no_clobber) {
        struct stat st;
        int exists = !stat(TT.destname, &st);

        // Prompt if -i or file isn't writable.  Technically "is writable"
is
        // more complicated (022 is not writeable by the owner, just
everybody
        // _else_) but I don't care.
        if (exists && (FLAG(i) || (!(st.st_mode & 0222) && isatty(0)))) {
          fprintf(stderr, "%s: overwrite '%s'", toys.which->name,
TT.destname);
          if (!yesno(0)) rc = 0;
          else unlink(TT.destname);
        }
        // if -n and dest exists, don't try to rename() or copy
        if (exists && no_clobber) rc = 0;
      }
      if (rc) rc = rename(src, TT.destname);
!     if (errno && !*trail) *trail = '/';
    }

it seems from the history like the EXDEV assignment was for the later test
of `errno != EXDEV` and is really meant to be a "did we successfully
move?". i don't think that's still valid now the force/clobber code has
been added?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20210311/fa7a13e4/attachment.html>


More information about the Toybox mailing list