+ /* 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@epipe.fi for pointing
+ this out */
+ fd2 = do_open(fnametmp,O_WRONLY|O_CREAT|O_EXCL,
+ file->mode & ACCESSPERMS);
+
+ if (fd2 == -1 && relative_paths && errno == ENOENT &&
+ create_directory_path(fnametmp) == 0) {
+ fd2 = do_open(fnametmp,O_WRONLY|O_CREAT|O_EXCL,
+ file->mode & ACCESSPERMS);
+ }
+ if (fd2 == -1) {
+ rprintf(FERROR,"open %s : %s\n",fnametmp,strerror(errno));
+ receive_data(f_in,buf,-1,NULL,file->length);
+ if (buf) unmap_file(buf);
+ close(fd1);
+ continue;
+ }
+
+ cleanup_fname = fnametmp;
+ cleanup_new_fname = fname;
+ cleanup_file = file;
+
+ if (!am_server && verbose)
+ printf("%s\n",fname);
+
+ /* recv file data */
+ recv_ok = receive_data(f_in,buf,fd2,fname,file->length);
+
+ if (buf) unmap_file(buf);
+ if (fd1 != -1) {
+ close(fd1);
+ }
+ close(fd2);
+
+ if (verbose > 2)
+ rprintf(FINFO,"renaming %s to %s\n",fnametmp,fname);
+
+ finish_transfer(fname, fnametmp, file);
+
+ cleanup_fname = NULL;
+
+ if (!recv_ok) {
+ if (csum_length == SUM_LENGTH) {
+ rprintf(FERROR,"ERROR: file corruption in %s. File changed during transfer?\n",
+ fname);
+ } else {
+ if (verbose > 1)
+ rprintf(FINFO,"redoing %s(%d)\n",fname,i);
+ write_int(f_gen,i);
+ }
+ }
+ }
+
+ if (preserve_hard_links)
+ do_hard_links(flist);
+
+ /* now we need to fix any directory permissions that were
+ modified during the transfer */
+ for (i = 0; i < flist->count; i++) {
+ file = flist->files[i];
+ if (!file->basename || !S_ISDIR(file->mode)) continue;
+ recv_generator(f_name(file),flist,i,-1);
+ }
+
+ if (verbose > 2)
+ rprintf(FINFO,"recv_files finished\n");
+
+ return 0;