Merge branch '2507-file-enumerator-docs' into 'main'

gfileenumerator: Warn if name is not available for get_child()

Closes #2507

See merge request GNOME/glib!2307
This commit is contained in:
Philip Withnall 2021-10-21 11:58:32 +00:00
commit 464470dd8f
2 changed files with 23 additions and 5 deletions

View File

@ -1025,7 +1025,9 @@ g_file_resolve_relative_path (GFile *file,
* "standard::*" means all attributes in the standard namespace.
* An example attribute query be "standard::*,owner::user".
* The standard attributes are available as defines, like
* #G_FILE_ATTRIBUTE_STANDARD_NAME.
* #G_FILE_ATTRIBUTE_STANDARD_NAME. #G_FILE_ATTRIBUTE_STANDARD_NAME should
* always be specified if you plan to call g_file_enumerator_get_child() or
* g_file_enumerator_iterate() on the returned enumerator.
*
* If @cancellable is not %NULL, then the operation can be cancelled
* by triggering the cancellable object from another thread. If the

View File

@ -662,7 +662,10 @@ g_file_enumerator_iterate (GFileEnumerator *direnum,
const char *name = g_file_info_get_name (ret_info);
if (G_UNLIKELY (name == NULL))
g_warning ("g_file_enumerator_iterate() created without standard::name");
{
g_critical ("g_file_enumerator_iterate() created without standard::name");
g_return_val_if_reached (FALSE);
}
else
{
*out_child = g_file_get_child (g_file_enumerator_get_container (direnum), name);
@ -718,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);
@ -733,10 +739,20 @@ GFile *
g_file_enumerator_get_child (GFileEnumerator *enumerator,
GFileInfo *info)
{
g_return_val_if_fail (G_IS_FILE_ENUMERATOR (enumerator), NULL);
const gchar *name;
return g_file_get_child (enumerator->priv->container,
g_file_info_get_name (info));
g_return_val_if_fail (G_IS_FILE_ENUMERATOR (enumerator), NULL);
g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
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