]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Code cleanup for reading caching decisions
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 24 Jan 2018 16:01:23 +0000 (18:01 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 29 Jan 2018 13:22:05 +0000 (15:22 +0200)
No functional changes.

src/lib-index/mail-cache-fields.c

index c0ab2ad350a4e46c395fd4fed5c5e299cd1b5bf2..ca16bb054498d29595445e1ea181f42605d634ca 100644 (file)
@@ -394,24 +394,35 @@ int mail_cache_header_fields_read(struct mail_cache *cache)
                        return -1;
                }
 
+               /* ignore any forced-flags in the file */
+               enum mail_cache_decision_type file_dec =
+                       decisions[i] & ~MAIL_CACHE_DECISION_FORCED;
+
                if (hash_table_lookup_full(cache->field_name_hash, names,
                                           &orig_key, &orig_value)) {
                        /* already exists, see if decision can be updated */
                        fidx = POINTER_CAST_TO(orig_value, unsigned int);
-                       if (!cache->fields[fidx].decision_dirty &&
-                           (cache->fields[fidx].field.decision &
-                            MAIL_CACHE_DECISION_FORCED) == 0) {
-                               cache->fields[fidx].field.decision =
-                                       decisions[i] & ~MAIL_CACHE_DECISION_FORCED;
+                       enum mail_cache_decision_type cur_dec =
+                               cache->fields[fidx].field.decision;
+                       if ((cur_dec & MAIL_CACHE_DECISION_FORCED) != 0) {
+                               /* Forced decision. */
+                       } else if (cache->fields[fidx].decision_dirty) {
+                               /* Decisions have recently been updated
+                                  internally. Don't change them. */
+                       } else {
+                               /* Use the decision from the cache file. */
+                               cache->fields[fidx].field.decision = file_dec;
                        }
                        if (field_type_verify(cache, fidx,
                                              types[i], sizes[i]) < 0)
                                return -1;
                } else {
+                       /* field is currently unknown, so just use whatever
+                          exists in the file. */
                        field.name = names;
                        field.type = types[i];
                        field.field_size = sizes[i];
-                       field.decision = decisions[i] & ~MAIL_CACHE_DECISION_FORCED;
+                       field.decision = file_dec;
                        mail_cache_register_fields(cache, &field, 1);
                        fidx = field.idx;
                }