[Toybox] [PATCH] mkpathat: return EEXIST only if MKPATHAT_MKLAST is given
Yi-Yo Chiang
yochiang at google.com
Sun Feb 7 08:07:10 PST 2021
There was a regression:
$ mkdir a
$ touch a/b
Calling mkpath("a/b") would return an error with EEXIST errno. This is
because "a/b" is a regular file. However mkpath() should only create the
leading directories of "a/b", which is "a/", which shouldn't be an error
because attempting to create an already existed directory shouldn't fail.
---
lib/lib.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/lib.c b/lib/lib.c
index dfa4499f..76726931 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -177,7 +177,8 @@ 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)) {
+ if (flags&MKPATHAT_MKLAST && !fstatat(atfd, dir, &buf, 0)
+ && !S_ISDIR(buf.st_mode)) {
errno = EEXIST;
return 1;
}
--
2.30.0.478.g8a0d178c01-goog
More information about the Toybox
mailing list