From 63bd650f4b966e560784b39b77c10263c4f7b555 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Tue, 20 Jun 2017 20:46:08 +0000 Subject: [PATCH] ln(1): fix -F behavior When '-F' option is used, the target directory needs to be unlinked. Currently, the modified target ("target/source") is being unlinked, and since it doesn't yet exist, the original target isn't removed. This is fixed by skipping the block where target is modified to "target/source" when '-F' option is set. Hence, a symbolic link (with the same name as of the original target) to the source_file is produced. Update the test for ln(1) to reflect fix for option '-F' MFC after: 1 month PR: 219943 Differential Revision: D11167 Submitted by: shivansh Sponsored by: Google (GSoC 2017) --- bin/ln/ln.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/ln/ln.c b/bin/ln/ln.c index 70867f6569d4..04fb492ab5fe 100644 --- a/bin/ln/ln.c +++ b/bin/ln/ln.c @@ -245,11 +245,11 @@ linkit(const char *source, const char *target, int isdir) /* * If the target is a directory (and not a symlink if hflag), - * append the source's name. + * append the source's name, unless Fflag is set. */ - if (isdir || + if (!Fflag && (isdir || (lstat(target, &sb) == 0 && S_ISDIR(sb.st_mode)) || - (!hflag && stat(target, &sb) == 0 && S_ISDIR(sb.st_mode))) { + (!hflag && stat(target, &sb) == 0 && S_ISDIR(sb.st_mode)))) { if (strlcpy(bbuf, source, sizeof(bbuf)) >= sizeof(bbuf) || (p = basename(bbuf)) == NULL || snprintf(path, sizeof(path), "%s/%s", target, p) >=