From: Karel Zak Date: Mon, 14 Feb 2022 13:53:24 +0000 (+0100) Subject: hardlink: ignore files specified more than once X-Git-Tag: v2.38-rc2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a28d961f7045bb46effb1afe5cc8d65c9f7a289;p=thirdparty%2Futil-linux.git hardlink: ignore files specified more than once Fixes: https://github.com/util-linux/util-linux/issues/1602 Signed-off-by: Karel Zak --- diff --git a/misc-utils/hardlink.c b/misc-utils/hardlink.c index d4f3ee3a35..ebb0aba722 100644 --- a/misc-utils/hardlink.c +++ b/misc-utils/hardlink.c @@ -757,6 +757,19 @@ static int file_link(struct file *a, struct file *b, int reflink) return TRUE; } +static int has_fpath(struct file *node, const char *path) +{ + struct link *l; + + for (l = node->links; l; l = l->next) { + if (strcmp(l->path, path) == 0) + return 1; + } + + return 0; +} + + /** * inserter - Callback function for nftw() * @fpath: The path of the file being visited @@ -829,8 +842,14 @@ static int inserter(const char *fpath, const struct stat *sb, assert((*node)->st.st_dev == sb->st_dev); assert((*node)->st.st_ino == sb->st_ino); - fil->links->next = (*node)->links; - (*node)->links = fil->links; + if (has_fpath(*node, fpath)) { + jlog(JLOG_VERBOSE1, + _("Skipped %s (specified more than once)"), fpath); + free(fil->links); + } else { + fil->links->next = (*node)->links; + (*node)->links = fil->links; + } free(fil); } else {