[glib/wip/chergert/fix-modification-date-time] fileinfo: ignore USEC if not available



commit b77a0ab6a6cab07688c1d8e71417dde2665c31c0
Author: Christian Hergert <chergert redhat com>
Date:   Wed Sep 4 13:41:24 2019 -0700

    fileinfo: ignore USEC if not available
    
    When future porting deprecated code to use
    g_file_info_get_modification_date_time() we risk a number of breakages
    because the current implementation also requires the additional use of
    G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC. This handles that situation gracefully
    and returns a GDateTime with less precision.
    
    Applications that want the adiditional precision, are already using the
    additional attribute.

 gio/gfileinfo.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/gio/gfileinfo.c b/gio/gfileinfo.c
index 65788d088..e57e6b54b 100644
--- a/gio/gfileinfo.c
+++ b/gio/gfileinfo.c
@@ -1790,6 +1790,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
  * Gets the modification time of the current @info and returns it as a
  * #GDateTime.
  *
+ * This requires the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute. If
+ * %G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC is provided, the resulting #GDateTime
+ * will have second-precision.
+ *
  * Returns: (transfer full) (nullable): modification time, or %NULL if unknown
  * Since: 2.62
  */
@@ -1812,11 +1816,12 @@ g_file_info_get_modification_date_time (GFileInfo *info)
   if (value == NULL)
     return NULL;
 
+  dt = g_date_time_new_from_unix_utc (_g_file_attribute_value_get_uint64 (value));
+
   value_usec = g_file_info_find_value (info, attr_mtime_usec);
   if (value_usec == NULL)
-    return NULL;
+    return g_steal_pointer (&dt);
 
-  dt = g_date_time_new_from_unix_utc (_g_file_attribute_value_get_uint64 (value));
   dt2 = g_date_time_add_seconds (dt, _g_file_attribute_value_get_uint32 (value_usec) / (gdouble) 
G_USEC_PER_SEC);
   g_date_time_unref (dt);
 


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