[gnome-software/wip/m1219-follow-up] gs-utils: Let gs_utils_get_file_age() return guint64



commit a324b4877add900834e5a4ca7f9ab8e50f250757
Author: Milan Crha <mcrha redhat com>
Date:   Tue Feb 22 17:52:36 2022 +0100

    gs-utils: Let gs_utils_get_file_age() return guint64
    
    Since https://gitlab.gnome.org/GNOME/gnome-software/-/merge_requests/1219 the cache
    file age is turned into guint64. Having the gs_utils_get_file_age() return
    guint and the cache file not existing meant returning G_MAXUINT, which is smaller
    than G_MAXUINT64, thus when the file did not exist it was behaving like
    the file exists and it failed later in the code.
    
    This could be seen on start as a runtime warning when there's no ratings.json file
    in the cache and automatic updates are enabled.

 lib/gs-external-appstream-utils.c                          |  4 ++--
 lib/gs-odrs-provider.c                                     |  4 ++--
 lib/gs-utils.c                                             | 14 +++++++-------
 lib/gs-utils.h                                             |  2 +-
 .../gs-plugin-fedora-pkgdb-collections.c                   |  4 ++--
 plugins/flatpak/gs-flatpak.c                               |  6 +++---
 6 files changed, 17 insertions(+), 17 deletions(-)
---
diff --git a/lib/gs-external-appstream-utils.c b/lib/gs-external-appstream-utils.c
index dc6d4b7e9..23462c0db 100644
--- a/lib/gs-external-appstream-utils.c
+++ b/lib/gs-external-appstream-utils.c
@@ -35,7 +35,7 @@ gs_external_appstream_check (const gchar *appstream_path,
                              guint64      cache_age_secs)
 {
        g_autoptr(GFile) file = g_file_new_for_path (appstream_path);
-       guint appstream_file_age = gs_utils_get_file_age (file);
+       guint64 appstream_file_age = gs_utils_get_file_age (file);
        return appstream_file_age >= cache_age_secs;
 }
 
@@ -221,7 +221,7 @@ gs_external_appstream_refresh_user (GsPlugin      *plugin,
                                     GCancellable  *cancellable,
                                     GError       **error)
 {
-       guint file_age;
+       guint64 file_age;
        g_autofree gchar *fullpath = NULL;
        g_autoptr(GFile) file = NULL;
        g_autoptr(GsApp) app_dl = gs_app_new (gs_plugin_get_name (plugin));
diff --git a/lib/gs-odrs-provider.c b/lib/gs-odrs-provider.c
index 279470706..82e1914cc 100644
--- a/lib/gs-odrs-provider.c
+++ b/lib/gs-odrs-provider.c
@@ -1288,12 +1288,12 @@ gs_odrs_provider_refresh (GsOdrsProvider  *self,
        if (cache_filename == NULL)
                return FALSE;
        if (cache_age_secs > 0) {
-               guint tmp;
+               guint64 tmp;
                g_autoptr(GFile) file = NULL;
                file = g_file_new_for_path (cache_filename);
                tmp = gs_utils_get_file_age (file);
                if (tmp < cache_age_secs) {
-                       g_debug ("%s is only %u seconds old, so ignoring refresh",
+                       g_debug ("%s is only %" G_GUINT64_FORMAT " seconds old, so ignoring refresh",
                                 cache_filename, tmp);
                        return gs_odrs_provider_load_ratings (self, cache_filename, error);
                }
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index b3e9e5f5e..2afe77d87 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -76,9 +76,9 @@ gs_mkdir_parent (const gchar *path, GError **error)
  *
  * Gets a file age.
  *
- * Returns: The time in seconds since the file was modified, or %G_MAXUINT for error
+ * Returns: The time in seconds since the file was modified, or %G_MAXUINT64 for error
  */
-guint
+guint64
 gs_utils_get_file_age (GFile *file)
 {
        guint64 now;
@@ -91,13 +91,13 @@ gs_utils_get_file_age (GFile *file)
                                  NULL,
                                  NULL);
        if (info == NULL)
-               return G_MAXUINT;
+               return G_MAXUINT64;
        mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
        now = (guint64) g_get_real_time () / G_USEC_PER_SEC;
        if (mtime > now)
-               return G_MAXUINT;
-       if (now - mtime > G_MAXUINT)
-               return G_MAXUINT;
+               return G_MAXUINT64;
+       if (now - mtime > G_MAXUINT64)
+               return G_MAXUINT64;
        return (guint) (now - mtime);
 }
 
@@ -110,7 +110,7 @@ gs_utils_filename_array_return_newest (GPtrArray *array)
        for (i = 0; i < array->len; i++) {
                const gchar *fn = g_ptr_array_index (array, i);
                g_autoptr(GFile) file = g_file_new_for_path (fn);
-               guint age_tmp = gs_utils_get_file_age (file);
+               guint64 age_tmp = gs_utils_get_file_age (file);
                if (age_tmp < age_lowest) {
                        age_lowest = age_tmp;
                        filename_best = fn;
diff --git a/lib/gs-utils.h b/lib/gs-utils.h
index a1f1514f7..6b7de2acf 100644
--- a/lib/gs-utils.h
+++ b/lib/gs-utils.h
@@ -35,7 +35,7 @@ typedef enum {
        GS_UTILS_CACHE_FLAG_LAST  /*< skip >*/
 } GsUtilsCacheFlags;
 
-guint           gs_utils_get_file_age          (GFile          *file);
+guint64                 gs_utils_get_file_age          (GFile          *file);
 gchar          *gs_utils_get_content_type      (GFile          *file,
                                                 GCancellable   *cancellable,
                                                 GError         **error);
diff --git a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c 
b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
index 41b1f0d80..6d28b2cd5 100644
--- a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
+++ b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
@@ -234,9 +234,9 @@ _refresh_cache (GsPluginFedoraPkgdbCollections *self,
        /* check cache age */
        if (cache_age > 0) {
                g_autoptr(GFile) file = g_file_new_for_path (self->cachefn);
-               guint tmp = gs_utils_get_file_age (file);
+               guint64 tmp = gs_utils_get_file_age (file);
                if (tmp < cache_age) {
-                       g_debug ("%s is only %u seconds old",
+                       g_debug ("%s is only %" G_GUINT64_FORMAT " seconds old",
                                 self->cachefn, tmp);
                        return TRUE;
                }
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 7b9fdd2d6..0ce1b7e0e 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -1202,7 +1202,7 @@ gs_flatpak_refresh_appstream (GsFlatpak     *self,
        }
        for (guint i = 0; i < xremotes->len; i++) {
                const gchar *remote_name;
-               guint tmp;
+               guint64 tmp;
                g_autoptr(GError) error_local = NULL;
                g_autoptr(GFile) file = NULL;
                g_autoptr(GFile) file_timestamp = NULL;
@@ -1230,13 +1230,13 @@ gs_flatpak_refresh_appstream (GsFlatpak     *self,
                tmp = gs_utils_get_file_age (file_timestamp);
                if (tmp < cache_age_secs) {
                        g_autofree gchar *fn = g_file_get_path (file_timestamp);
-                       g_debug ("%s is only %u seconds old, so ignoring refresh",
+                       g_debug ("%s is only %" G_GUINT64_FORMAT " seconds old, so ignoring refresh",
                                 fn, tmp);
                        continue;
                }
 
                /* download new data */
-               g_debug ("%s is %u seconds old, so downloading new data",
+               g_debug ("%s is %" G_GUINT64_FORMAT " seconds old, so downloading new data",
                         remote_name, tmp);
                ret = gs_flatpak_refresh_appstream_remote (self,
                                                           remote_name,


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