- if (failed) {
- if (verbose > 2) {
- rprintf(FERROR, "robust_move failed: %s(%d)\n",
- strerror(errno), errno);
- }
- switch (errno) {
- case EXDEV: /* external filesystem */
- keep_path_extfs = 1;
- keep_trying--;
- break;
- case ENOENT: /* no directory to write to */
- if (make_bak_dir(dst) < 0)
- keep_trying = 0;
- else
- keep_trying--;
- break;
- default:
- keep_trying = 0;
- break;
- }
- } else
- keep_trying = 0;
+/* Has same return codes as make_backup(). */
+static inline int link_or_rename(const char *from, const char *to,
+ BOOL prefer_rename, STRUCT_STAT *stp)
+{
+#ifdef SUPPORT_HARD_LINKS
+ if (!prefer_rename) {
+#ifndef CAN_HARDLINK_SYMLINK
+ if (S_ISLNK(stp->st_mode))
+ return 0; /* Use copy code. */
+#endif
+#ifndef CAN_HARDLINK_SPECIAL
+ if (IS_SPECIAL(stp->st_mode) || IS_DEVICE(stp->st_mode))
+ return 0; /* Use copy code. */
+#endif
+ if (do_link(from, to) == 0) {
+ if (DEBUG_GTE(BACKUP, 1))
+ rprintf(FINFO, "make_backup: HLINK %s successful.\n", from);
+ return 2;
+ }
+ /* We prefer to rename a regular file rather than copy it. */
+ if (!S_ISREG(stp->st_mode) || errno == EEXIST || errno == EISDIR)
+ return 0;