[nautilus/wip/ernestask/search-fix: 2/2] search-engine: Query file system to determine remoteness



commit 62ba6d83df162b149785ed10a13d242ee1a13dc1
Author: Ernestas Kulik <ernestask gnome org>
Date:   Fri Sep 14 13:52:11 2018 +0300

    search-engine: Query file system to determine remoteness
    
    Querying the file cache in is_recursive_search() does not guarantee that
    the file system field will be populated with a value, and somehow
    results in data races, in turn resulting in random crashes/file list
    corruption.
    
    Hopefully fixes https://gitlab.gnome.org/GNOME/nautilus/issues/640,
    closes https://gitlab.gnome.org/GNOME/nautilus/issues/632 and resolves
    https://gitlab.gnome.org/GNOME/nautilus/issues/602

 src/nautilus-file-utilities.c | 18 ++++++++++++++++++
 src/nautilus-file-utilities.h |  2 ++
 src/nautilus-file.c           | 14 +-------------
 src/nautilus-search-engine.c  | 18 +++++++++++++++---
 4 files changed, 36 insertions(+), 16 deletions(-)
---
diff --git a/src/nautilus-file-utilities.c b/src/nautilus-file-utilities.c
index 575c138cf..40acff938 100644
--- a/src/nautilus-file-utilities.c
+++ b/src/nautilus-file-utilities.c
@@ -1489,3 +1489,21 @@ location_settings_search_get_recursive_for_location (GFile *location)
 
     return recursive;
 }
+
+gboolean
+nautilus_file_system_is_remote (const char *file_system)
+{
+    static const gchar * const remote_types[] =
+    {
+        "afp",
+        "google-drive",
+        "sftp",
+        "webdav",
+        "ftp",
+        "nfs",
+        "cifs",
+        NULL
+    };
+
+    return file_system != NULL && g_strv_contains (remote_types, file_system);
+}
diff --git a/src/nautilus-file-utilities.h b/src/nautilus-file-utilities.h
index 67df0e4d9..22d851c1b 100644
--- a/src/nautilus-file-utilities.h
+++ b/src/nautilus-file-utilities.h
@@ -141,3 +141,5 @@ gchar * nautilus_uri_to_native_uri (const gchar *uri);
 
 NautilusQueryRecursive location_settings_search_get_recursive (void);
 NautilusQueryRecursive location_settings_search_get_recursive_for_location (GFile *location);
+
+gboolean nautilus_file_system_is_remote (const char *file_system);
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index dc3a788d0..c62b47a6b 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -8065,18 +8065,6 @@ nautilus_file_is_in_starred (NautilusFile *file)
     return nautilus_directory_is_in_starred (file->details->directory);
 }
 
-static const gchar * const remote_types[] =
-{
-    "afp",
-    "google-drive",
-    "sftp",
-    "webdav",
-    "ftp",
-    "nfs",
-    "cifs",
-    NULL
-};
-
 /**
  * nautilus_file_is_remote
  *
@@ -8100,7 +8088,7 @@ nautilus_file_is_remote (NautilusFile *file)
 
     filesystem_type = nautilus_file_get_filesystem_type (file);
 
-    return filesystem_type != NULL && g_strv_contains (remote_types, filesystem_type);
+    return nautilus_file_system_is_remote (filesystem_type);
 }
 
 /**
diff --git a/src/nautilus-search-engine.c b/src/nautilus-search-engine.c
index 23c1c7e88..b5a67b730 100644
--- a/src/nautilus-search-engine.c
+++ b/src/nautilus-search-engine.c
@@ -23,7 +23,7 @@
 #include "nautilus-search-engine.h"
 #include "nautilus-search-engine-private.h"
 
-#include "nautilus-file.h"
+#include "nautilus-file-utilities.h"
 #include "nautilus-search-engine-model.h"
 #include <glib/gi18n.h>
 #define DEBUG_FLAG NAUTILUS_DEBUG_SEARCH
@@ -563,8 +563,20 @@ is_recursive_search (NautilusSearchEngineType  engine_type,
 
         case NAUTILUS_QUERY_RECURSIVE_LOCAL_ONLY:
         {
-            g_autoptr (NautilusFile) file = nautilus_file_get (location);
-            return !nautilus_file_is_remote (file);
+            g_autoptr (GFileInfo) file_system_info = NULL;
+
+            file_system_info = g_file_query_filesystem_info (location,
+                                                             G_FILE_ATTRIBUTE_FILESYSTEM_TYPE,
+                                                             NULL, NULL);
+            if (file_system_info != NULL)
+            {
+                const char *file_system;
+
+                file_system = g_file_info_get_attribute_string (file_system_info,
+                                                                G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
+
+                return !nautilus_file_system_is_remote (file_system);
+            }
         }
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]