[gcab: 5/6] Fix GTimeVal deprecation warnings



commit 74c45180f0ad0d28dade1457136fd8cd8abddae6
Author: Marc-André Lureau <marcandre lureau redhat com>
Date:   Wed Nov 27 12:18:59 2019 +0400

    Fix GTimeVal deprecation warnings
    
    Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>

 libgcab/gcab-file.c    |  6 +++---
 src/gcab.c             | 10 +++-------
 tests/gcab-self-test.c | 20 ++++----------------
 3 files changed, 10 insertions(+), 26 deletions(-)
---
diff --git a/libgcab/gcab-file.c b/libgcab/gcab-file.c
index 4ab0114..b7e1c5c 100644
--- a/libgcab/gcab-file.c
+++ b/libgcab/gcab-file.c
@@ -225,14 +225,14 @@ G_GNUC_END_IGNORE_DEPRECATIONS
 G_GNUC_INTERNAL gboolean
 gcab_file_update_info (GCabFile *self, GFileInfo *info)
 {
-    GTimeVal tv;
+    g_autoptr(GDateTime) dt = NULL;
 
     g_return_val_if_fail (GCAB_IS_FILE (self), FALSE);
     g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
 
-    g_file_info_get_modification_time (info, &tv);
+    dt = g_file_info_get_modification_date_time (info);
     if (self->cfile->date == 0)
-        gcab_file_set_date (self, &tv);
+        gcab_file_set_date_time (self, dt);
     self->cfile->usize = g_file_info_get_size (info);
     self->cfile->fattr = GCAB_FILE_ATTRIBUTE_ARCH;
 
diff --git a/src/gcab.c b/src/gcab.c
index 2023fec..cb9e374 100644
--- a/src/gcab.c
+++ b/src/gcab.c
@@ -193,13 +193,9 @@ individual files from the archive.\
 
                 for (l = files; l != NULL; l = l->next) {
                     if (list_details) {
-                        gchar date[32];
-                        struct tm *tm;
-                        GTimeVal tv = {0};
-
-                        gcab_file_get_date (GCAB_FILE (l->data), &tv);
-                        tm = localtime (&tv.tv_sec);
-                        strftime (date, sizeof (date), "%Y-%m-%d %H:%M:%S", tm);
+                        g_autoptr(GDateTime) dt = gcab_file_get_date_time (GCAB_FILE (l->data));
+                        g_autoptr(GDateTime) dtl = g_date_time_to_local (dt);
+                        g_autofree char *date = g_date_time_format (dtl, "%Y-%m-%d %H:%M:%S");
 
                         g_print ("%s %u %s 0x%X\n",
                                  gcab_file_get_name (GCAB_FILE (l->data)),
diff --git a/tests/gcab-self-test.c b/tests/gcab-self-test.c
index 746d069..cdfb9b6 100644
--- a/tests/gcab-self-test.c
+++ b/tests/gcab-self-test.c
@@ -35,8 +35,6 @@ gcab_test_get_filename (const gchar *filename)
 static void
 gcab_test_file_func (void)
 {
-    gboolean ret;
-    GTimeVal tv;
     g_autofree gchar *fn = NULL;
     g_autoptr(GCabFile) cabfile = NULL;
     g_autoptr(GDateTime) dt = NULL;
@@ -52,9 +50,7 @@ gcab_test_file_func (void)
 
     /* set the time */
     dt_bday = g_date_time_new_utc (2017, 9, 15, 0, 0, 0.f);
-    ret = g_date_time_to_timeval (dt_bday, &tv);
-    g_assert (ret);
-    gcab_file_set_date (cabfile, &tv);
+    gcab_file_set_date_time (cabfile, dt_bday);
 
     /* verify */
     g_assert (gcab_file_get_file (cabfile) == gfile);
@@ -62,9 +58,7 @@ gcab_test_file_func (void)
     g_assert_cmpstr (gcab_file_get_extract_name (cabfile), ==, "tæst.bin");
     g_assert_cmpint (gcab_file_get_size (cabfile), ==, 0);
     g_assert_cmpint (gcab_file_get_attributes (cabfile), ==, 0);
-    ret = gcab_file_get_date (cabfile, &tv);
-    g_assert (ret);
-    dt = g_date_time_new_from_timeval_utc (&tv);
+    dt = gcab_file_get_date_time (cabfile);
     g_assert_cmpint (g_date_time_get_year (dt), ==, 2017);
     g_assert_cmpint (g_date_time_get_month (dt), ==, 9);
     g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 15);
@@ -283,10 +277,7 @@ gcab_test_cabinet_blob_func (void)
 
         /* set the time and attributes */
         g_autoptr(GDateTime) dt = dt = g_date_time_new_utc (2017, 9, 15, 0, 0, 0.f);
-        GTimeVal tv;
-        ret = g_date_time_to_timeval (dt, &tv);
-        g_assert (ret);
-        gcab_file_set_date (cabfile, &tv);
+        gcab_file_set_date_time (cabfile, dt);
         gcab_file_set_attributes (cabfile, GCAB_FILE_ATTRIBUTE_ARCH);
 
         /* add file to folder */
@@ -536,13 +527,10 @@ gcab_test_cabinet_write_func (void)
             g_autoptr(GFile) file = g_file_new_for_path (fn_tmp);
             g_autoptr(GCabFile) cabfile = gcab_file_new_with_file (files[j].fn, file);
             g_autoptr(GDateTime) dt = NULL;
-            GTimeVal tv;
 
             /* set the time so the checksums match */
             dt = g_date_time_new_utc (2017, 9, 15, 0, 0, 0.f);
-            ret = g_date_time_to_timeval (dt, &tv);
-            g_assert (ret);
-            gcab_file_set_date (cabfile, &tv);
+            gcab_file_set_date_time (cabfile, dt);
 
             ret = gcab_folder_add_file (cabfolder, cabfile, FALSE, NULL, &error);
             g_assert_no_error (error);


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