ln: allow dangling symlinks

This commit is contained in:
Eivind Uggedal 2015-06-05 11:11:09 +00:00 committed by sin
parent d383612450
commit 9e04a4fcdc

5
ln.c
View File

@ -65,6 +65,7 @@ main(int argc, char *argv[])
if (!hastarget) if (!hastarget)
target = basename(*argv); target = basename(*argv);
if (!sflag) {
if (stat(*argv, &st) < 0) { if (stat(*argv, &st) < 0) {
weprintf("stat %s:", *argv); weprintf("stat %s:", *argv);
ret = 1; ret = 1;
@ -76,10 +77,12 @@ main(int argc, char *argv[])
continue; continue;
} }
} else if (st.st_dev == tst.st_dev && st.st_ino == tst.st_ino) { } else if (st.st_dev == tst.st_dev && st.st_ino == tst.st_ino) {
weprintf("%s and %s/%s are the same file\n", *argv, targetdir, target); weprintf("%s and %s/%s are the same file\n",
*argv, targetdir, target);
ret = 1; ret = 1;
continue; continue;
} }
}
if (fflag && unlinkat(dirfd, target, 0) < 0 && errno != ENOENT) { if (fflag && unlinkat(dirfd, target, 0) < 0 && errno != ENOENT) {
weprintf("unlinkat %s %s:", targetdir, target); weprintf("unlinkat %s %s:", targetdir, target);