directory: Restructure and document is_local_or_fuse()

Avoid calling g_file_get_path() if we have enough information.

Clarify the purpose of this function.
This commit is contained in:
António Fernandes 2020-05-17 00:40:01 +01:00 committed by Ondrej Holy
parent e327f8f445
commit b92a7d5232

View file

@ -761,6 +761,19 @@ nautilus_directory_new (GFile *location)
return handling_instance;
}
/**
* nautilus_directory_is_local_or_fuse:
*
* @directory: a #NautilusDirectory
*
* Checks whether this directory contains files with local paths. Usually, this
* means the local path can be obtained by calling g_file_get_path(). As an
* exception, the local URI for files in recent:// can only be obtained from the
* G_FILE_ATTRIBUTE_STANDARD_TARGET_URI attribute.
*
* Returns: %TRUE if a local path is known to be obtainable for all files in
* this directory. Otherwise, %FALSE.
*/
gboolean
nautilus_directory_is_local (NautilusDirectory *directory)
{
@ -777,19 +790,28 @@ nautilus_directory_is_local (NautilusDirectory *directory)
gboolean
nautilus_directory_is_local_or_fuse (NautilusDirectory *directory)
{
g_autofree char *path = NULL;
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
g_return_val_if_fail (directory->details->location, FALSE);
/* If the glib reports a path, then it can use FUSE to convert the uri
* to a local path
*/
path = g_file_get_path (directory->details->location);
return nautilus_directory_is_in_recent (directory) ||
g_file_is_native (directory->details->location) ||
path != NULL;
if (nautilus_directory_is_in_recent (directory)
|| g_file_is_native (directory->details->location))
{
/* Native files have a local path by definition. The files in recent:/
* have a local URI stored in the standard::target-uri attribute. */
return TRUE;
}
else
{
g_autofree char *path = NULL;
/* Non-native files may have local paths in FUSE mounts. The only way to
* know if that's the case is to test if GIO reports a path.
*/
path = g_file_get_path (directory->details->location);
return (path != NULL);
}
}
gboolean