diff options
author | António Fernandes <antoniof@gnome.org> | 2020-05-17 00:40:01 +0100 |
---|---|---|
committer | Ondrej Holy <oholy@redhat.com> | 2021-01-25 10:54:11 +0000 |
commit | b92a7d5232667ed2958df3db8cdb75d8a28d0ba3 (patch) | |
tree | d9bff1972ba998856444d32f2ad5f367bfa7f83e /src/nautilus-directory.c | |
parent | e327f8f44597d9829586acee66ff7f83149313ee (diff) | |
download | nautilus-b92a7d5232667ed2958df3db8cdb75d8a28d0ba3.tar.gz |
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.
Diffstat (limited to 'src/nautilus-directory.c')
-rw-r--r-- | src/nautilus-directory.c | 40 |
1 files 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 |