]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add mail_index_alloc_cache_find()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 13 Oct 2021 08:45:05 +0000 (11:45 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 13 Oct 2021 10:32:29 +0000 (13:32 +0300)
src/lib-index/mail-index-alloc-cache.c
src/lib-index/mail-index-alloc-cache.h

index e348fabfa70511a3e4c29aae244ba9c333ed0a07..fe52754ea5cabbdfc0f506251d6b245be9ed4c80 100644 (file)
@@ -81,8 +81,9 @@ mail_index_alloc_cache_list_free(struct mail_index_alloc_cache_list *list)
 }
 
 static struct mail_index_alloc_cache_list *
-mail_index_alloc_cache_find(const char *mailbox_path, const char *index_dir,
-                           const struct stat *index_st)
+mail_index_alloc_cache_find_and_expire(const char *mailbox_path,
+                                      const char *index_dir,
+                                      const struct stat *index_st)
 {
        struct mail_index_alloc_cache_list **indexp, *rec, *match;
        unsigned int destroy_count;
@@ -157,7 +158,8 @@ mail_index_alloc_cache_get(struct event *parent_event, const char *mailbox_path,
                }
        }
 
-       match = mail_index_alloc_cache_find(mailbox_path, index_dir, &st);
+       match = mail_index_alloc_cache_find_and_expire(mailbox_path,
+                                                      index_dir, &st);
        if (match == NULL) {
                struct mail_index *index =
                        mail_index_alloc(parent_event, index_dir, prefix);
@@ -169,6 +171,26 @@ mail_index_alloc_cache_get(struct event *parent_event, const char *mailbox_path,
        return match->index;
 }
 
+struct mail_index *
+mail_index_alloc_cache_find(const char *index_dir)
+{
+       struct mail_index_alloc_cache_list *rec;
+       struct stat st;
+
+       if (stat(index_dir, &st) < 0) {
+               if (errno != ENOENT)
+                       i_error("stat(%s) failed: %m", index_dir);
+               return NULL;
+       }
+
+       for (rec = indexes; rec != NULL; rec = rec->next) {
+               if (st.st_ino == rec->index_dir_ino &&
+                   CMP_DEV_T(st.st_dev, rec->index_dir_dev))
+                       return rec->index;
+       }
+       return NULL;
+}
+
 static bool destroy_unrefed(unsigned int min_destroy_count)
 {
        struct mail_index_alloc_cache_list **list, *rec;
index eadfc30f03d82b2bc7781edea6bfa25e7c325a3e..5f285639a054facdb5b6b2e748821b669190182b 100644 (file)
@@ -7,6 +7,10 @@ mail_index_alloc_cache_get(struct event *parent_event, const char *mailbox_path,
                           const char *index_dir, const char *prefix);
 void mail_index_alloc_cache_unref(struct mail_index **index);
 
+/* Find an existing already opened index from a given index directory. */
+struct mail_index *
+mail_index_alloc_cache_find(const char *index_dir);
+
 void mail_index_alloc_cache_destroy_unrefed(void);
 
 /* internal: */