From 39dea7710fa49adf4d255956c32e19a9f90afc98 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 22 Mar 2024 02:59:53 -0500 Subject: [PATCH] Fix "install -dm 02750 directory" and add tests. --- tests/install.test | 7 +++++++ toys/posix/cp.c | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/install.test b/tests/install.test index b1113c0f..2f10f753 100755 --- a/tests/install.test +++ b/tests/install.test @@ -17,3 +17,10 @@ testing "install -D -t creates directory" \ "touch a; install -Dt b a && echo yes" \ "yes\n" "" "" rm -rf a b + +testing "install -d" "umask 0 && install -d potato && stat -c%a potato" \ + "755\n" "" "" +rmdir potato +testcmd "-dm" "-dm 02750 potato && stat -c%a potato" "2750\n" "" "" +rmdir potato +testcmd '' '-dm +x potato && stat -c%a potato' '111\n' '' '' diff --git a/toys/posix/cp.c b/toys/posix/cp.c index 0467027a..3306c49f 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -515,12 +515,15 @@ void install_main(void) TT.gid = TT.i.g ? xgetgid(TT.i.g) : -1; if (FLAG(d)) { + int mode = TT.i.m ? string_to_mode(TT.i.m, 0) : 0755; + for (ss = toys.optargs; *ss; ss++) { if (FLAG(v)) printf("%s\n", *ss); - if (mkpathat(AT_FDCWD, *ss, 0777, MKPATHAT_MKLAST | MKPATHAT_MAKE)) + if (mkpathat(AT_FDCWD, *ss, mode, MKPATHAT_MKLAST | MKPATHAT_MAKE)) perror_msg_raw(*ss); if (FLAG(g)||FLAG(o)) if (lchown(*ss, TT.uid, TT.gid)) perror_msg("chown '%s'", *ss); + if ((mode&~01777) && chmod(*ss, mode)) perror_msg("chmod '%s'", *ss); } return; -- 2.39.2