Skip to content

Commit

Permalink
Add install -t
Browse files Browse the repository at this point in the history
  • Loading branch information
landley committed Feb 10, 2021
1 parent 4775535 commit 3d5cb06
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions toys/posix/cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
USE_CP(NEWTOY(cp, "<2(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))
USE_INSTALL(NEWTOY(install, "<1cdDpsvt:m:o:g:", TOYFLAG_USR|TOYFLAG_BIN))
config CP
bool "cp"
Expand Down Expand Up @@ -71,7 +71,7 @@ config INSTALL
bool "install"
default y
help
usage: install [-dDpsv] [-o USER] [-g GROUP] [-m MODE] [SOURCE...] DEST
usage: install [-dDpsv] [-o USER] [-g GROUP] [-m MODE] [-t TARGET] [SOURCE...] DEST
Copy files and set attributes.
Expand All @@ -82,6 +82,7 @@ config INSTALL
-o Make copy belong to USER
-p Preserve timestamps
-s Call "strip -p"
-t Copy files to TARGET dir (no DEST)
-v Verbose
*/

Expand All @@ -93,7 +94,7 @@ GLOBALS(
union {
// install's options
struct {
char *g, *o, *m;
char *g, *o, *m, *t;
} i;
// cp's options
struct {
Expand Down Expand Up @@ -359,15 +360,15 @@ static int cp_node(struct dirtree *try)

void cp_main(void)
{
char *destname = toys.optargs[--toys.optc];
char *destname = TT.i.t ? : 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)
if ((toys.optc>1 || FLAG(D) || TT.i.t) && !destdir)
error_exit("'%s' not directory", destname);

if (FLAG(a)||FLAG(p)) TT.pflags = _CP_mode|_CP_ownership|_CP_timestamps;
Expand Down

0 comments on commit 3d5cb06

Please sign in to comment.