diff options
-rw-r--r-- | toys/posix/cp.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/toys/posix/cp.c b/toys/posix/cp.c index 373ac13e..97cccb2f 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -487,9 +487,14 @@ void install_main(void) char **ss; int flags = toys.optflags; + TT.uid = TT.i.o ? xgetuid(TT.i.o) : -1; + TT.gid = TT.i.g ? xgetgid(TT.i.g) : -1; + if (flags & FLAG_d) { for (ss = toys.optargs; *ss; ss++) { if (mkpathat(AT_FDCWD, *ss, 0777, 3)) perror_msg_raw(*ss); + if (flags & (FLAG_g|FLAG_o)) + if (lchown(*ss, TT.uid, TT.gid)) perror_msg("chown '%s'", *ss); if (flags & FLAG_v) printf("%s\n", *ss); } @@ -509,9 +514,6 @@ void install_main(void) if (flags & FLAG_v) toys.optflags |= cp_flag_v(); if (flags & (FLAG_p|FLAG_o|FLAG_g)) toys.optflags |= cp_flag_p(); - if (TT.i.o) TT.uid = xgetuid(TT.i.o); - if (TT.i.g) TT.gid = xgetgid(TT.i.g); - TT.callback = install_node; cp_main(); } |