aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-01-23 19:18:32 -0800
committerRob Landley <rob@landley.net>2020-01-24 05:57:53 -0600
commit51442ce32e99c28fbbd74305e6a8b8e5686293c0 (patch)
treee6d5661e2a10cadcd7cb478fb18f41f97a56b2ab /toys
parent898a25b85144d11b4e31109c35ecc51ea027791d (diff)
downloadtoybox-51442ce32e99c28fbbd74305e6a8b8e5686293c0.tar.gz
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...)
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/cp.c31
1 files changed, 19 insertions, 12 deletions
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);