X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/9935066b704bcf2e6e48dac85cb1b4047d8f439d..a41a1e87182410ec6c2eeaddb0cd961ec554c404:/hlink.c diff --git a/hlink.c b/hlink.c index f42df53d..1a489c27 100644 --- a/hlink.c +++ b/hlink.c @@ -22,6 +22,7 @@ extern int dry_run; extern int verbose; +extern int make_backups; #if SUPPORT_HARD_LINKS static int hlink_compare(struct file_struct **file1, struct file_struct **file2) @@ -38,8 +39,8 @@ static int hlink_compare(struct file_struct **file1, struct file_struct **file2) return file_compare(file1, file2); } -struct file_struct **hlink_list; -int hlink_count; +static struct file_struct **hlink_list; +static int hlink_count; #define LINKED(p1,p2) ((p1)->F_DEV == (p2)->F_DEV \ && (p1)->F_INODE == (p2)->F_INODE) @@ -134,7 +135,8 @@ void init_hard_links(struct file_list *flist) int hard_link_check(struct file_struct *file, int skip) { - if (!file->link_u.links) +#if SUPPORT_HARD_LINKS + if (!hlink_list || !file->link_u.links) return 0; if (skip && !(file->flags & FLAG_HLINK_EOL)) hlink_list[file->F_HLINDEX] = file->F_NEXT; @@ -145,6 +147,7 @@ int hard_link_check(struct file_struct *file, int skip) } return 1; } +#endif return 0; } @@ -153,8 +156,8 @@ static void hard_link_one(char *hlink1, char *hlink2) { if (do_link(hlink1, hlink2)) { if (verbose) { - rprintf(FINFO, "link %s => %s failed: %s\n", - hlink2, hlink1, strerror(errno)); + rsyserr(FINFO, errno, "link %s => %s failed", + hlink2, hlink1); } } else if (verbose) @@ -182,20 +185,22 @@ void do_hard_links(void) for (i = 0; i < hlink_count; i++) { first = file = hlink_list[i]; - if (link_stat(f_name_to(first, hlink1), &st1) != 0) + if (link_stat(f_name_to(first, hlink1), &st1, 0) < 0) continue; while ((file = file->F_NEXT) != first) { hlink2 = f_name(file); - if (link_stat(hlink2, &st2) == 0) { + if (link_stat(hlink2, &st2, 0) == 0) { if (st2.st_dev == st1.st_dev && st2.st_ino == st1.st_ino) continue; - if (robust_unlink(hlink2)) { + if (make_backups) { + if (!make_backup(hlink2)) + continue; + } else if (robust_unlink(hlink2)) { if (verbose > 0) { - rprintf(FINFO, - "unlink %s failed: %s\n", - full_fname(hlink2), - strerror(errno)); + rsyserr(FINFO, errno, + "unlink %s failed", + full_fname(hlink2)); } continue; }