Added: -T Replaced: & flag_# with FLAG(#) There was feature request on github. Apparently there is some android scripts with ln -sfT
-Jarno
From ed03f8cdeb5560b9ac7dd40d1ce1ef061b47ab77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarno=20M=C3=A4kip=C3=A4=C3=A4?= <[email protected]> Date: Wed, 25 Sep 2019 23:08:43 +0300 Subject: [PATCH] ln: add -T, use FLAG() Added: -T Replaced: & flag_# with FLAG(#) There was feature request on github. Apparently there is some android scripts with ln -sfT --- toys/posix/ln.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/toys/posix/ln.c b/toys/posix/ln.c index 06700dd0..7d5ade99 100644 --- a/toys/posix/ln.c +++ b/toys/posix/ln.c @@ -4,13 +4,13 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/ln.html -USE_LN(NEWTOY(ln, "<1vnfs", TOYFLAG_BIN)) +USE_LN(NEWTOY(ln, "<1vnfsT", TOYFLAG_BIN)) config LN bool "ln" default y help - usage: ln [-sfnv] [FROM...] TO + usage: ln [-sfnvT] [FROM...] TO Create a link between FROM and TO. With only one argument, create link in current directory. @@ -19,6 +19,7 @@ config LN -f Force the creation of the link, even if TO already exists -n Symlink at destination treated as file -v Verbose + -T No target directory */ #define FOR_ln @@ -35,9 +36,12 @@ void ln_main(void) toys.optc++; dest="."; } - // Is destination a directory? - if (((toys.optflags&FLAG_n) ? lstat : stat)(dest, &buf) + if (FLAG(T)) { + lstat(dest, &buf); + if (S_ISDIR(buf.st_mode)) error_exit("'%s' is a directory", dest); + + } else if (((FLAG(n)) ? lstat : stat)(dest, &buf) || !S_ISDIR(buf.st_mode)) { if (toys.optc>1) error_exit("'%s' not a directory", dest); @@ -55,7 +59,7 @@ void ln_main(void) // a temp version and renaming it over the old one, so we can retain the // old file in cases we can't replace it (such as hardlink between mounts). oldnew = new; - if (toys.optflags & FLAG_f) { + if (FLAG(f)) { new = xmprintf("%s_XXXXXX", new); rc = mkstemp(new); if (rc >= 0) { @@ -64,8 +68,8 @@ void ln_main(void) } } - rc = (toys.optflags & FLAG_s) ? symlink(try, new) : link(try, new); - if (toys.optflags & FLAG_f) { + rc = (FLAG(s)) ? symlink(try, new) : link(try, new); + if (FLAG(f)) { if (!rc) { int temp; @@ -79,9 +83,9 @@ void ln_main(void) } if (rc) perror_msg("cannot create %s link from '%s' to '%s'", - (toys.optflags & FLAG_s) ? "symbolic" : "hard", try, new); + (FLAG(s)) ? "symbolic" : "hard", try, new); else - if (toys.optflags & FLAG_v) fprintf(stderr, "'%s' -> '%s'\n", new, try); + if (FLAG(v)) fprintf(stderr, "'%s' -> '%s'\n", new, try); if (new != dest) free(new); } -- 2.19.1
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
