]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
acl: Cleanup - move code to a new acl_vfile_validity_has_changed()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 6 Oct 2017 13:54:20 +0000 (16:54 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Fri, 6 Oct 2017 20:46:32 +0000 (23:46 +0300)
src/plugins/acl/acl-backend-vfile.c

index 7a53e5e175ce6c4a570fc7cefd1677c496c194c8..46ab558f001ead042211667517aac2cb48d68258 100644 (file)
@@ -455,6 +455,28 @@ acl_backend_vfile_read_with_retry(struct acl_object *aclobj,
        return ret <= 0 ? -1 : 0;
 }
 
+static int
+acl_vfile_validity_has_changed(struct acl_backend_vfile *backend,
+                              const struct acl_vfile_validity *validity,
+                              const struct stat *st)
+{
+       if (st->st_mtime == validity->last_mtime &&
+           st->st_size == validity->last_size) {
+               /* same timestamp, but if it was modified within the
+                  same second we want to refresh it again later (but
+                  do it only after a couple of seconds so we don't
+                  keep re-reading it all the time within those
+                  seconds) */
+               time_t cache_secs = backend->cache_secs;
+
+               if (validity->last_read_time != 0 &&
+                   (st->st_mtime < validity->last_read_time - cache_secs ||
+                    ioloop_time - validity->last_read_time <= cache_secs))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
 static int
 acl_backend_vfile_refresh(struct acl_object *aclobj, const char *path,
                          struct acl_vfile_validity *validity)
@@ -488,23 +510,7 @@ acl_backend_vfile_refresh(struct acl_object *aclobj, const char *path,
                i_error("stat(%s) failed: %m", path);
                return -1;
        }
-
-       if (st.st_mtime == validity->last_mtime &&
-           st.st_size == validity->last_size) {
-               /* same timestamp, but if it was modified within the
-                  same second we want to refresh it again later (but
-                  do it only after a couple of seconds so we don't
-                  keep re-reading it all the time within those
-                  seconds) */
-               time_t cache_secs = backend->cache_secs;
-
-               if (validity->last_read_time != 0 &&
-                   (st.st_mtime < validity->last_read_time - cache_secs ||
-                    ioloop_time - validity->last_read_time <= cache_secs))
-                       return 0;
-       }
-
-       return 1;
+       return acl_vfile_validity_has_changed(backend, validity, &st) ? 1 : 0;
 }
 
 int acl_backend_vfile_object_get_mtime(struct acl_object *aclobj,