mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-19 23:28:54 +02:00
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.)
This commit is contained in:
committed by
Philip Withnall
parent
7a33239bab
commit
b933b0f369
@@ -1790,6 +1790,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||||||
* Gets the modification time of the current @info and returns it as a
|
* Gets the modification time of the current @info and returns it as a
|
||||||
* #GDateTime.
|
* #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
|
* Returns: (transfer full) (nullable): modification time, or %NULL if unknown
|
||||||
* Since: 2.62
|
* Since: 2.62
|
||||||
*/
|
*/
|
||||||
@@ -1812,11 +1816,12 @@ g_file_info_get_modification_date_time (GFileInfo *info)
|
|||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
return 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);
|
value_usec = g_file_info_find_value (info, attr_mtime_usec);
|
||||||
if (value_usec == NULL)
|
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);
|
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);
|
g_date_time_unref (dt);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user