]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Use stat_first_parent() instead of doing it ourself.
authorTimo Sirainen <tss@iki.fi>
Thu, 13 Dec 2012 10:14:03 +0000 (12:14 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 13 Dec 2012 10:14:03 +0000 (12:14 +0200)
src/lib-storage/mailbox-list.c

index e18b0126d8c45603507b04369dddd900bed2a9d6..84bd8ca13f94a042f3db79393a2629cfdad07a14 100644 (file)
@@ -765,27 +765,6 @@ void mailbox_list_get_root_permissions(struct mailbox_list *list,
        }
 }
 
-static int
-mailbox_list_stat_parent(const char *path, const char **root_dir_r,
-                        struct stat *st_r, const char **error_r)
-{
-       const char *p;
-
-       while (stat(path, st_r) < 0) {
-               if (errno != ENOENT || strcmp(path, "/") == 0) {
-                       *error_r = t_strdup_printf("stat(%s) failed: %m", path);
-                       return -1;
-               }
-               p = strrchr(path, '/');
-               if (p == NULL)
-                       path = "/";
-               else
-                       path = t_strdup_until(path, p);
-       }
-       *root_dir_r = path;
-       return 0;
-}
-
 static const char *
 get_expanded_path(const char *unexpanded_start, const char *unexpanded_stop,
                  const char *expanded_full)
@@ -873,9 +852,10 @@ int mailbox_list_mkdir_root(struct mailbox_list *list, const char *path,
                /* up to this directory get the permissions from the first
                   parent directory that exists, if it has setgid bit
                   enabled. */
-               if (mailbox_list_stat_parent(expanded, &root_dir, &st,
-                                            error_r) < 0)
+               if (stat_first_parent(expanded, &root_dir, &st) < 0) {
+                       *error_r = t_strdup_printf("stat(%s) failed: %m", root_dir);
                        return -1;
+               }
                if ((st.st_mode & S_ISGID) != 0 && root_dir != expanded) {
                        if (mkdir_parents_chgrp(expanded, st.st_mode,
                                                (gid_t)-1, root_dir) < 0 &&