Improve make_path() error return for non-dir element.
authorWayne Davison <wayned@samba.org>
Mon, 24 Aug 2015 03:52:59 +0000 (20:52 -0700)
committerWayne Davison <wayned@samba.org>
Mon, 24 Aug 2015 04:55:16 +0000 (21:55 -0700)
util.c

diff --git a/util.c b/util.c
index 0775add81292c05ceb2b11c8307e77e9c7bb3f3a..c0e239d4ae4e3b75a8c18c18d7292b8c4e4138e8 100644 (file)
--- 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;
                }