Made read_arg_from_pipe() handle EINTR.
[rsync/rsync.git] / hlink.c
diff --git a/hlink.c b/hlink.c
index 6dde2cc..87e4236 100644 (file)
--- a/hlink.c
+++ b/hlink.c
@@ -24,6 +24,7 @@
 
 extern int verbose;
 extern int dry_run;
+extern int list_only;
 extern int am_sender;
 extern int inc_recurse;
 extern int do_xfers;
@@ -34,11 +35,9 @@ extern int protocol_version;
 extern int remove_source_files;
 extern int stdout_format_has_i;
 extern int maybe_ATTRS_REPORT;
+extern int unsort_ndx;
 extern char *basis_dir[];
 extern struct file_list *cur_flist;
-#ifdef ICONV_OPTION
-extern int ic_ndx;
-#endif
 
 #ifdef SUPPORT_HARD_LINKS
 
@@ -144,12 +143,10 @@ static void match_gnums(int32 *ndx_list, int ndx_count)
                        if (gnum != gnum_next)
                                break;
                        F_HL_PREV(file) = prev;
-                       /* The linked list must use raw ndx values. */
-#ifdef ICONV_OPTION
-                       if (ic_ndx)
+                       /* The linked list uses over-the-wire ndx values. */
+                       if (unsort_ndx)
                                prev = F_NDX(file);
                        else
-#endif
                                prev = ndx_list[from] + hlink_flist->ndx_start;
                }
                if (prev < 0 && !inc_recurse) {
@@ -163,11 +160,9 @@ static void match_gnums(int32 *ndx_list, int ndx_count)
                file->flags |= FLAG_HLINK_LAST;
                F_HL_PREV(file) = prev;
                if (inc_recurse && CVAL(node->data, 0) == 0) {
-#ifdef ICONV_OPTION
-                       if (ic_ndx)
+                       if (unsort_ndx)
                                prev = F_NDX(file);
                        else
-#endif
                                prev = ndx_list[from] + hlink_flist->ndx_start;
                        SIVAL(node->data, 1, prev);
                }
@@ -180,23 +175,25 @@ static void match_gnums(int32 *ndx_list, int ndx_count)
  * to first when we're done. */
 void match_hard_links(struct file_list *flist)
 {
-       int i, ndx_count = 0;
-       int32 *ndx_list;
+       if (!list_only) {
+               int i, ndx_count = 0;
+               int32 *ndx_list;
 
-       if (!(ndx_list = new_array(int32, flist->used)))
-               out_of_memory("match_hard_links");
+               if (!(ndx_list = new_array(int32, flist->used)))
+                       out_of_memory("match_hard_links");
 
-       for (i = 0; i < flist->used; i++) {
-               if (F_IS_HLINKED(flist->sorted[i]))
-                       ndx_list[ndx_count++] = i;
-       }
+               for (i = 0; i < flist->used; i++) {
+                       if (F_IS_HLINKED(flist->sorted[i]))
+                               ndx_list[ndx_count++] = i;
+               }
 
-       hlink_flist = flist;
+               hlink_flist = flist;
 
-       if (ndx_count)
-               match_gnums(ndx_list, ndx_count);
+               if (ndx_count)
+                       match_gnums(ndx_list, ndx_count);
 
-       free(ndx_list);
+               free(ndx_list);
+       }
        if (protocol_version < 30)
                idev_destroy();
 }
@@ -223,7 +220,7 @@ static int maybe_hard_link(struct file_struct *file, int ndx,
                        if (!make_backup(fname))
                                return -1;
                } else if (robust_unlink(fname)) {
-                       rsyserr(FERROR, errno, "unlink %s failed",
+                       rsyserr(FERROR_XFER, errno, "unlink %s failed",
                                full_fname(fname));
                        return -1;
                }
@@ -278,13 +275,13 @@ int hard_link_check(struct file_struct *file, int ndx, const char *fname,
        if (!prev_name) {
                struct file_struct *prev_file = flist->files[prev_ndx - flist->ndx_start];
 
-               /* Is the previous link is not complete yet? */
+               /* Is the previous link not complete yet? */
                if (!(prev_file->flags & FLAG_HLINK_DONE)) {
                        /* Is the previous link being transferred? */
                        if (prev_file->flags & FLAG_FILE_SENT) {
-                               /* Add ourselves to the list of files that will be
-                                * updated when the transfer completes, and mark
-                                * ourself as waiting for the transfer. */
+                               /* Add ourselves to the list of files that will
+                                * be updated when the transfer completes, and
+                                * mark ourself as waiting for the transfer. */
                                F_HL_PREV(file) = F_HL_PREV(prev_file);
                                F_HL_PREV(prev_file) = ndx;
                                file->flags |= FLAG_FILE_SENT;
@@ -323,7 +320,7 @@ int hard_link_check(struct file_struct *file, int ndx, const char *fname,
        }
 
        if (link_stat(prev_name, &prev_st, 0) < 0) {
-               rsyserr(FERROR, errno, "stat %s failed",
+               rsyserr(FERROR_XFER, errno, "stat %s failed",
                        full_fname(prev_name));
                return -1;
        }
@@ -345,7 +342,8 @@ int hard_link_check(struct file_struct *file, int ndx, const char *fname,
                                 || prev_st.st_ino != alt_sx.st.st_ino)
                                        continue;
                                statret = 1;
-                               if (verbose < 2 || !stdout_format_has_i) {
+                               if (stdout_format_has_i == 0
+                                || (verbose < 2 && stdout_format_has_i < 2)) {
                                        itemizing = 0;
                                        code = FNONE;
                                        if (verbose > 1 && maybe_ATTRS_REPORT)
@@ -398,7 +396,7 @@ int hard_link_one(struct file_struct *file, const char *fname,
                                return -1;
                        code = FINFO;
                } else
-                       code = FERROR;
+                       code = FERROR_XFER;
                rsyserr(code, errno, "link %s => %s failed",
                        full_fname(fname), oldname);
                return 0;
@@ -422,7 +420,7 @@ void finish_hard_link(struct file_struct *file, const char *fname, int fin_ndx,
 
        if (stp == NULL && prev_ndx >= 0) {
                if (link_stat(fname, &st, 0) < 0) {
-                       rsyserr(FERROR, errno, "stat %s failed",
+                       rsyserr(FERROR_XFER, errno, "stat %s failed",
                                full_fname(fname));
                        return;
                }