[gimp/gimp-2-10] app: make gimp_versions.json parsing easier to test.



commit 07807203b5700eed0cfa53c8e8388978e268cfb9
Author: Jehan <jehan girinstud io>
Date:   Sat Dec 28 20:28:13 2019 +0100

    app: make gimp_versions.json parsing easier to test.
    
    First, let's make the check happen at each startup on unstable (still
    once a week on stable).
    Second, make it parse gimp.org's gimp_versions.json on stable, but
    testing's one on unstable and also check environment variable
    GIMP_DEV_VERSIONS_JSON (unstable only) to allow setting a local path
    (allowing to tweak the file and test various cases).
    
    Unrelated to testing, some improvements:
    - save a timestamp in seconds (really no need to keep microseconds
      precision here).
    - just in case, check that the saved timestamp is not in the future.
    
    (cherry picked from commit b874cadfad609e7a787a8dda7fd7da40ef2f4855)

 app/gimp-update.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/app/gimp-update.c b/app/gimp-update.c
index 68d8d56b59..29c284bd07 100644
--- a/app/gimp-update.c
+++ b/app/gimp-update.c
@@ -145,7 +145,7 @@ gimp_check_updates_callback (GObject      *source,
       if (gimp_version_break (last_version, &major, &minor, &micro))
         {
           g_object_set (config,
-                        "check-update-timestamp", g_get_real_time(),
+                        "check-update-timestamp", g_get_real_time() / G_USEC_PER_SEC,
                         "last-known-release",
                         (major > GIMP_MAJOR_VERSION ||
                          (major == GIMP_MAJOR_VERSION && minor > GIMP_MINOR_VERSION) ||
@@ -175,13 +175,26 @@ gimp_update_check (GimpCoreConfig *config)
   g_object_get (config,
                 "check-update-timestamp", &prev_update_timestamp,
                 NULL);
-  current_timestamp = g_get_real_time();
+  current_timestamp = g_get_real_time() / G_USEC_PER_SEC;
 
+  /* Get rid of invalid saved timestamps. */
+  if (prev_update_timestamp > current_timestamp)
+    prev_update_timestamp = -1;
+
+#ifndef GIMP_UNSTABLE
   /* Do not check more than once a week. */
-  if (current_timestamp - prev_update_timestamp < (gint64) G_USEC_PER_SEC * 3600L * 24L * 7L)
+  if (current_timestamp - prev_update_timestamp < 3600L * 24L * 7L)
     return FALSE;
-
-  gimp_versions = g_file_new_for_uri ("https://testing.gimp.org/gimp_versions.json";);
+#endif
+
+#ifdef GIMP_UNSTABLE
+  if (g_getenv ("GIMP_DEV_VERSIONS_JSON"))
+    gimp_versions = g_file_new_for_path (g_getenv ("GIMP_DEV_VERSIONS_JSON"));
+  else
+    gimp_versions = g_file_new_for_uri ("https://testing.gimp.org/gimp_versions.json";);
+#else
+  gimp_versions = g_file_new_for_uri ("https://gimp.org/gimp_versions.json";);
+#endif
   g_file_read_async (gimp_versions, 0, NULL, gimp_check_updates_callback, config);
   g_object_unref (gimp_versions);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]