From b92a7d5232667ed2958df3db8cdb75d8a28d0ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Sun, 17 May 2020 00:40:01 +0100 Subject: 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. --- src/nautilus-directory.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/nautilus-directory.c b/src/nautilus-directory.c index de7cb4ead..89d3756b4 100644 --- a/src/nautilus-directory.c +++ b/src/nautilus-directory.c @@ -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 -- cgit v1.2.1