- if (robust_rename(fnametmp,fname) != 0) {
- if (errno == EXDEV) {
- /* rename failed on cross-filesystem link.
- Copy the file instead. */
- if (copy_file(fnametmp,fname, file->mode & INITACCESSPERMS)) {
- rprintf(FERROR,"copy %s -> %s : %s\n",
- fnametmp,fname,strerror(errno));
- } else {
- set_perms(fname,file,NULL,0);
- }
- } else {
- rprintf(FERROR,"rename %s -> %s : %s\n",
- fnametmp,fname,strerror(errno));
+ if (DEBUG_GTE(RECV, 1))
+ rprintf(FINFO, "renaming %s to %s\n", fnametmp, fname);
+ ret = robust_rename(fnametmp, fname, temp_copy_name,
+ file->mode & INITACCESSPERMS);
+ if (ret < 0) {
+ rsyserr(FERROR_XFER, errno, "%s %s -> \"%s\"",
+ ret == -2 ? "copy" : "rename",
+ full_fname(fnametmp), fname);
+ if (!partialptr || (ret == -2 && temp_copy_name)
+ || robust_rename(fnametmp, partialptr, NULL,
+ file->mode & INITACCESSPERMS) < 0)
+ do_unlink(fnametmp);
+ return 0;
+ }
+ if (ret == 0) {
+ /* The file was moved into place (not copied), so it's done. */
+ return 1;
+ }
+ /* The file was copied, so tweak the perms of the copied file. If it
+ * was copied to partialptr, move it into its final destination. */
+ fnametmp = temp_copy_name ? temp_copy_name : fname;
+
+ do_set_file_attrs:
+ set_file_attrs(fnametmp, file, NULL, fnamecmp,
+ ok_to_set_time ? 0 : ATTRS_SKIP_MTIME);
+
+ if (temp_copy_name) {
+ if (do_rename(fnametmp, fname) < 0) {
+ rsyserr(FERROR_XFER, errno, "rename %s -> \"%s\"",
+ full_fname(fnametmp), fname);
+ return 0;