Fix a bug that prevented the restoration of hard links to files that

had the schg flag set.  Reported by Matthew Thyer <thyerm@camtech.net.au>.
This commit is contained in:
John Polstra 1998-07-09 03:57:26 +00:00
parent 4ec1acf055
commit adb915cb28
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=37523

View File

@ -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);