[tracker-miners/wip/carlosg/delay-monitors: 18/19] tracker-miner-fs: Avoid ancillary file to mark first-index
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/delay-monitors: 18/19] tracker-miner-fs: Avoid ancillary file to mark first-index
- Date: Sun, 8 Nov 2020 21:07:06 +0000 (UTC)
commit 6e61b626e6867e4babfd8e432bba2c7febee512d
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Nov 8 20:47:05 2020 +0100
tracker-miner-fs: Avoid ancillary file to mark first-index
We have a better cue now, we can check that the cache dir exists or
not. Do that, and avoid this file.
src/miners/fs/tracker-main.c | 10 ++-
src/miners/fs/tracker-miner-files.c | 119 ++++++------------------------------
src/miners/fs/tracker-miner-files.h | 6 +-
3 files changed, 28 insertions(+), 107 deletions(-)
---
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 03041685b..dc9c9f699 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -581,7 +581,9 @@ check_eligible (void)
/* Create new TrackerMinerFiles object */
config = tracker_config_new ();
miner_files = tracker_miner_files_new (sparql_conn, config,
- domain_ontology_name, NULL);
+ domain_ontology_name,
+ FALSE,
+ NULL);
g_object_unref (config);
if (!miner_files) {
@@ -903,6 +905,7 @@ main (gint argc, gchar *argv[])
GMemoryMonitor *memory_monitor;
#endif
gchar *domain_name, *dbus_name;
+ gboolean first_run = TRUE;
main_loop = NULL;
@@ -989,6 +992,7 @@ main (gint argc, gchar *argv[])
if (!dry_run) {
GFile *store = get_cache_dir (domain_ontology);
+ first_run = !g_file_query_exists (store, NULL);
tracker_error_report_init (store);
g_object_unref (store);
}
@@ -1008,7 +1012,9 @@ main (gint argc, gchar *argv[])
/* Create new TrackerMinerFiles object */
miner_files = tracker_miner_files_new (sparql_conn, config,
- domain_ontology_name, &error);
+ domain_ontology_name,
+ first_run,
+ &error);
if (!miner_files) {
g_critical ("Couldn't create new Files miner: '%s'",
error ? error->message : "unknown error");
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index f0c69e820..7513fc124 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -48,9 +48,6 @@
#define DISK_SPACE_CHECK_FREQUENCY 10
#define SECONDS_PER_DAY 86400
-/* Stamp files to know crawling/indexing state */
-#define FIRST_INDEX_FILENAME "first-index.txt"
-
#define DEFAULT_GRAPH "tracker:FileSystem"
#define FILE_ATTRIBUTES \
@@ -86,6 +83,7 @@ struct TrackerMinerFilesPrivate {
gboolean low_battery_pause;
gboolean start_extractor;
+ gboolean first_run;
#if defined(HAVE_UPOWER) || defined(HAVE_HAL)
TrackerPower *power;
@@ -1271,7 +1269,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 (mf)) {
+ } else if (mf->private->first_run) {
g_message ("Running on battery and first-time index "
"already done, pausing");
should_pause = TRUE;
@@ -1337,11 +1335,6 @@ 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 (mf)) {
- tracker_miner_files_set_first_index_done (mf, TRUE);
- }
-
/* And remove the signal handler so that it's not
* called again */
if (mf->private->finished_handler) {
@@ -2518,19 +2511,25 @@ TrackerMiner *
tracker_miner_files_new (TrackerSparqlConnection *connection,
TrackerConfig *config,
const gchar *domain,
+ gboolean first_run,
GError **error)
{
- return g_initable_new (TRACKER_TYPE_MINER_FILES,
- NULL,
- error,
- "connection", connection,
- "root", NULL,
- "config", config,
- "domain", domain,
- "processing-pool-wait-limit", 1,
- "processing-pool-ready-limit", 100,
- "file-attributes", FILE_ATTRIBUTES,
- NULL);
+ TrackerMinerFiles *mf;
+
+ mf = g_initable_new (TRACKER_TYPE_MINER_FILES,
+ NULL,
+ error,
+ "connection", connection,
+ "root", NULL,
+ "config", config,
+ "domain", domain,
+ "processing-pool-wait-limit", 1,
+ "processing-pool-ready-limit", 100,
+ "file-attributes", FILE_ATTRIBUTES,
+ NULL);
+ mf->private->first_run = first_run;
+
+ return TRACKER_MINER (mf);
}
static void
@@ -2685,83 +2684,3 @@ miner_files_add_removable_or_optical_directory (TrackerMinerFiles *mf,
flags);
g_object_unref (mount_point_file);
}
-
-inline static gchar *
-get_first_index_filename (TrackerMinerFiles *mf)
-{
- 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;
-}
-
-/**
- * tracker_miner_files_get_first_index_done:
- *
- * Check if first full index of files was already done.
- *
- * Returns: %TRUE if a first full index have been done, %FALSE otherwise.
- **/
-gboolean
-tracker_miner_files_get_first_index_done (TrackerMinerFiles *mf)
-{
- gboolean exists;
- gchar *filename;
-
- filename = get_first_index_filename (mf);
- exists = g_file_test (filename, G_FILE_TEST_EXISTS);
- g_free (filename);
-
- return exists;
-}
-
-/**
- * tracker_miner_files_set_first_index_done:
- *
- * Set the status of the first full index of files. Should be set to
- * %FALSE if the index was never done or if a reindex is needed. When
- * the index is completed, should be set to %TRUE.
- **/
-void
-tracker_miner_files_set_first_index_done (TrackerMinerFiles *mf,
- gboolean done)
-{
- gboolean already_exists;
- gchar *filename;
-
- filename = get_first_index_filename (mf);
- already_exists = g_file_test (filename, G_FILE_TEST_EXISTS);
-
- if (done && !already_exists) {
- GError *error = NULL;
-
- /* If done, create stamp file if not already there */
- if (!g_file_set_contents (filename, PACKAGE_VERSION, -1, &error)) {
- g_warning (" Could not create file:'%s' failed, %s",
- filename,
- error->message);
- g_error_free (error);
- } else {
- g_info (" First index file:'%s' created", filename);
- }
- } else if (!done && already_exists) {
- /* If NOT done, remove stamp file */
- g_info (" Removing first index file:'%s'", filename);
-
- if (g_remove (filename)) {
- g_warning (" Could not remove file:'%s': %m",
- filename);
- }
- }
-
- g_free (filename);
-}
diff --git a/src/miners/fs/tracker-miner-files.h b/src/miners/fs/tracker-miner-files.h
index 16e8deb1e..0fa134822 100644
--- a/src/miners/fs/tracker-miner-files.h
+++ b/src/miners/fs/tracker-miner-files.h
@@ -51,13 +51,9 @@ GType tracker_miner_files_get_type (void) G_GNUC_CONST;
TrackerMiner *tracker_miner_files_new (TrackerSparqlConnection *connection,
TrackerConfig *config,
const gchar *domain,
+ gboolean first_run,
GError **error);
-/* Global functions to handle timestamp files */
-gboolean tracker_miner_files_get_first_index_done (TrackerMinerFiles *mf);
-void tracker_miner_files_set_first_index_done (TrackerMinerFiles *mf,
- gboolean done);
-
G_END_DECLS
#endif /* __TRACKER_MINER_FS_FILES_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]