From 51cc908ee40615b6bb162674f2466cb5b8795c57 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 25 Sep 2019 16:07:21 -0500 Subject: Add ln -T --- toys/posix/ln.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'toys/posix') diff --git a/toys/posix/ln.c b/toys/posix/ln.c index 7f635402..fb47e911 100644 --- a/toys/posix/ln.c +++ b/toys/posix/ln.c @@ -4,7 +4,7 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/ln.html -USE_LN(NEWTOY(ln, "<1vnfs", TOYFLAG_BIN)) +USE_LN(NEWTOY(ln, "<1Tvnfs", TOYFLAG_BIN)) config LN bool "ln" @@ -13,11 +13,12 @@ config LN usage: ln [-sfnv] [FROM...] TO Create a link between FROM and TO. - With only one argument, create link in current directory. + One/two/many arguments work like "mv" or "cp". -s Create a symbolic link -f Force the creation of the link, even if TO already exists - -n Symlink at destination treated as file + -n Symlink at TO treated as file + -T TO always treated as file -v Verbose */ @@ -37,11 +38,12 @@ void ln_main(void) } // Is destination a directory? - if ((FLAG(n) ? lstat : stat)(dest, &buf) || !S_ISDIR(buf.st_mode)) - { - if (toys.optc>1) error_exit("'%s' not a directory", dest); - buf.st_mode = 0; - } + if (!((FLAG(n)||FLAG(T)) ? lstat : stat)(dest, &buf)) { + i = S_ISDIR(buf.st_mode); + + if ((FLAG(T) && i) || (!i && toys.optc>1)) + error_exit("'%s' %s a directory", dest, i ? "is" : "not"); + } else buf.st_mode = 0; for (i=0; i