From: Timo Sirainen Date: Thu, 13 Dec 2012 10:14:03 +0000 (+0200) Subject: lib-storage: Use stat_first_parent() instead of doing it ourself. X-Git-Tag: 2.1.13~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2eb22deb4bf53ef9f40732bea9f04b842fdff15b;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Use stat_first_parent() instead of doing it ourself. --- diff --git a/src/lib-storage/mailbox-list.c b/src/lib-storage/mailbox-list.c index e18b0126d8..84bd8ca13f 100644 --- a/src/lib-storage/mailbox-list.c +++ b/src/lib-storage/mailbox-list.c @@ -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 &&