[tepl] Metadata: preparation for using TeplMetadataStore



commit 240ad0fba720426d8cc9fa003ebad2ef76a697e5
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Apr 15 19:03:19 2020 +0200

    Metadata: preparation for using TeplMetadataStore

 tepl/tepl-metadata.c | 72 ++++++++++++++++++++++++++++++++++++++++------------
 tepl/tepl-metadata.h |  4 +++
 2 files changed, 60 insertions(+), 16 deletions(-)
---
diff --git a/tepl/tepl-metadata.c b/tepl/tepl-metadata.c
index fadbadf..4328371 100644
--- a/tepl/tepl-metadata.c
+++ b/tepl/tepl-metadata.c
@@ -17,6 +17,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "config.h"
 #include "tepl-metadata.h"
 
 /* Almost a drop-in replacement for, or a wrapping of, the
@@ -25,6 +26,29 @@
  * - Use the TeplMetadataStore otherwise. TODO: do it.
  */
 
+static gboolean force_using_metadata_store;
+
+void
+_tepl_metadata_set_force_using_metadata_store (gboolean value)
+{
+       force_using_metadata_store = value != FALSE;
+}
+
+static gboolean
+use_gvfs_metadata (void)
+{
+       if (force_using_metadata_store)
+       {
+               return FALSE;
+       }
+
+#if ENABLE_GVFS_METADATA
+       return TRUE;
+#else
+       return FALSE;
+#endif
+}
+
 void
 _tepl_metadata_query_info_async (GFile               *location,
                                 gint                 io_priority,
@@ -32,13 +56,16 @@ _tepl_metadata_query_info_async (GFile               *location,
                                 GAsyncReadyCallback  callback,
                                 gpointer             user_data)
 {
-       g_file_query_info_async (location,
-                                "metadata::*",
-                                G_FILE_QUERY_INFO_NONE,
-                                io_priority,
-                                cancellable,
-                                callback,
-                                user_data);
+       if (use_gvfs_metadata ())
+       {
+               g_file_query_info_async (location,
+                                        "metadata::*",
+                                        G_FILE_QUERY_INFO_NONE,
+                                        io_priority,
+                                        cancellable,
+                                        callback,
+                                        user_data);
+       }
 }
 
 GFileInfo *
@@ -46,7 +73,12 @@ _tepl_metadata_query_info_finish (GFile         *location,
                                  GAsyncResult  *result,
                                  GError       **error)
 {
-       return g_file_query_info_finish (location, result, error);
+       if (use_gvfs_metadata ())
+       {
+               return g_file_query_info_finish (location, result, error);
+       }
+
+       return NULL;
 }
 
 void
@@ -57,13 +89,16 @@ _tepl_metadata_set_attributes_async (GFile               *location,
                                     GAsyncReadyCallback  callback,
                                     gpointer             user_data)
 {
-       g_file_set_attributes_async (location,
-                                    info,
-                                    G_FILE_QUERY_INFO_NONE,
-                                    io_priority,
-                                    cancellable,
-                                    callback,
-                                    user_data);
+       if (use_gvfs_metadata ())
+       {
+               g_file_set_attributes_async (location,
+                                            info,
+                                            G_FILE_QUERY_INFO_NONE,
+                                            io_priority,
+                                            cancellable,
+                                            callback,
+                                            user_data);
+       }
 }
 
 gboolean
@@ -71,5 +106,10 @@ _tepl_metadata_set_attributes_finish (GFile         *location,
                                      GAsyncResult  *result,
                                      GError       **error)
 {
-       return g_file_set_attributes_finish (location, result, NULL, error);
+       if (use_gvfs_metadata ())
+       {
+               return g_file_set_attributes_finish (location, result, NULL, error);
+       }
+
+       return FALSE;
 }
diff --git a/tepl/tepl-metadata.h b/tepl/tepl-metadata.h
index 58ce8eb..650e982 100644
--- a/tepl/tepl-metadata.h
+++ b/tepl/tepl-metadata.h
@@ -49,6 +49,10 @@ gboolean     _tepl_metadata_set_attributes_finish    (GFile         *location,
                                                         GAsyncResult  *result,
                                                         GError       **error);
 
+/* For unit tests. */
+G_GNUC_INTERNAL
+void           _tepl_metadata_set_force_using_metadata_store (gboolean value);
+
 G_END_DECLS
 
 #endif /* TEPL_METADATA_H */


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