mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 15:03:39 +02:00
gfileenumerator: Warn if name is not available for get_child()
`standard::name` must be available for `g_file_enumerator_get_child()` to work. Emit a critical warning and return if it’s not. This is similar to the existing behaviour in `g_file_enumerator_iterate()`. Improve the documentation to mention this. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #2507
This commit is contained in:
@@ -721,6 +721,9 @@ g_file_enumerator_get_container (GFileEnumerator *enumerator)
|
||||
* directory of @enumerator. This function is primarily intended to be used
|
||||
* inside loops with g_file_enumerator_next_file().
|
||||
*
|
||||
* To use this, #G_FILE_ATTRIBUTE_STANDARD_NAME must have been listed in the
|
||||
* attributes list used when creating the #GFileEnumerator.
|
||||
*
|
||||
* This is a convenience method that's equivalent to:
|
||||
* |[<!-- language="C" -->
|
||||
* gchar *name = g_file_info_get_name (info);
|
||||
@@ -736,11 +739,20 @@ GFile *
|
||||
g_file_enumerator_get_child (GFileEnumerator *enumerator,
|
||||
GFileInfo *info)
|
||||
{
|
||||
const gchar *name;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE_ENUMERATOR (enumerator), NULL);
|
||||
g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
|
||||
|
||||
return g_file_get_child (enumerator->priv->container,
|
||||
g_file_info_get_name (info));
|
||||
name = g_file_info_get_name (info);
|
||||
|
||||
if (G_UNLIKELY (name == NULL))
|
||||
{
|
||||
g_critical ("GFileEnumerator created without standard::name");
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
|
||||
return g_file_get_child (enumerator->priv->container, name);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Reference in New Issue
Block a user