ln: allow dangling symlinks
This commit is contained in:
parent
d383612450
commit
9e04a4fcdc
25
ln.c
25
ln.c
@ -65,20 +65,23 @@ main(int argc, char *argv[])
|
|||||||
if (!hastarget)
|
if (!hastarget)
|
||||||
target = basename(*argv);
|
target = basename(*argv);
|
||||||
|
|
||||||
if (stat(*argv, &st) < 0) {
|
if (!sflag) {
|
||||||
weprintf("stat %s:", *argv);
|
if (stat(*argv, &st) < 0) {
|
||||||
ret = 1;
|
weprintf("stat %s:", *argv);
|
||||||
continue;
|
ret = 1;
|
||||||
} else if (fstatat(dirfd, target, &tst, AT_SYMLINK_NOFOLLOW) < 0) {
|
continue;
|
||||||
if (errno != ENOENT) {
|
} else if (fstatat(dirfd, target, &tst, AT_SYMLINK_NOFOLLOW) < 0) {
|
||||||
weprintf("fstatat %s %s:", targetdir, target);
|
if (errno != ENOENT) {
|
||||||
|
weprintf("fstatat %s %s:", targetdir, target);
|
||||||
|
ret = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} 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);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} 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);
|
|
||||||
ret = 1;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fflag && unlinkat(dirfd, target, 0) < 0 && errno != ENOENT) {
|
if (fflag && unlinkat(dirfd, target, 0) < 0 && errno != ENOENT) {
|
||||||
|
Loading…
Reference in New Issue
Block a user