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...)
---
tests/cp.test | 7 +++++++
toys/posix/cp.c | 31 +++++++++++++++++++------------
2 files changed, 26 insertions(+), 12 deletions(-)
From 26e6a4c4e734e59a4adafaa615de0e5421b525d0 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Thu, 23 Jan 2020 19:18:32 -0800
Subject: [PATCH] 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...)
---
tests/cp.test | 7 +++++++
toys/posix/cp.c | 31 +++++++++++++++++++------------
2 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/tests/cp.test b/tests/cp.test
index b665e47e..dfb80ea1 100755
--- a/tests/cp.test
+++ b/tests/cp.test
@@ -113,6 +113,13 @@ testing "duplicated --preserve options" \
"cp --preserve=mode,mode walrus walrus2 2>&1 || echo bad" "" "" ""
rm -rf walrus woot carpenter
+mkdir dir
+echo a > file
+echo b > b
+testing "-T file" "cp -T b file && cat file" "b\n" "" ""
+testing "-T dir" "cp -T b dir 2>/dev/null || echo expected" "expected\n" "" ""
+rm b file
+
# cp -r ../source destdir
# cp -r one/two/three missing
# cp -r one/two/three two
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);
--
2.25.0.341.g760bfbb309-goog
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net