[tracker-miners/wip/carlosg/parallel-installable: 32/34] tracker-miner-fs: Make all cache paths dependent on the domain ontology



commit 304cde2ba161ad759d25b81ff5d43af1857f6996
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Mar 8 11:52:00 2020 +0100

    tracker-miner-fs: Make all cache paths dependent on the domain ontology
    
    This wasn't the case for misc files.

 src/miners/fs/tracker-main.c        |  57 ++++++++++++++------
 src/miners/fs/tracker-miner-files.c | 104 +++++++++++++++++++++++++++---------
 src/miners/fs/tracker-miner-files.h |  15 +++---
 3 files changed, 127 insertions(+), 49 deletions(-)
---
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 77d93ba79..7a6f9ff8a 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -151,12 +151,26 @@ miner_reset_applications (TrackerMiner *miner)
        }
 }
 
+static GFile *
+get_cache_dir (TrackerDomainOntology *domain_ontology)
+{
+       GFile *cache;
+
+       cache = tracker_domain_ontology_get_cache (domain_ontology);
+       return g_object_ref (cache);
+}
+
 static void
-save_current_locale (void)
+save_current_locale (TrackerDomainOntology *domain_ontology)
 {
        GError *error = NULL;
        gchar *locale = tracker_locale_get (TRACKER_LOCALE_LANGUAGE);
-       gchar *locale_file = g_build_filename (g_get_user_cache_dir (), "tracker", LOCALE_FILENAME, NULL);
+       GFile *cache = get_cache_dir (domain_ontology);
+       gchar *cache_path = g_file_get_path (cache);
+       gchar *locale_file;
+
+       locale_file = g_build_filename (cache_path, LOCALE_FILENAME, NULL);
+       g_free (cache_path);
 
        g_message ("Saving locale used to index applications");
        g_message ("  Creating locale file '%s'", locale_file);
@@ -176,14 +190,20 @@ save_current_locale (void)
 }
 
 static gboolean
-detect_locale_changed (TrackerMiner *miner)
+detect_locale_changed (TrackerMiner          *miner,
+                      TrackerDomainOntology *domain_ontology)
 {
+       GFile *cache;
+       gchar *cache_path;
        gchar *locale_file;
        gchar *previous_locale = NULL;
        gchar *current_locale;
        gboolean changed;
 
-       locale_file = g_build_filename (g_get_user_cache_dir (), "tracker", LOCALE_FILENAME, NULL);
+       cache = get_cache_dir (domain_ontology);
+       cache_path = g_file_get_path (cache);
+       locale_file = g_build_filename (cache_path, LOCALE_FILENAME, NULL);
+       g_free (cache_path);
 
        if (G_LIKELY (g_file_test (locale_file, G_FILE_TEST_EXISTS))) {
                gchar *contents;
@@ -300,8 +320,9 @@ initialize_priority_and_scheduling (void)
 }
 
 static gboolean
-should_crawl (TrackerConfig *config,
-              gboolean      *forced)
+should_crawl (TrackerMinerFiles *miner_files,
+             TrackerConfig     *config,
+              gboolean          *forced)
 {
        gint crawling_interval;
 
@@ -326,7 +347,7 @@ should_crawl (TrackerConfig *config,
        } else {
                guint64 then, now;
 
-               then = tracker_miner_files_get_last_crawl_done ();
+               then = tracker_miner_files_get_last_crawl_done (miner_files);
 
                if (then < 1) {
                        return TRUE;
@@ -412,7 +433,8 @@ miner_finished_cb (TrackerMinerFS *fs,
                total_files_found);
 
        if (do_crawling) {
-               tracker_miner_files_set_last_crawl_done (TRUE);
+               tracker_miner_files_set_last_crawl_done (TRACKER_MINER_FILES (fs),
+                                                        TRUE);
        }
 
        /* We're not sticking around for file updates, so stop
@@ -737,16 +759,17 @@ setup_connection_and_endpoint (TrackerDomainOntology    *domain,
                                TrackerEndpointDBus     **endpoint,
                                GError                  **error)
 {
-       GFile *store;
-       GFile *ontology;
+       GFile *store, *ontology;
 
-       store = tracker_domain_ontology_get_cache (domain);
+       store = get_cache_dir (domain);
        ontology = tracker_domain_ontology_get_ontology (domain);
        *sparql_conn = tracker_sparql_connection_new (get_fts_connection_flags (),
                                                      store,
                                                      ontology,
                                                      NULL,
                                                      error);
+       g_object_unref (store);
+
        if (!*sparql_conn)
                return FALSE;
 
@@ -900,7 +923,7 @@ main (gint argc, gchar *argv[])
        }
 
        /* If the locales changed, we need to reset some things first */
-       detect_locale_changed (TRACKER_MINER (miner_files));
+       detect_locale_changed (TRACKER_MINER (miner_files), domain_ontology);
 
        proxy = tracker_miner_proxy_new (miner_files, connection, DBUS_PATH, NULL, &error);
        if (error) {
@@ -951,7 +974,7 @@ main (gint argc, gchar *argv[])
        /* Check if we should crawl and if we should force mtime
         * checking based on the config.
         */
-       do_crawling = should_crawl (config, &force_mtime_checking);
+       do_crawling = should_crawl (miner_files, config, &force_mtime_checking);
 
        /* Get the last shutdown state to see if we need to perform a
         * full mtime check against the db or not.
@@ -965,7 +988,7 @@ main (gint argc, gchar *argv[])
        if (force_mtime_checking) {
                do_mtime_checking = TRUE;
        } else {
-               do_mtime_checking = tracker_miner_files_get_need_mtime_check ();
+               do_mtime_checking = tracker_miner_files_get_need_mtime_check (miner_files);
        }
 
        g_message ("  %s %s",
@@ -976,7 +999,7 @@ main (gint argc, gchar *argv[])
         * event of a crash, this is changed back on shutdown if
         * everything appears to be fine.
         */
-       tracker_miner_files_set_need_mtime_check (TRUE);
+       tracker_miner_files_set_need_mtime_check (miner_files, TRUE);
 
        /* Configure files miner */
        tracker_miner_files_set_mtime_checking (TRACKER_MINER_FILES (miner_files), do_mtime_checking);
@@ -995,8 +1018,8 @@ main (gint argc, gchar *argv[])
        g_message ("Shutdown started");
 
        if (miners_timeout_id == 0 && !miner_needs_check (miner_files)) {
-               tracker_miner_files_set_need_mtime_check (FALSE);
-               save_current_locale ();
+               tracker_miner_files_set_need_mtime_check (miner_files, FALSE);
+               save_current_locale (domain_ontology);
        }
 
        g_main_loop_unref (main_loop);
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 36829354b..2a75a3de2 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -86,6 +86,7 @@ struct TrackerMinerFilesPrivate {
        GSList *index_single_directories;
 
        gchar *domain;
+       TrackerDomainOntology *domain_ontology;
 
        guint disk_space_check_id;
        gboolean disk_space_pause;
@@ -578,6 +579,12 @@ miner_files_initable_init (GInitable     *initable,
 
        miner_files_update_filters (mf);
 
+       mf->private->domain_ontology = tracker_domain_ontology_new (mf->private->domain, NULL, &inner_error);
+       if (!mf->private->domain_ontology) {
+               g_propagate_error (error, inner_error);
+               return FALSE;
+       }
+
        /* Set up extractor and signals */
        mf->private->connection =  g_bus_get_sync (TRACKER_IPC_BUS, NULL, &inner_error);
        if (!mf->private->connection) {
@@ -929,6 +936,8 @@ miner_files_finalize (GObject *object)
        }
 #endif /* defined(HAVE_UPOWER) || defined(HAVE_HAL) */
 
+       tracker_domain_ontology_unref (priv->domain_ontology);
+
        if (priv->storage) {
                g_object_unref (priv->storage);
        }
@@ -1647,7 +1656,7 @@ check_battery_status (TrackerMinerFiles *mf)
                        if (!tracker_config_get_index_on_battery_first_time (mf->private->config)) {
                                g_message ("Running on battery, but not enabled, pausing");
                                should_pause = TRUE;
-                       } else if (tracker_miner_files_get_first_index_done ()) {
+                       } else if (tracker_miner_files_get_first_index_done (mf)) {
                                g_message ("Running on battery and first-time index "
                                           "already done, pausing");
                                should_pause = TRUE;
@@ -1714,8 +1723,8 @@ miner_finished_cb (TrackerMinerFS *fs,
        TrackerMinerFiles *mf = TRACKER_MINER_FILES (fs);
 
        /* Create stamp file if not already there */
-       if (!tracker_miner_files_get_first_index_done ()) {
-               tracker_miner_files_set_first_index_done (TRUE);
+       if (!tracker_miner_files_get_first_index_done (mf)) {
+               tracker_miner_files_set_first_index_done (mf, TRUE);
        }
 
        /* And remove the signal handler so that it's not
@@ -1750,9 +1759,20 @@ mount_pre_unmount_cb (GVolumeMonitor    *volume_monitor,
        g_free (uri);
 }
 
+static GFile *
+get_cache_dir (TrackerMinerFiles *mf)
+{
+       GFile *cache;
+
+       cache = tracker_domain_ontology_get_cache (mf->private->domain_ontology);
+       return g_object_ref (cache);
+}
+
+
 static gboolean
 disk_space_check (TrackerMinerFiles *mf)
 {
+       GFile *file;
        gint limit;
        gchar *data_dir;
        gdouble remaining;
@@ -1764,9 +1784,11 @@ disk_space_check (TrackerMinerFiles *mf)
        }
 
        /* Get % of remaining space in the partition where the cache is */
-       data_dir = g_build_filename (g_get_user_cache_dir (), "tracker", NULL);
+       file = get_cache_dir (mf);
+       data_dir = g_file_get_path (file);
        remaining = tracker_file_system_get_remaining_space_percentage (data_dir);
        g_free (data_dir);
+       g_object_unref (file);
 
        if (remaining <= limit) {
                g_message ("WARNING: Available disk space (%lf%%) is below "
@@ -2709,7 +2731,7 @@ miner_files_finished (TrackerMinerFS *fs,
        if (priv->thumbnailer)
                tracker_thumbnailer_send (priv->thumbnailer);
 
-       tracker_miner_files_set_last_crawl_done (TRUE);
+       tracker_miner_files_set_last_crawl_done (TRACKER_MINER_FILES (fs), TRUE);
 
        tracker_miner_files_check_unextracted (TRACKER_MINER_FILES (fs));
 }
@@ -3385,12 +3407,21 @@ tracker_miner_files_is_file_eligible (TrackerMinerFiles *miner,
 }
 
 inline static gchar *
-get_first_index_filename (void)
+get_first_index_filename (TrackerMinerFiles *mf)
 {
-       return g_build_filename (g_get_user_cache_dir (),
-                                "tracker",
+       GFile *file;
+       gchar *prefix, *path;
+
+       file = get_cache_dir (mf);
+       prefix = g_file_get_path (file);
+
+       path = g_build_filename (prefix,
                                 FIRST_INDEX_FILENAME,
                                 NULL);
+       g_free (prefix);
+       g_object_unref (file);
+
+       return path;
 }
 
 /**
@@ -3401,12 +3432,12 @@ get_first_index_filename (void)
  * Returns: %TRUE if a first full index have been done, %FALSE otherwise.
  **/
 gboolean
-tracker_miner_files_get_first_index_done (void)
+tracker_miner_files_get_first_index_done (TrackerMinerFiles *mf)
 {
        gboolean exists;
        gchar *filename;
 
-       filename = get_first_index_filename ();
+       filename = get_first_index_filename (mf);
        exists = g_file_test (filename, G_FILE_TEST_EXISTS);
        g_free (filename);
 
@@ -3421,12 +3452,13 @@ tracker_miner_files_get_first_index_done (void)
  *  the index is completed, should be set to %TRUE.
  **/
 void
-tracker_miner_files_set_first_index_done (gboolean done)
+tracker_miner_files_set_first_index_done (TrackerMinerFiles *mf,
+                                         gboolean           done)
 {
        gboolean already_exists;
        gchar *filename;
 
-       filename = get_first_index_filename ();
+       filename = get_first_index_filename (mf);
        already_exists = g_file_test (filename, G_FILE_TEST_EXISTS);
 
        if (done && !already_exists) {
@@ -3455,12 +3487,21 @@ tracker_miner_files_set_first_index_done (gboolean done)
 }
 
 static inline gchar *
-get_last_crawl_filename (void)
+get_last_crawl_filename (TrackerMinerFiles *mf)
 {
-       return g_build_filename (g_get_user_cache_dir (),
-                                "tracker",
+       GFile *file;
+       gchar *prefix, *path;
+
+       file = get_cache_dir (mf);
+       prefix = g_file_get_path (file);
+
+       path = g_build_filename (prefix,
                                 LAST_CRAWL_FILENAME,
                                 NULL);
+       g_free (prefix);
+       g_object_unref (file);
+
+       return path;
 }
 
 /**
@@ -3471,13 +3512,13 @@ get_last_crawl_filename (void)
  * Returns: time_t() value when last crawl occurred, otherwise 0.
  **/
 guint64
-tracker_miner_files_get_last_crawl_done (void)
+tracker_miner_files_get_last_crawl_done (TrackerMinerFiles *mf)
 {
        gchar *filename;
        gchar *content;
        guint64 then;
 
-       filename = get_last_crawl_filename ();
+       filename = get_last_crawl_filename (mf);
 
        if (!g_file_get_contents (filename, &content, NULL, NULL)) {
                g_info ("  No previous timestamp, crawling forced");
@@ -3496,12 +3537,13 @@ tracker_miner_files_get_last_crawl_done (void)
  * Set the time stamp of the last full index of files.
  **/
 void
-tracker_miner_files_set_last_crawl_done (gboolean done)
+tracker_miner_files_set_last_crawl_done (TrackerMinerFiles *mf,
+                                        gboolean           done)
 {
        gboolean already_exists;
        gchar *filename;
 
-       filename = get_last_crawl_filename ();
+       filename = get_last_crawl_filename (mf);
        already_exists = g_file_test (filename, G_FILE_TEST_EXISTS);
 
        if (done) {
@@ -3531,12 +3573,21 @@ tracker_miner_files_set_last_crawl_done (gboolean done)
 }
 
 inline static gchar *
-get_need_mtime_check_filename (void)
+get_need_mtime_check_filename (TrackerMinerFiles *mf)
 {
-       return g_build_filename (g_get_user_cache_dir (),
-                                "tracker",
+       GFile *file;
+       gchar *prefix, *path;
+
+       file = get_cache_dir (mf);
+       prefix = g_file_get_path (file);
+
+       path = g_build_filename (prefix,
                                 NEED_MTIME_CHECK_FILENAME,
                                 NULL);
+       g_free (prefix);
+       g_object_unref (file);
+
+       return path;
 }
 
 /**
@@ -3548,12 +3599,12 @@ get_need_mtime_check_filename (void)
  * the database on the next start for the miner-fs, %FALSE otherwise.
  **/
 gboolean
-tracker_miner_files_get_need_mtime_check (void)
+tracker_miner_files_get_need_mtime_check (TrackerMinerFiles *mf)
 {
        gboolean exists;
        gchar *filename;
 
-       filename = get_need_mtime_check_filename ();
+       filename = get_need_mtime_check_filename (mf);
        exists = g_file_test (filename, G_FILE_TEST_EXISTS);
        g_free (filename);
 
@@ -3578,12 +3629,13 @@ tracker_miner_files_get_need_mtime_check (void)
  * other uncontrolled shutdown reason).
  **/
 void
-tracker_miner_files_set_need_mtime_check (gboolean needed)
+tracker_miner_files_set_need_mtime_check (TrackerMinerFiles *mf,
+                                         gboolean           needed)
 {
        gboolean already_exists;
        gchar *filename;
 
-       filename = get_need_mtime_check_filename ();
+       filename = get_need_mtime_check_filename (mf);
        already_exists = g_file_test (filename, G_FILE_TEST_EXISTS);
 
        /* !needed = add file
diff --git a/src/miners/fs/tracker-miner-files.h b/src/miners/fs/tracker-miner-files.h
index 648c025cd..79a7bd79d 100644
--- a/src/miners/fs/tracker-miner-files.h
+++ b/src/miners/fs/tracker-miner-files.h
@@ -72,14 +72,17 @@ gboolean      tracker_miner_files_is_file_eligible         (TrackerMinerFiles *m
                                                             GFile             *file);
 
 /* Global functions to handle timestamp files */
-gboolean tracker_miner_files_get_first_index_done (void);
-void     tracker_miner_files_set_first_index_done (gboolean done);
+gboolean tracker_miner_files_get_first_index_done (TrackerMinerFiles *mf);
+void     tracker_miner_files_set_first_index_done (TrackerMinerFiles *mf,
+                                                   gboolean           done);
 
-guint64  tracker_miner_files_get_last_crawl_done  (void);
-void     tracker_miner_files_set_last_crawl_done  (gboolean done);
+guint64  tracker_miner_files_get_last_crawl_done  (TrackerMinerFiles *mf);
+void     tracker_miner_files_set_last_crawl_done  (TrackerMinerFiles *mf,
+                                                   gboolean           done);
 
-gboolean tracker_miner_files_get_need_mtime_check (void);
-void     tracker_miner_files_set_need_mtime_check (gboolean needed);
+gboolean tracker_miner_files_get_need_mtime_check (TrackerMinerFiles *mf);
+void     tracker_miner_files_set_need_mtime_check (TrackerMinerFiles *mf,
+                                                   gboolean           needed);
 
 void     tracker_miner_files_set_mtime_checking   (TrackerMinerFiles *miner,
                                                    gboolean           mtime_checking);


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