+ }
+ if (statret == 0) {
+ char lnk[MAXPATHLEN];
+ int len;
+
+ if (S_ISLNK(sx.st.st_mode)
+ && (len = do_readlink(fname, lnk, MAXPATHLEN-1)) > 0
+ && strncmp(lnk, sl, len) == 0 && sl[len] == '\0') {
+ /* The link is pointing to the right place. */
+ set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT);
+ if (itemizing)
+ itemize(fname, file, ndx, 0, &sx, 0, 0, NULL);
+#if defined SUPPORT_HARD_LINKS && defined CAN_HARDLINK_SYMLINK
+ if (preserve_hard_links && F_IS_HLINKED(file))
+ finish_hard_link(file, fname, ndx, &sx.st, itemizing, code, -1);
+#endif
+ if (remove_source_files == 1)
+ goto return_with_success;
+ goto cleanup;
+ }
+ } else if (basis_dir[0] != NULL) {
+ int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
+ itemizing, code);
+ if (j == -2) {
+#ifndef CAN_HARDLINK_SYMLINK
+ if (link_dest) {
+ /* Resort to --copy-dest behavior. */
+ } else
+#endif
+ if (!copy_dest)
+ goto cleanup;
+ itemizing = 0;
+ code = FNONE;
+ } else if (j >= 0)
+ statret = 1;
+ }
+ if (atomic_create(file, fname, sl, MAKEDEV(0, 0), &sx, statret == 0 ? DEL_FOR_SYMLINK : 0)) {
+ set_file_attrs(fname, file, NULL, NULL, 0);
+ if (itemizing) {
+ if (statret == 0 && !S_ISLNK(sx.st.st_mode))
+ statret = -1;
+ itemize(fname, file, ndx, statret, &sx,
+ ITEM_LOCAL_CHANGE|ITEM_REPORT_CHANGE, 0, NULL);
+ }
+ if (code != FNONE && INFO_GTE(NAME, 1))
+ rprintf(code, "%s -> %s\n", fname, sl);
+#ifdef SUPPORT_HARD_LINKS
+ if (preserve_hard_links && F_IS_HLINKED(file))
+ finish_hard_link(file, fname, ndx, NULL, itemizing, code, -1);
+#endif
+ /* This does not check remove_source_files == 1
+ * because this is one of the items that the old
+ * --remove-sent-files option would remove. */
+ if (remove_source_files)
+ goto return_with_success;
+ }
+#endif
+ goto cleanup;
+ }
+
+ if ((am_root && preserve_devices && IS_DEVICE(file->mode))
+ || (preserve_specials && IS_SPECIAL(file->mode))) {
+ dev_t rdev;
+ int del_for_flag = 0;
+ if (IS_DEVICE(file->mode)) {
+ uint32 *devp = F_RDEV_P(file);
+ rdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp));
+ } else
+ rdev = 0;
+ if (statret == 0) {
+ if (IS_DEVICE(file->mode)) {
+ if (!IS_DEVICE(sx.st.st_mode))
+ statret = -1;
+ del_for_flag = DEL_FOR_DEVICE;
+ } else {
+ if (!IS_SPECIAL(sx.st.st_mode))
+ statret = -1;
+ del_for_flag = DEL_FOR_SPECIAL;
+ }
+ if (statret == 0
+ && BITS_EQUAL(sx.st.st_mode, file->mode, _S_IFMT)
+ && (IS_SPECIAL(sx.st.st_mode) || sx.st.st_rdev == rdev)) {
+ /* The device or special file is identical. */
+ set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT);
+ if (itemizing)
+ itemize(fname, file, ndx, 0, &sx, 0, 0, NULL);
+#ifdef SUPPORT_HARD_LINKS
+ if (preserve_hard_links && F_IS_HLINKED(file))
+ finish_hard_link(file, fname, ndx, &sx.st, itemizing, code, -1);
+#endif
+ if (remove_source_files == 1)
+ goto return_with_success;
+ goto cleanup;
+ }
+ } else if (basis_dir[0] != NULL) {
+ int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
+ itemizing, code);
+ if (j == -2) {
+#ifndef CAN_HARDLINK_SPECIAL
+ if (link_dest) {
+ /* Resort to --copy-dest behavior. */
+ } else
+#endif
+ if (!copy_dest)
+ goto cleanup;
+ itemizing = 0;
+ code = FNONE;
+ } else if (j >= 0)
+ statret = 1;
+ }
+ if (DEBUG_GTE(GENR, 1)) {
+ rprintf(FINFO, "mknod(%s, 0%o, [%ld,%ld])\n",
+ fname, (int)file->mode,
+ (long)major(rdev), (long)minor(rdev));
+ }
+ if (atomic_create(file, fname, NULL, rdev, &sx, del_for_flag)) {
+ set_file_attrs(fname, file, NULL, NULL, 0);
+ if (itemizing) {
+ itemize(fname, file, ndx, statret, &sx,
+ ITEM_LOCAL_CHANGE|ITEM_REPORT_CHANGE, 0, NULL);
+ }
+ if (code != FNONE && INFO_GTE(NAME, 1))
+ rprintf(code, "%s\n", fname);
+#ifdef SUPPORT_HARD_LINKS
+ if (preserve_hard_links && F_IS_HLINKED(file))
+ finish_hard_link(file, fname, ndx, NULL, itemizing, code, -1);
+#endif
+ if (remove_source_files == 1)
+ goto return_with_success;
+ }
+ goto cleanup;
+ }
+
+ if (!S_ISREG(file->mode)) {
+ if (solo_file)
+ fname = f_name(file, NULL);
+ rprintf(FINFO, "skipping non-regular file \"%s\"\n", fname);
+ goto cleanup;
+ }
+
+ if (max_size > 0 && F_LENGTH(file) > max_size) {
+ if (INFO_GTE(SKIP, 1)) {
+ if (solo_file)
+ fname = f_name(file, NULL);
+ rprintf(FINFO, "%s is over max-size\n", fname);
+ }
+ goto cleanup;
+ }
+ if (min_size > 0 && F_LENGTH(file) < min_size) {
+ if (INFO_GTE(SKIP, 1)) {
+ if (solo_file)
+ fname = f_name(file, NULL);
+ rprintf(FINFO, "%s is under min-size\n", fname);
+ }
+ goto cleanup;
+ }
+
+ if (update_only > 0 && statret == 0
+ && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
+ if (INFO_GTE(SKIP, 1))
+ rprintf(FINFO, "%s is newer\n", fname);
+#ifdef SUPPORT_HARD_LINKS
+ if (F_IS_HLINKED(file))
+ handle_skipped_hlink(file, itemizing, code, f_out);
+#endif
+ goto cleanup;
+ }
+
+ fnamecmp_type = FNAMECMP_FNAME;
+
+ if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
+ if (delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_FILE) != 0)
+ goto cleanup;