mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-24 13:06:14 +01:00
gfileinfo: Add g_file_info_{get,set}_modification_date_time() APIs
These are alternatives to g_file_info_{get,set}_modification_time(), which will soon be deprecated due to using the deprecated GTimeVal type, which is not year 2038 safe. The new APIs take a GDateTime instead. Signed-off-by: Philip Withnall <withnall@endlessm.com> Helps: #1438
This commit is contained in:
parent
a3f22f0c2c
commit
d166a55c64
@ -395,6 +395,7 @@ g_file_info_get_symbolic_icon
|
||||
g_file_info_get_content_type
|
||||
g_file_info_get_size
|
||||
g_file_info_get_modification_time
|
||||
g_file_info_get_modification_date_time
|
||||
g_file_info_get_symlink_target
|
||||
g_file_info_get_etag
|
||||
g_file_info_get_sort_order
|
||||
@ -412,6 +413,7 @@ g_file_info_set_symbolic_icon
|
||||
g_file_info_set_content_type
|
||||
g_file_info_set_size
|
||||
g_file_info_set_modification_time
|
||||
g_file_info_set_modification_date_time
|
||||
g_file_info_set_symlink_target
|
||||
g_file_info_set_sort_order
|
||||
g_file_attribute_matcher_new
|
||||
|
@ -1776,6 +1776,46 @@ g_file_info_get_modification_time (GFileInfo *info,
|
||||
result->tv_usec = _g_file_attribute_value_get_uint32 (value);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_file_info_get_modification_date_time:
|
||||
* @info: a #GFileInfo.
|
||||
*
|
||||
* Gets the modification time of the current @info and returns it as a
|
||||
* #GDateTime.
|
||||
*
|
||||
* Returns: (transfer full) (nullable): modification time, or %NULL if unknown
|
||||
* Since: 2.62
|
||||
*/
|
||||
GDateTime *
|
||||
g_file_info_get_modification_date_time (GFileInfo *info)
|
||||
{
|
||||
static guint32 attr_mtime = 0, attr_mtime_usec;
|
||||
GFileAttributeValue *value, *value_usec;
|
||||
GDateTime *dt = NULL, *dt2 = NULL;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
|
||||
|
||||
if (attr_mtime == 0)
|
||||
{
|
||||
attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
|
||||
attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
|
||||
}
|
||||
|
||||
value = g_file_info_find_value (info, attr_mtime);
|
||||
if (value == NULL)
|
||||
return NULL;
|
||||
|
||||
value_usec = g_file_info_find_value (info, attr_mtime_usec);
|
||||
if (value_usec == NULL)
|
||||
return NULL;
|
||||
|
||||
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);
|
||||
|
||||
return g_steal_pointer (&dt2);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_file_info_get_symlink_target:
|
||||
* @info: a #GFileInfo.
|
||||
@ -2138,6 +2178,40 @@ g_file_info_set_modification_time (GFileInfo *info,
|
||||
_g_file_attribute_value_set_uint32 (value, mtime->tv_usec);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_file_info_set_modification_date_time:
|
||||
* @info: a #GFileInfo.
|
||||
* @mtime: (not nullable): a #GDateTime.
|
||||
*
|
||||
* Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute in the file
|
||||
* info to the given date/time value.
|
||||
*
|
||||
* Since: 2.62
|
||||
*/
|
||||
void
|
||||
g_file_info_set_modification_date_time (GFileInfo *info,
|
||||
GDateTime *mtime)
|
||||
{
|
||||
static guint32 attr_mtime = 0, attr_mtime_usec;
|
||||
GFileAttributeValue *value;
|
||||
|
||||
g_return_if_fail (G_IS_FILE_INFO (info));
|
||||
g_return_if_fail (mtime != NULL);
|
||||
|
||||
if (attr_mtime == 0)
|
||||
{
|
||||
attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
|
||||
attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
|
||||
}
|
||||
|
||||
value = g_file_info_create_value (info, attr_mtime);
|
||||
if (value)
|
||||
_g_file_attribute_value_set_uint64 (value, g_date_time_to_unix (mtime));
|
||||
value = g_file_info_create_value (info, attr_mtime_usec);
|
||||
if (value)
|
||||
_g_file_attribute_value_set_uint32 (value, g_date_time_get_microsecond (mtime));
|
||||
}
|
||||
|
||||
/**
|
||||
* g_file_info_set_symlink_target:
|
||||
* @info: a #GFileInfo.
|
||||
|
@ -1049,6 +1049,8 @@ goffset g_file_info_get_size (GFileInfo *info);
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
void g_file_info_get_modification_time (GFileInfo *info,
|
||||
GTimeVal *result);
|
||||
GLIB_AVAILABLE_IN_2_62
|
||||
GDateTime * g_file_info_get_modification_date_time (GFileInfo *info);
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
const char * g_file_info_get_symlink_target (GFileInfo *info);
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
@ -1096,6 +1098,9 @@ void g_file_info_set_size (GFileInfo *info,
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
void g_file_info_set_modification_time (GFileInfo *info,
|
||||
GTimeVal *mtime);
|
||||
GLIB_AVAILABLE_IN_2_62
|
||||
void g_file_info_set_modification_date_time (GFileInfo *info,
|
||||
GDateTime *mtime);
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
void g_file_info_set_symlink_target (GFileInfo *info,
|
||||
const char *symlink_target);
|
||||
|
Loading…
Reference in New Issue
Block a user