From: Timo Sirainen Date: Tue, 21 Mar 2023 21:08:12 +0000 (+0200) Subject: lib-dict-extra: dict-fs - Implement DICT_ITERATE_FLAG_EXACT_KEY X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f18469c3af7f766c1aaf280cb3ca6711ccfc42c7;p=thirdparty%2Fdovecot%2Fcore.git lib-dict-extra: dict-fs - Implement DICT_ITERATE_FLAG_EXACT_KEY --- diff --git a/src/lib-dict-extra/dict-fs.c b/src/lib-dict-extra/dict-fs.c index b83f657045..43178c837e 100644 --- a/src/lib-dict-extra/dict-fs.c +++ b/src/lib-dict-extra/dict-fs.c @@ -17,6 +17,7 @@ struct fs_dict_iterate_context { struct dict_iterate_context ctx; char *path; enum dict_iterate_flags flags; + unsigned int key_count; pool_t value_pool; struct fs_iter *fs_iter; const char *values[2]; @@ -156,7 +157,6 @@ fs_dict_iterate_init(struct dict *_dict, const struct dict_op_settings *set, /* these flags are not supported for now */ i_assert((flags & DICT_ITERATE_FLAG_RECURSE) == 0); - i_assert((flags & DICT_ITERATE_FLAG_EXACT_KEY) == 0); i_assert((flags & (DICT_ITERATE_FLAG_SORT_BY_KEY | DICT_ITERATE_FLAG_SORT_BY_VALUE)) == 0); @@ -178,12 +178,25 @@ static bool fs_dict_iterate(struct dict_iterate_context *ctx, const char *path, *error; int ret; - if (iter->error != NULL) + if (iter->error != NULL || iter->fs_iter == NULL) return FALSE; *key_r = fs_iter_next(iter->fs_iter); - if (*key_r == NULL) - return FALSE; + if (*key_r == NULL) { + if (iter->key_count > 0 || + (iter->flags & DICT_ITERATE_FLAG_EXACT_KEY) == 0) + return FALSE; + + if (fs_iter_deinit(&iter->fs_iter, &error) == 0) + return FALSE; + if (errno != ENOTDIR) { + iter->error = i_strdup(error); + return FALSE; + } + /* the path itself is the only key we are going to return */ + *key_r = ""; + } + iter->key_count++; path = t_strconcat(iter->path, *key_r, NULL); if ((iter->flags & DICT_ITERATE_FLAG_NO_VALUE) != 0) {