[tracker/wip/carlosg/domain-ontologies: 44/116] tracker-miner-fs: Adopt DBManager API to manipulate stamp files
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/domain-ontologies: 44/116] tracker-miner-fs: Adopt DBManager API to manipulate stamp files
- Date: Sun, 25 Jun 2017 13:08:51 +0000 (UTC)
commit b4a55302abadd1cb45ccf291be568fa9951cf3ce
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Jun 9 14:41:16 2017 +0200
tracker-miner-fs: Adopt DBManager API to manipulate stamp files
Those just matter for indexing purposes, so move all management here.
tracker-extract has just been made to equate SCHED_IDLE_FIRST_INDEX to
SCHED_ALWAYS.
src/libtracker-data/tracker-data-backup.c | 5 -
src/libtracker-data/tracker-db-manager.c | 254 -----------------------------
src/miners/fs/tracker-main.c | 12 +-
src/miners/fs/tracker-miner-files.c | 249 ++++++++++++++++++++++++++++-
src/miners/fs/tracker-miner-files.h | 10 +
src/tracker-extract/tracker-main.c | 6 +-
6 files changed, 263 insertions(+), 273 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index 5e4c3df..c9899df 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -660,11 +660,6 @@ tracker_data_backup_restore (GFile *journal,
* or after a backup restoration). */
tracker_db_manager_create_version_file ();
- /* Given we're radically changing the database, we
- * force a full mtime check against all known files in
- * the database for complete synchronisation. */
- tracker_db_manager_set_need_mtime_check (TRUE);
-
#ifndef DISABLE_JOURNAL
journal_writer = tracker_db_journal_new (data_location, FALSE, &n_error);
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 193ec0d..3d8d2c1 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -62,10 +62,6 @@
#define IN_USE_FILENAME ".meta.isrunning"
-/* Stamp files to know crawling/indexing state */
-#define FIRST_INDEX_FILENAME "first-index.txt"
-#define LAST_CRAWL_FILENAME "last-crawl.txt"
-#define NEED_MTIME_CHECK_FILENAME "no-need-mtime-check.txt"
#define PARSER_SHA1_FILENAME "parser-sha1.txt"
typedef enum {
@@ -387,11 +383,6 @@ db_manager_remove_all (void)
g_info ("Removing all database/storage files");
- /* Remove stamp files */
- tracker_db_manager_set_first_index_done (FALSE);
- tracker_db_manager_set_last_crawl_done (FALSE);
- tracker_db_manager_set_need_mtime_check (TRUE);
-
/* NOTE: We don't have to be initialized for this so we
* calculate the absolute directories here.
*/
@@ -832,7 +823,6 @@ db_manager_init_unlocked (TrackerDBManagerFlags flags,
if (need_reindex) {
tracker_db_manager_create_version_file ();
- tracker_db_manager_set_need_mtime_check (TRUE);
}
}
@@ -912,9 +902,6 @@ db_manager_init_unlocked (TrackerDBManagerFlags flags,
return FALSE;
}
- /* Clear the first-index stamp file */
- tracker_db_manager_set_first_index_done (FALSE);
-
perform_recreate (first_time, &internal_error);
if (internal_error) {
@@ -1419,247 +1406,6 @@ tracker_db_manager_has_enough_space (void)
return tracker_file_system_has_enough_space (data_dir, TRACKER_DB_MIN_REQUIRED_SPACE, FALSE);
}
-
-inline static gchar *
-get_first_index_filename (void)
-{
- return g_build_filename (data_dir,
- FIRST_INDEX_FILENAME,
- NULL);
-}
-
-/**
- * tracker_db_manager_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_db_manager_get_first_index_done (void)
-{
- gboolean exists;
- gchar *filename;
-
- filename = get_first_index_filename ();
- exists = g_file_test (filename, G_FILE_TEST_EXISTS);
- g_free (filename);
-
- return exists;
-}
-
-/**
- * tracker_db_manager_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_db_manager_set_first_index_done (gboolean done)
-{
- gboolean already_exists;
- gchar *filename;
-
- filename = get_first_index_filename ();
- 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', %s",
- filename,
- g_strerror (errno));
- }
- }
-
- g_free (filename);
-}
-
-inline static gchar *
-get_last_crawl_filename (void)
-{
- return g_build_filename (data_dir,
- LAST_CRAWL_FILENAME,
- NULL);
-}
-
-/**
- * tracker_db_manager_get_last_crawl_done:
- *
- * Check when last crawl was performed.
- *
- * Returns: time_t() value when last crawl occurred, otherwise 0.
- **/
-guint64
-tracker_db_manager_get_last_crawl_done (void)
-{
- gchar *filename;
- gchar *content;
- guint64 then;
-
- filename = get_last_crawl_filename ();
-
- if (!g_file_get_contents (filename, &content, NULL, NULL)) {
- g_info (" No previous timestamp, crawling forced");
- return 0;
- }
-
- then = g_ascii_strtoull (content, NULL, 10);
- g_free (content);
-
- return then;
-}
-
-/**
- * tracker_db_manager_set_last_crawl_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_db_manager_set_last_crawl_done (gboolean done)
-{
- gboolean already_exists;
- gchar *filename;
-
- filename = get_last_crawl_filename ();
- already_exists = g_file_test (filename, G_FILE_TEST_EXISTS);
-
- if (done && !already_exists) {
- GError *error = NULL;
- gchar *content;
-
- content = g_strdup_printf ("%" G_GUINT64_FORMAT, (guint64) time (NULL));
-
- /* If done, create stamp file if not already there */
- if (!g_file_set_contents (filename, content, -1, &error)) {
- g_warning (" Could not create file:'%s' failed, %s",
- filename,
- error->message);
- g_error_free (error);
- } else {
- g_info (" Last crawl file:'%s' created", filename);
- }
-
- g_free (content);
- } else if (!done && already_exists) {
- /* If NOT done, remove stamp file */
- g_info (" Removing last crawl file:'%s'", filename);
-
- if (g_remove (filename)) {
- g_warning (" Could not remove file:'%s', %s",
- filename,
- g_strerror (errno));
- }
- }
-
- g_free (filename);
-}
-
-inline static gchar *
-get_need_mtime_check_filename (void)
-{
- return g_build_filename (data_dir,
- NEED_MTIME_CHECK_FILENAME,
- NULL);
-}
-
-/**
- * tracker_db_manager_get_need_mtime_check:
- *
- * Check if the miner-fs was cleanly shutdown or not.
- *
- * Returns: %TRUE if we need to check mtimes for directories against
- * the database on the next start for the miner-fs, %FALSE otherwise.
- *
- * Since: 0.10
- **/
-gboolean
-tracker_db_manager_get_need_mtime_check (void)
-{
- gboolean exists;
- gchar *filename;
-
- filename = get_need_mtime_check_filename ();
- exists = g_file_test (filename, G_FILE_TEST_EXISTS);
- g_free (filename);
-
- /* Existence of the file means we cleanly shutdown before and
- * don't need to do the mtime check again on this start.
- */
- return !exists;
-}
-
-/**
- * tracker_db_manager_set_need_mtime_check:
- * @needed: a #gboolean
- *
- * If the next start of miner-fs should perform a full mtime check
- * against each directory found and those in the database (for
- * complete synchronisation), then @needed should be #TRUE, otherwise
- * #FALSE.
- *
- * Creates a file in $HOME/.cache/tracker/ if an mtime check is not
- * needed. The idea behind this is that a check is forced if the file
- * is not cleaned up properly on shutdown (i.e. due to a crash or any
- * other uncontrolled shutdown reason).
- *
- * Since: 0.10
- **/
-void
-tracker_db_manager_set_need_mtime_check (gboolean needed)
-{
- gboolean already_exists;
- gchar *filename;
-
- filename = get_need_mtime_check_filename ();
- already_exists = g_file_test (filename, G_FILE_TEST_EXISTS);
-
- /* !needed = add file
- * needed = remove file
- */
- if (!needed && !already_exists) {
- GError *error = NULL;
-
- /* 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 (" Need mtime check file:'%s' created", filename);
- }
- } else if (needed && already_exists) {
- /* Remove stamp file */
- g_info (" Removing need mtime check file:'%s'", filename);
-
- if (g_remove (filename)) {
- g_warning (" Could not remove file:'%s', %s",
- filename,
- g_strerror (errno));
- }
- }
-
- g_free (filename);
-}
-
inline static gchar *
get_parser_sha1_filename (void)
{
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 4e2f607..a7cdca3 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -220,7 +220,7 @@ should_crawl (TrackerConfig *config,
} else {
guint64 then, now;
- then = tracker_db_manager_get_last_crawl_done ();
+ then = tracker_miner_files_get_last_crawl_done ();
if (then < 1) {
return TRUE;
@@ -329,7 +329,7 @@ miner_finished_cb (TrackerMinerFS *fs,
if (TRACKER_IS_MINER_FILES (fs) &&
tracker_miner_fs_get_initial_crawling (fs)) {
- tracker_db_manager_set_last_crawl_done (TRUE);
+ tracker_miner_files_set_last_crawl_done (TRUE);
}
miner_handle_next ();
@@ -738,7 +738,7 @@ main (gint argc, gchar *argv[])
/* This makes sure we don't steal all the system's resources */
initialize_priority_and_scheduling (tracker_config_get_sched_idle (config),
- tracker_db_manager_get_first_index_done () == FALSE);
+ tracker_miner_files_get_first_index_done () == FALSE);
main_loop = g_main_loop_new (NULL, FALSE);
@@ -797,7 +797,7 @@ main (gint argc, gchar *argv[])
if (force_mtime_checking) {
do_mtime_checking = TRUE;
} else {
- do_mtime_checking = tracker_db_manager_get_need_mtime_check ();
+ do_mtime_checking = tracker_miner_files_get_need_mtime_check ();
}
g_message (" %s %s",
@@ -808,7 +808,7 @@ main (gint argc, gchar *argv[])
* event of a crash, this is changed back on shutdown if
* everything appears to be fine.
*/
- tracker_db_manager_set_need_mtime_check (TRUE);
+ tracker_miner_files_set_need_mtime_check (TRUE);
/* Configure files miner */
tracker_miner_fs_set_initial_crawling (TRACKER_MINER_FS (miner_files), do_crawling);
@@ -832,7 +832,7 @@ main (gint argc, gchar *argv[])
if (miners_timeout_id == 0 &&
!miner_needs_check (miner_files, store_available)) {
- tracker_db_manager_set_need_mtime_check (FALSE);
+ tracker_miner_files_set_need_mtime_check (FALSE);
}
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 e9dc1ef..e68ec07 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -49,6 +49,11 @@
#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 LAST_CRAWL_FILENAME "last-crawl.txt"
+#define NEED_MTIME_CHECK_FILENAME "no-need-mtime-check.txt"
+
#define TRACKER_MINER_FILES_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER_FILES,
TrackerMinerFilesPrivate))
static GQuark miner_files_error_quark = 0;
@@ -1342,7 +1347,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_db_manager_get_first_index_done ()) {
+ } else if (tracker_miner_files_get_first_index_done ()) {
g_message ("Running on battery and first-time index "
"already done, pausing");
should_pause = TRUE;
@@ -1413,8 +1418,8 @@ miner_finished_cb (TrackerMinerFS *fs,
TrackerMinerFiles *mf = TRACKER_MINER_FILES (fs);
/* Create stamp file if not already there */
- if (!tracker_db_manager_get_first_index_done ()) {
- tracker_db_manager_set_first_index_done (TRUE);
+ if (!tracker_miner_files_get_first_index_done ()) {
+ tracker_miner_files_set_first_index_done (TRUE);
}
/* And remove the signal handler so that it's not
@@ -2498,7 +2503,7 @@ miner_files_finished (TrackerMinerFS *fs,
gint files_found,
gint files_ignored)
{
- tracker_db_manager_set_last_crawl_done (TRUE);
+ tracker_miner_files_set_last_crawl_done (TRUE);
}
TrackerMiner *
@@ -2949,3 +2954,239 @@ tracker_miner_files_is_file_eligible (TrackerMinerFiles *miner,
/* file is eligible to be indexed */
return TRUE;
}
+
+inline static gchar *
+get_first_index_filename (void)
+{
+ return g_build_filename (g_get_user_cache_dir (),
+ "tracker",
+ FIRST_INDEX_FILENAME,
+ NULL);
+}
+
+/**
+ * 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 (void)
+{
+ gboolean exists;
+ gchar *filename;
+
+ filename = get_first_index_filename ();
+ 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 (gboolean done)
+{
+ gboolean already_exists;
+ gchar *filename;
+
+ filename = get_first_index_filename ();
+ 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);
+}
+
+static inline gchar *
+get_last_crawl_filename (void)
+{
+ return g_build_filename (g_get_user_cache_dir (),
+ "tracker",
+ LAST_CRAWL_FILENAME,
+ NULL);
+}
+
+/**
+ * tracker_miner_files_get_last_crawl_done:
+ *
+ * Check when last crawl was performed.
+ *
+ * Returns: time_t() value when last crawl occurred, otherwise 0.
+ **/
+guint64
+tracker_miner_files_get_last_crawl_done (void)
+{
+ gchar *filename;
+ gchar *content;
+ guint64 then;
+
+ filename = get_last_crawl_filename ();
+
+ if (!g_file_get_contents (filename, &content, NULL, NULL)) {
+ g_info (" No previous timestamp, crawling forced");
+ return 0;
+ }
+
+ then = g_ascii_strtoull (content, NULL, 10);
+ g_free (content);
+
+ return then;
+}
+
+/**
+ * tracker_miner_files_set_last_crawl_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_last_crawl_done (gboolean done)
+{
+ gboolean already_exists;
+ gchar *filename;
+
+ filename = get_last_crawl_filename ();
+ already_exists = g_file_test (filename, G_FILE_TEST_EXISTS);
+
+ if (done && !already_exists) {
+ GError *error = NULL;
+ gchar *content;
+
+ content = g_strdup_printf ("%" G_GUINT64_FORMAT, (guint64) time (NULL));
+
+ /* If done, create stamp file if not already there */
+ if (!g_file_set_contents (filename, content, -1, &error)) {
+ g_warning (" Could not create file:'%s' failed, %s",
+ filename,
+ error->message);
+ g_error_free (error);
+ } else {
+ g_info (" Last crawl file:'%s' created", filename);
+ }
+
+ g_free (content);
+ } else if (!done && already_exists) {
+ /* If NOT done, remove stamp file */
+ g_info (" Removing last crawl file:'%s'", filename);
+
+ if (g_remove (filename)) {
+ g_warning (" Could not remove file:'%s': %m",
+ filename);
+ }
+ }
+
+ g_free (filename);
+}
+
+inline static gchar *
+get_need_mtime_check_filename (void)
+{
+ return g_build_filename (g_get_user_cache_dir (),
+ "tracker",
+ NEED_MTIME_CHECK_FILENAME,
+ NULL);
+}
+
+/**
+ * tracker_miner_files_get_need_mtime_check:
+ *
+ * Check if the miner-fs was cleanly shutdown or not.
+ *
+ * Returns: %TRUE if we need to check mtimes for directories against
+ * the database on the next start for the miner-fs, %FALSE otherwise.
+ **/
+gboolean
+tracker_miner_files_get_need_mtime_check (void)
+{
+ gboolean exists;
+ gchar *filename;
+
+ filename = get_need_mtime_check_filename ();
+ exists = g_file_test (filename, G_FILE_TEST_EXISTS);
+ g_free (filename);
+
+ /* Existence of the file means we cleanly shutdown before and
+ * don't need to do the mtime check again on this start.
+ */
+ return !exists;
+}
+
+/**
+ * tracker_miner_files_set_need_mtime_check:
+ * @needed: a #gboolean
+ *
+ * If the next start of miner-fs should perform a full mtime check
+ * against each directory found and those in the database (for
+ * complete synchronisation), then @needed should be #TRUE, otherwise
+ * #FALSE.
+ *
+ * Creates a file in $HOME/.cache/tracker/ if an mtime check is not
+ * needed. The idea behind this is that a check is forced if the file
+ * is not cleaned up properly on shutdown (i.e. due to a crash or any
+ * other uncontrolled shutdown reason).
+ **/
+void
+tracker_miner_files_set_need_mtime_check (gboolean needed)
+{
+ gboolean already_exists;
+ gchar *filename;
+
+ filename = get_need_mtime_check_filename ();
+ already_exists = g_file_test (filename, G_FILE_TEST_EXISTS);
+
+ /* !needed = add file
+ * needed = remove file
+ */
+ if (!needed && !already_exists) {
+ GError *error = NULL;
+
+ /* 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 (" Need mtime check file:'%s' created", filename);
+ }
+ } else if (needed && already_exists) {
+ /* Remove stamp file */
+ g_info (" Removing need mtime check 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 e7cf5cb..10121b1 100644
--- a/src/miners/fs/tracker-miner-files.h
+++ b/src/miners/fs/tracker-miner-files.h
@@ -69,6 +69,16 @@ gboolean tracker_miner_files_monitor_directory (GFile *f
gboolean tracker_miner_files_is_file_eligible (TrackerMinerFiles *miner,
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);
+
+guint64 tracker_miner_files_get_last_crawl_done (void);
+void tracker_miner_files_set_last_crawl_done (gboolean done);
+
+gboolean tracker_miner_files_get_need_mtime_check (void);
+void tracker_miner_files_set_need_mtime_check (gboolean needed);
+
G_END_DECLS
#endif /* __TRACKER_MINER_FS_FILES_H__ */
diff --git a/src/tracker-extract/tracker-main.c b/src/tracker-extract/tracker-main.c
index 484371f..103c75b 100644
--- a/src/tracker-extract/tracker-main.c
+++ b/src/tracker-extract/tracker-main.c
@@ -274,8 +274,7 @@ run_standalone (TrackerConfig *config)
tracker_locale_sanity_check ();
/* This makes sure we don't steal all the system's resources */
- initialize_priority_and_scheduling (tracker_config_get_sched_idle (config),
- tracker_db_manager_get_first_index_done () == FALSE);
+ initialize_priority_and_scheduling (tracker_config_get_sched_idle (config), TRUE);
file = g_file_new_for_commandline_arg (filename);
uri = g_file_get_uri (file);
@@ -368,8 +367,7 @@ main (int argc, char *argv[])
initialize_directories ();
/* This makes sure we don't steal all the system's resources */
- initialize_priority_and_scheduling (tracker_config_get_sched_idle (config),
- tracker_db_manager_get_first_index_done () == FALSE);
+ initialize_priority_and_scheduling (tracker_config_get_sched_idle (config), TRUE);
extract = tracker_extract_new (TRUE, force_module);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]