aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
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);