Fix "install -dm 02750 directory" and add tests.

This commit is contained in:
Rob Landley 2024-03-22 02:59:53 -05:00
parent 896bb66a6d
commit 39dea7710f
2 changed files with 11 additions and 1 deletions

View File

@ -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' '' ''

View File

@ -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;