diff options
author | Alistair Delva <adelva@google.com> | 2019-11-20 21:27:39 +0000 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2019-11-21 15:58:58 +0000 |
commit | 169239e04d5763ef29cb18f228b489a6657dcb8d (patch) | |
tree | 91a870050f0450dc2138debcdcfc88dec82247a7 /toys/posix/ln.c | |
parent | 56af1fb2d0ee6830a77b6a9224ec0fce70734e4f (diff) | |
download | toybox-169239e04d5763ef29cb18f228b489a6657dcb8d.tar.gz |
Revert "Merge remote-tracking branch 'toybox/master' into HEAD"
0b2cfcb8fdea9673f3c2e0940f1b16d5825e16ea caused http://b/144698492.
See also
http://lists.landley.net/pipermail/toybox-landley.net/2019-November/011238.html
on the mailing list.
Bug: http://b/144698492
Change-Id: I05b95683c968070b98b5c86644620d94ebda2142
Diffstat (limited to 'toys/posix/ln.c')
-rw-r--r-- | toys/posix/ln.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/toys/posix/ln.c b/toys/posix/ln.c index 3cd5c7b8..306f0cac 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, "<1rt:Tvnfs", TOYFLAG_BIN)) +USE_LN(NEWTOY(ln, "<1t:Tvnfs", TOYFLAG_BIN)) config LN bool "ln" @@ -18,7 +18,6 @@ config LN -s Create a symbolic link -f Force the creation of the link, even if TO already exists -n Symlink at TO treated as file - -r Create relative symlink from -> to -t Create links in DIR -T TO always treated as file, max 2 arguments -v Verbose @@ -35,37 +34,30 @@ void ln_main(void) { char *dest = TT.t ? TT.t : toys.optargs[--toys.optc], *new; struct stat buf; - int i, rc; - - if (FLAG(T) && toys.optc>1) help_exit("Max 2 arguments"); + int i; // With one argument, create link in current directory. if (!toys.optc) { toys.optc++; - dest = "."; + dest="."; } + if (FLAG(T) && toys.optc>1) help_exit("Max 2 arguments"); // Is destination a directory? if (!((FLAG(n)||FLAG(T)) ? lstat : stat)(dest, &buf)) { - if ((i = S_ISDIR(buf.st_mode)) ? FLAG(T) : (toys.optc>1 || TT.t)) + i = S_ISDIR(buf.st_mode); + + if ((FLAG(T) && i) || (!i && (toys.optc>1 || TT.t))) error_exit("'%s' %s a directory", dest, i ? "is" : "not"); } else buf.st_mode = 0; for (i=0; i<toys.optc; i++) { - char *oldnew = 0, *try = toys.optargs[i]; + int rc; + char *oldnew, *try = toys.optargs[i]; if (S_ISDIR(buf.st_mode)) new = xmprintf("%s/%s", dest, basename(try)); else new = dest; - if (FLAG(r)) { - try = relative_path(new, try); - if (!try) { - if (new != dest) free(new); - continue; - } - toys.optflags |= FLAG_s; - } - // Force needs to unlink the existing target (if any). Do that by creating // 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). @@ -96,7 +88,6 @@ void ln_main(void) FLAG(s) ? "symbolic" : "hard", try, new); else if (FLAG(v)) fprintf(stderr, "'%s' -> '%s'\n", new, try); - if (try != toys.optargs[i]) free(try); if (new != dest) free(new); } } |