From 51442ce32e99c28fbbd74305e6a8b8e5686293c0 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 23 Jan 2020 19:18:32 -0800 Subject: cp/mv: add -T. The kernel script scripts/kconfig/merge_config.sh uses cp -T. (Also sort the options into alphabetical order while adding -T, so that eyeball binary search actually works when trying to find an option! Oddly, they all show in reverse order because there's a bug in the help text generator, but that's a problem for another day...) --- toys/posix/cp.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'toys') diff --git a/toys/posix/cp.c b/toys/posix/cp.c index f6ffaf10..13bfd7ef 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -15,34 +15,35 @@ // options shared between mv/cp must be in same order (right to left) // for FLAG macros to work out right in shared infrastructure. -USE_CP(NEWTOY(cp, "<2"USE_CP_PRESERVE("(preserve):;")"D(parents)RHLPprdaslvnF(remove-destination)fi[-HLPd][-ni]", TOYFLAG_BIN)) -USE_MV(NEWTOY(mv, "<2vnF(remove-destination)fi[-ni]", TOYFLAG_BIN)) +USE_CP(NEWTOY(cp, "<2"USE_CP_PRESERVE("(preserve):;")"D(parents)RHLPprdaslvnF(remove-destination)fiT[-HLPd][-ni]", TOYFLAG_BIN)) +USE_MV(NEWTOY(mv, "<2vnF(remove-destination)fiT[-ni]", TOYFLAG_BIN)) USE_INSTALL(NEWTOY(install, "<1cdDpsvm:o:g:", TOYFLAG_USR|TOYFLAG_BIN)) config CP bool "cp" default y help - usage: cp [-adlnrsvfipRHLP] SOURCE... DEST + usage: cp [-adfHiLlnPpRrsTv] SOURCE... DEST Copy files from SOURCE to DEST. If more than one SOURCE, DEST must be a directory. + -a Same as -dpr -D Create leading dirs under DEST (--parents) - -f Delete destination files we can't write to + -d Don't dereference symlinks -F Delete any existing destination file first (--remove-destination) - -i Interactive, prompt before overwriting existing DEST - -p Preserve timestamps, ownership, and mode - -R Recurse into subdirectories (DEST must be a directory) + -f Delete destination files we can't write to -H Follow symlinks listed on command line + -i Interactive, prompt before overwriting existing DEST -L Follow all symlinks - -P Do not follow symlinks [default] - -a Same as -dpr - -d Don't dereference symlinks -l Hard link instead of copy -n No clobber (don't overwrite DEST) + -P Do not follow symlinks [default] + -p Preserve timestamps, ownership, and mode + -R Recurse into subdirectories (DEST must be a directory) -r Synonym for -R -s Symlink instead of copy + -T DEST always treated as file, max 2 arguments -v Verbose config CP_PRESERVE @@ -66,12 +67,13 @@ config MV bool "mv" default y help - usage: mv [-fivn] SOURCE... DEST + usage: mv [-finTv] SOURCE... DEST -f Force copy by deleting destination file -i Interactive, prompt before overwriting existing DEST - -v Verbose -n No clobber (don't overwrite DEST) + -T DEST always treated as file, max 2 arguments + -v Verbose config INSTALL bool "install" @@ -368,6 +370,11 @@ void cp_main(void) char *destname = toys.optargs[--toys.optc]; int i, destdir = !stat(destname, &TT.top) && S_ISDIR(TT.top.st_mode); + if (FLAG(T)) { + if (toys.optc>1) help_exit("Max 2 arguments"); + if (destdir) error_exit("'%s' is a directory", destname); + } + if ((toys.optc>1 || FLAG(D)) && !destdir) error_exit("'%s' not directory", destname); -- cgit v1.2.3