]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Split off path_get_parent_dir()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 18 Feb 2022 10:11:53 +0000 (12:11 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 25 Feb 2022 19:44:45 +0000 (19:44 +0000)
src/lib-storage/list/mailbox-list-fs.c

index c1aabb9ce1931a784a548e4c670389e30673ad22..be8277b8a15de1a7d48834627f5df188ed99eb1d 100644 (file)
@@ -353,6 +353,12 @@ static int fs_list_delete_dir(struct mailbox_list *list, const char *name)
        return -1;
 }
 
+static const char *path_get_parent_dir(const char *path)
+{
+       const char *p = strrchr(path, '/');
+       return p == NULL ? "/" : t_strdup_until(path, p);
+}
+
 static int rename_dir(struct mailbox_list *oldlist, const char *oldname,
                      struct mailbox_list *newlist, const char *newname,
                      enum mailbox_list_path_type type, bool rmdir_parent)
@@ -367,10 +373,8 @@ static int rename_dir(struct mailbox_list *oldlist, const char *oldname,
        if (strcmp(oldpath, newpath) == 0)
                return 0;
 
-       p = strrchr(oldpath, '/');
-       oldparent = p == NULL ? "/" : t_strdup_until(oldpath, p);
-       p = strrchr(newpath, '/');
-       newparent = p == NULL ? "/" : t_strdup_until(newpath, p);
+       oldparent = path_get_parent_dir(oldpath);
+       newparent = path_get_parent_dir(newpath);
 
        if (strcmp(oldparent, newparent) != 0 && stat(oldpath, &st) == 0) {
                /* make sure the newparent exists */