possible typo/bug in receiver.c

Craig Barratt craig at atheros.com
Sat Jan 18 07:44:00 EST 2003


The following code in receiver.c around line 421 (2.5.6pre1) contains
some dead code:

        /* we initially set the perms without the
           setuid/setgid bits to ensure that there is no race
           condition. They are then correctly updated after
           the lchown. Thanks to snabb at epipe.fi for pointing
           this out.  We also set it initially without group
           access because of a similar race condition. */
        fd2 = do_mkstemp(fnametmp, file->mode & INITACCESSPERMS);
        if (fd2 == -1) {
                rprintf(FERROR,"mkstemp %s failed: %s\n",fnametmp,strerror(errno));
                receive_data(f_in,buf,-1,NULL,file->length);
                if (buf) unmap_file(buf);
                if (fd1 != -1) close(fd1);
                continue;
        }

        /* in most cases parent directories will already exist
           because their information should have been previously
           transferred, but that may not be the case with -R */
        if (fd2 == -1 && relative_paths && errno == ENOENT &&
            create_directory_path(fnametmp, orig_umask) == 0) {
                strlcpy(fnametmp, template, sizeof(fnametmp));
                fd2 = do_mkstemp(fnametmp, file->mode & INITACCESSPERMS);
        }
        if (fd2 == -1) {
                rprintf(FERROR,"cannot create %s : %s\n",fnametmp,strerror(errno));
                receive_data(f_in,buf,-1,NULL,file->length);
                if (buf) unmap_file(buf);
                if (fd1 != -1) close(fd1);
                continue;
        }

If mkstemp() fails (for various reasons, including the directory not
existing) then fd == -1.  So the first if () executes, which flushes
the data and does a continue.  So the next two if () statements will
never execute.

It might be an editing error (not sure how old it is).  It looks
like the first if () statement was meant to be replaced by the
next two; ie: the first if () statement should be eliminated.

I haven't backed out a command-level example that shows the difference,
but it relates to receiving into a path whose last two or more
directories don't exist.  Is rsync meant to create deep directories
that don't exist?

Craig



More information about the rsync mailing list