[glib/wip/chergert/fix-modification-date-time: 7/9] fileinfo: ignore USEC if not available
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/chergert/fix-modification-date-time: 7/9] fileinfo: ignore USEC if not available
- Date: Thu, 5 Sep 2019 16:13:20 +0000 (UTC)
commit b933b0f369c99bd8ca8a22956b8eadf8b75cba54
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 additional precision, are already using the
additional attribute.
(Minor tweaks by Philip Withnall.)
gio/gfileinfo.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/gio/gfileinfo.c b/gio/gfileinfo.c
index 65788d088..ab4cbea96 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 microsecond 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]