aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-09-25 16:07:21 -0500
committerRob Landley <rob@landley.net>2019-09-25 16:07:21 -0500
commit51cc908ee40615b6bb162674f2466cb5b8795c57 (patch)
tree24e422ca45bbb2c10bf444373209d11930280f79 /toys
parent0489bdd7da194cc8224910b0d8ba09ba19490815 (diff)
downloadtoybox-51cc908ee40615b6bb162674f2466cb5b8795c57.tar.gz
Add ln -T
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/ln.c18
1 files changed, 10 insertions, 8 deletions
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<toys.optc; i++) {
int rc;