From 9d1cd2437c81dadb5d1a7eff2cec0c529d10289a Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Sun, 23 Aug 2015 20:52:59 -0700 Subject: [PATCH] Improve make_path() error return for non-dir element. --- util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util.c b/util.c index 0775add8..c0e239d4 100644 --- a/util.c +++ b/util.c @@ -190,7 +190,7 @@ int make_path(char *fname, int flags) if (flags & MKP_DROP_NAME) { end = strrchr(fname, '/'); - if (!end) + if (!end || end == fname) return 0; *end = '\0'; } else @@ -210,8 +210,10 @@ int make_path(char *fname, int flags) ret++; break; } + if (errno != ENOENT) { - if (errno != EEXIST) + STRUCT_STAT st; + if (errno != EEXIST || (do_stat(fname, &st) == 0 && !S_ISDIR(st.st_mode))) ret = -ret - 1; break; } -- 2.47.2