Make sure we never try to store a 0 key and tweak key64 init.
[rsync/rsync.git] / hlink.c
diff --git a/hlink.c b/hlink.c
index 291c5ce..9057a92 100644 (file)
--- a/hlink.c
+++ b/hlink.c
@@ -32,7 +32,6 @@ extern int do_xfers;
 extern int link_dest;
 extern int preserve_acls;
 extern int preserve_xattrs;
-extern int make_backups;
 extern int protocol_version;
 extern int remove_source_files;
 extern int stdout_format_has_i;
@@ -377,9 +376,13 @@ int hard_link_check(struct file_struct *file, int ndx, char *fname,
        }
 
        if (link_stat(prev_name, &prev_st, 0) < 0) {
-               rsyserr(FERROR_XFER, errno, "stat %s failed",
-                       full_fname(prev_name));
-               return -1;
+               if (!dry_run || errno != ENOENT) {
+                       rsyserr(FERROR_XFER, errno, "stat %s failed", full_fname(prev_name));
+                       return -1;
+               }
+               /* A new hard-link will get a new dev & inode, so approximate
+                * those values in dry-run mode by zeroing them. */
+               memset(&prev_st, 0, sizeof prev_st);
        }
 
        if (statret < 0 && basis_dir[0] != NULL) {
@@ -540,7 +543,14 @@ void finish_hard_link(struct file_struct *file, const char *fname, int fin_ndx,
        if (inc_recurse) {
                int gnum = F_HL_GNUM(file);
                struct ht_int32_node *node = hashtable_find(prior_hlinks, gnum, 0);
-               assert(node != NULL && node->data != NULL);
+               if (node == NULL) {
+                       rprintf(FERROR, "Unable to find a hlink node for %d (%s)\n", gnum, f_name(file, prev_name));
+                       exit_cleanup(RERR_MESSAGEIO);
+               }
+               if (node->data == NULL) {
+                       rprintf(FERROR, "Hlink node data for %d is NULL (%s)\n", gnum, f_name(file, prev_name));
+                       exit_cleanup(RERR_MESSAGEIO);
+               }
                assert(CVAL(node->data, 0) == 0);
                free(node->data);
                if (!(node->data = strdup(our_name)))