[tracker-miners/sam/index-file-sync: 4/18] miners/fs: Remove all data added by IndexFileForProcess on shutdown



commit 5234681cbd5f6f9e6af7db6d8c17a8ce4c62696f
Author: Sam Thursfield <sam afuera me uk>
Date:   Sun Mar 8 20:13:21 2020 +0100

    miners/fs: Remove all data added by IndexFileForProcess on shutdown
    
    The IndexFileForProcess method is intended for apps to trigger on-demand
    indexing of removable devices. The data remains in the store as long as
    the app is connected to D-Bus, then it's deleted.
    
    If the miner-fs shut down before the app, the data would remain in the
    store forever and would not be updated, until an app one day called
    IndexFileForProcess again for the same location.

 src/libtracker-miner/tracker-miner-fs.c           | 34 ++++++++++++++++------
 src/libtracker-miner/tracker-miner-fs.h           |  2 ++
 src/miners/fs/tracker-main.c                      | 35 ++++++++++++++++++++++-
 src/miners/fs/tracker-miner-files-index.c         |  8 ++++++
 src/miners/fs/tracker-miner-files-index.h         |  1 +
 src/miners/fs/tracker-miner-files-peer-listener.c | 24 ++++++++++++++++
 src/miners/fs/tracker-miner-files-peer-listener.h |  1 +
 7 files changed, 96 insertions(+), 9 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 24e5c405f..c0abde854 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -827,19 +827,12 @@ fs_finalize (GObject *object)
                tracker_file_notifier_stop (priv->file_notifier);
        }
 
-       /* Cancel every pending task */
-       tracker_task_pool_foreach (priv->task_pool,
-                                  task_pool_cancel_foreach,
-                                  NULL);
-       g_object_unref (priv->task_pool);
+       tracker_miner_fs_cancel_all_tasks (TRACKER_MINER_FS (object));
 
        if (priv->sparql_buffer) {
                g_object_unref (priv->sparql_buffer);
        }
 
-       tracker_priority_queue_foreach (priv->items,
-                                       (GFunc) queue_event_free,
-                                       NULL);
        tracker_priority_queue_unref (priv->items);
 
        g_object_unref (priv->root);
@@ -2657,3 +2650,28 @@ tracker_miner_fs_get_data_provider (TrackerMinerFS *fs)
 
        return fs->priv->data_provider;
 }
+
+/**
+ * tracker_miner_fs_cancel_all_tasks:
+ * @fs: a #TrackerMinerFS
+ *
+ * Cancels all tasks which are in progress.
+ *
+ * Since: 3.0
+ **/
+void
+tracker_miner_fs_cancel_all_tasks (TrackerMinerFS *fs)
+{
+       TrackerMinerFSPrivate *priv;
+
+       priv = fs->priv;
+
+       /* Cancel every pending task */
+       tracker_task_pool_foreach (priv->task_pool,
+                                  task_pool_cancel_foreach,
+                                  NULL);
+
+       tracker_priority_queue_foreach (priv->items,
+                                      (GFunc) queue_event_free,
+                                      NULL);
+}
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 3fdb67414..871b20375 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -175,6 +175,8 @@ gchar                *tracker_miner_fs_query_urn             (TrackerMinerFS  *f
 /* Progress */
 gboolean              tracker_miner_fs_has_items_to_process  (TrackerMinerFS  *fs);
 
+void                  tracker_miner_fs_cancel_all_tasks       (TrackerMinerFS  *fs);
+
 G_END_DECLS
 
 #endif /* __LIBTRACKER_MINER_MINER_FS_H__ */
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index e015e008d..f21deda1d 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -767,6 +767,24 @@ setup_connection_and_endpoint (TrackerDomainOntology    *domain,
        return TRUE;
 }
 
+static gboolean
+quit_on_miner_finished_cb (TrackerMinerFiles *miner,
+                           gdouble time,
+                           guint directories_found,
+                           guint directories_ignored,
+                           guint files_found,
+                           guint files_ignored,
+                           gpointer user_data)
+{
+       GMainLoop *loop = user_data;
+
+       g_debug ("miner-fs finished processing removals");
+
+       g_main_loop_quit (loop);
+
+       return G_SOURCE_REMOVE;
+}
+
 int
 main (gint argc, gchar *argv[])
 {
@@ -784,6 +802,7 @@ main (gint argc, gchar *argv[])
        TrackerEndpointDBus *endpoint;
        TrackerDomainOntology *domain_ontology;
        gchar *domain_name, *dbus_name;
+       GMainLoop *shutdown_loop;
 
        main_loop = NULL;
 
@@ -998,15 +1017,29 @@ main (gint argc, gchar *argv[])
 
        /* Go, go, go! */
        g_main_loop_run (main_loop);
+       g_main_loop_unref (main_loop);
 
        g_message ("Shutdown started");
 
+       tracker_miner_fs_cancel_all_tasks (TRACKER_MINER_FS (miner_files));
+       tracker_miner_files_index_remove_temporary_data (miner_files_index);
+
+       shutdown_loop = g_main_loop_new (NULL, 0);
+
+       if (tracker_miner_fs_has_items_to_process (TRACKER_MINER_FS (miner_files))) {
+               g_debug ("Waiting for miner-fs to process removals.");
+               g_signal_connect (miner_files, "finished", G_CALLBACK (quit_on_miner_finished_cb), 
shutdown_loop);
+               g_main_loop_run (shutdown_loop);
+       } else {
+               g_debug ("No removals to process.");
+       }
+
        if (miners_timeout_id == 0 && !miner_needs_check (miner_files)) {
                tracker_miner_files_set_need_mtime_check (FALSE);
                save_current_locale ();
        }
 
-       g_main_loop_unref (main_loop);
+       g_main_loop_unref (shutdown_loop);
        g_object_unref (config);
        g_object_unref (miner_files_index);
 
diff --git a/src/miners/fs/tracker-miner-files-index.c b/src/miners/fs/tracker-miner-files-index.c
index db662b4fe..a03b20af7 100644
--- a/src/miners/fs/tracker-miner-files-index.c
+++ b/src/miners/fs/tracker-miner-files-index.c
@@ -583,3 +583,11 @@ tracker_miner_files_index_new (TrackerMinerFiles *miner_files)
 
        return (TrackerMinerFilesIndex *) miner;
 }
+
+void
+tracker_miner_files_index_remove_temporary_data (TrackerMinerFilesIndex *miner_files)
+{
+       TrackerMinerFilesIndexPrivate *priv = TRACKER_MINER_FILES_INDEX_GET_PRIVATE (miner_files);
+
+       tracker_miner_files_peer_listener_remove_all (priv->peer_listener);
+}
diff --git a/src/miners/fs/tracker-miner-files-index.h b/src/miners/fs/tracker-miner-files-index.h
index 447d9e293..62b032659 100644
--- a/src/miners/fs/tracker-miner-files-index.h
+++ b/src/miners/fs/tracker-miner-files-index.h
@@ -46,6 +46,7 @@ struct TrackerMinerFilesIndexClass {
 
 GType                   tracker_miner_files_index_get_type (void);
 TrackerMinerFilesIndex *tracker_miner_files_index_new      (TrackerMinerFiles *miner_files);
+void                    tracker_miner_files_index_remove_temporary_data (TrackerMinerFilesIndex 
*miner_files);
 
 G_END_DECLS
 
diff --git a/src/miners/fs/tracker-miner-files-peer-listener.c 
b/src/miners/fs/tracker-miner-files-peer-listener.c
index 5301e1527..5efb50361 100644
--- a/src/miners/fs/tracker-miner-files-peer-listener.c
+++ b/src/miners/fs/tracker-miner-files-peer-listener.c
@@ -332,6 +332,30 @@ tracker_miner_files_peer_listener_add_watch (TrackerMinerFilesPeerListener *list
        file_peers_data_add_dbus_name (file_data, peer_data->dbus_name);
 }
 
+void
+tracker_miner_files_peer_listener_remove_all (TrackerMinerFilesPeerListener *listener)
+{
+       TrackerMinerFilesPeerListenerPrivate *priv;
+       GHashTableIter iter;
+       GFile *file;
+       FilePeersData *file_data;
+
+       g_return_if_fail (TRACKER_IS_MINER_FILES_PEER_LISTENER (listener));
+
+       priv = tracker_miner_files_peer_listener_get_instance_private (listener);
+
+       g_message ("Removing all data added with IndexFileForProcess");
+
+       g_hash_table_remove_all (priv->peer_files);
+
+       g_hash_table_iter_init (&iter, priv->file_peers);
+       while (g_hash_table_iter_next (&iter, (gpointer *)&file, (gpointer *)&file_data)) {
+               g_hash_table_iter_remove (&iter);
+
+               g_signal_emit (listener, signals[UNWATCH_FILE], 0, file);
+       }
+}
+
 void
 tracker_miner_files_peer_listener_remove_watch (TrackerMinerFilesPeerListener *listener,
                                                 const gchar                   *dbus_name,
diff --git a/src/miners/fs/tracker-miner-files-peer-listener.h 
b/src/miners/fs/tracker-miner-files-peer-listener.h
index 7a23d328d..4e7997d02 100644
--- a/src/miners/fs/tracker-miner-files-peer-listener.h
+++ b/src/miners/fs/tracker-miner-files-peer-listener.h
@@ -55,6 +55,7 @@ void     tracker_miner_files_peer_listener_remove_watch (TrackerMinerFilesPeerLi
                                                          const gchar                   *dbus_name,
                                                          GFile                         *file);
 
+void     tracker_miner_files_peer_listener_remove_all       (TrackerMinerFilesPeerListener *listener);
 void     tracker_miner_files_peer_listener_remove_dbus_name (TrackerMinerFilesPeerListener *listener,
                                                              const gchar                   *dbus_name);
 void     tracker_miner_files_peer_listener_remove_file      (TrackerMinerFilesPeerListener *listener,


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