- 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",
- full_fname(fnametmp), fname,
- strerror(errno));
- } else {
- set_perms(fname,file,NULL,0);
- }
+ 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;
+ }
+ handle_partial_dir(temp_copy_name, PDIR_DELETE);
+ }
+ return 1;
+}
+
+struct file_list *flist_for_ndx(int ndx, const char *fatal_error_loc)
+{
+ struct file_list *flist = cur_flist;
+
+ if (!flist && !(flist = first_flist))
+ goto not_found;
+
+ while (ndx < flist->ndx_start-1) {
+ if (flist == first_flist)
+ goto not_found;
+ flist = flist->prev;
+ }
+ while (ndx >= flist->ndx_start + flist->used) {
+ if (!(flist = flist->next))
+ goto not_found;
+ }
+ return flist;
+
+ not_found:
+ if (fatal_error_loc) {
+ int first, last;
+ if (first_flist) {
+ first = first_flist->ndx_start - 1;
+ last = first_flist->prev->ndx_start + first_flist->prev->used - 1;