From adb915cb280cdc76d25ef1fcdef56caf79b49993 Mon Sep 17 00:00:00 2001 From: John Polstra Date: Thu, 9 Jul 1998 03:57:26 +0000 Subject: [PATCH] Fix a bug that prevented the restoration of hard links to files that had the schg flag set. Reported by Matthew Thyer . --- sbin/restore/utilities.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/sbin/restore/utilities.c b/sbin/restore/utilities.c index 3232b9b2e9dd..265b596f8721 100644 --- a/sbin/restore/utilities.c +++ b/sbin/restore/utilities.c @@ -218,11 +218,26 @@ linkit(existing, new, type) return (FAIL); } } else if (type == HARDLINK) { - if (!Nflag && link(existing, new) < 0) { - fprintf(stderr, - "warning: cannot create hard link %s->%s: %s\n", - new, existing, strerror(errno)); - return (FAIL); + int ret; + + if (!Nflag && (ret = link(existing, new)) < 0) { + struct stat s; + + /* + * Most likely, the schg flag is set. Clear the + * flags and try again. + */ + if (stat(existing, &s) == 0 && s.st_flags != 0 && + chflags(existing, 0) == 0) { + ret = link(existing, new); + chflags(existing, s.st_flags); + } + if (ret < 0) { + fprintf(stderr, "warning: cannot create " + "hard link %s->%s: %s\n", + new, existing, strerror(errno)); + return (FAIL); + } } } else { panic("linkit: unknown type %d\n", type);