aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2021-02-08 01:50:28 -0600
committerRob Landley <rob@landley.net>2021-02-08 01:50:28 -0600
commitbdb0e5fd6e031f9b3fae95d8180cf6bba32384c8 (patch)
treef147c56ccd305be446dd9780fe3e6c8f0d26d124
parenta4b84d92d9016dc8460255b954ffbd04d5ff6b92 (diff)
downloadtoybox-bdb0e5fd6e031f9b3fae95d8180cf6bba32384c8.tar.gz
Yi-Yo Chiang pointed out install -D was broken when the target file exists.
Add a test, with comment that "make install_test" doesn't currently exist...
-rw-r--r--lib/lib.c8
-rwxr-xr-xtests/install.test15
2 files changed, 20 insertions, 3 deletions
diff --git a/lib/lib.c b/lib/lib.c
index de67efa2..06e39169 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -177,9 +177,11 @@ int mkpathat(int atfd, char *dir, mode_t lastmode, int flags)
// not-a-directory along the way, but the last one we must explicitly
// test for. Might as well do it up front.
- if (!fstatat(atfd, dir, &buf, 0) && !S_ISDIR(buf.st_mode)) {
- errno = EEXIST;
- return 1;
+ if (!fstatat(atfd, dir, &buf, 0)) {
+ if ((flags&MKPATHAT_MKLAST) && !S_ISDIR(buf.st_mode)) {
+ errno = EEXIST;
+ return 1;
+ } else return 0;
}
for (s = dir; ;s++) {
diff --git a/tests/install.test b/tests/install.test
new file mode 100755
index 00000000..228d2470
--- /dev/null
+++ b/tests/install.test
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+# TODO: fill this out.
+# TODO: "make install" means something else, so no test_install, only callable
+# from "make tests"...
+
+[ -f testing.sh ] && . testing.sh
+
+#testing "name" "command" "result" "infile" "stdin"
+
+dd if=/dev/urandom of=random bs=64 count=1 2> /dev/null
+testing "install -D exists" \
+ "mkdir -p a; touch a/b; install -D random a/b && cmp random a/b && echo yes" \
+ "yes\n" "" ""
+rm -rf a random