Handle ln -sf a foo/ correctly

Previously it would not delete foo/a if it already existed.  Use
unlinkat() instead to do that.
This commit is contained in:
sin 2015-01-22 16:26:30 +00:00
parent 3946d1fcc9
commit d475a6bdf2
1 changed files with 1 additions and 1 deletions

2
ln.c
View File

@ -67,7 +67,7 @@ main(int argc, char *argv[])
if (!hasto)
to = basename(argv[0]);
if (fflag)
remove(to);
unlinkat(dirfd, to, 0);
if ((!sflag ? linkat(AT_FDCWD, argv[0], dirfd, to, flags)
: symlinkat(argv[0], dirfd, to)) < 0) {
eprintf("%s %s <- %s:", fname, argv[0], to);