[tracker/wip/carlosg/domain-ontologies: 44/124] libtracker-data: Move journal deletion code to tracker-db-journal.c



commit d0a5a611aa508d2a5e8bda0d538048d762f83a86
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Jun 6 12:18:57 2017 +0200

    libtracker-data: Move journal deletion code to tracker-db-journal.c
    
    And call it directly from the "tracker reset" subcommand, which seems
    about the only place where this is needed.
    
    In the future, we should just consider cache/journal directory ours,
    delete those altogether, and avoid these horrible layering breaks.

 src/libtracker-data/tracker-data-manager.c |    2 +-
 src/libtracker-data/tracker-db-journal.c   |   76 +++++++++++++++++++++---
 src/libtracker-data/tracker-db-journal.h   |    3 +-
 src/libtracker-data/tracker-db-manager.c   |   91 +--------------------------
 src/libtracker-data/tracker-db-manager.h   |    2 +-
 src/tracker/tracker-reset.c                |    4 +-
 tests/libtracker-data/tracker-db-journal.c |    5 --
 7 files changed, 79 insertions(+), 104 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 4e5f7af..6f9bc45 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -4608,7 +4608,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 
                        if (g_error_matches (internal_error, TRACKER_DB_INTERFACE_ERROR, 
TRACKER_DB_NO_SPACE)) {
                                GError *n_error = NULL;
-                               tracker_db_manager_remove_all (FALSE);
+                               tracker_db_manager_remove_all ();
                                tracker_db_manager_shutdown ();
                                /* Call may fail without notice, we're in error handling already.
                                 * When fails it means that close() of journal file failed. */
diff --git a/src/libtracker-data/tracker-db-journal.c b/src/libtracker-data/tracker-db-journal.c
index 11ff97a..8bd3f2b 100644
--- a/src/libtracker-data/tracker-db-journal.c
+++ b/src/libtracker-data/tracker-db-journal.c
@@ -682,14 +682,6 @@ tracker_db_journal_get_size (void)
        return writer.cur_size;
 }
 
-const gchar *
-tracker_db_journal_get_filename (void)
-{
-       /* Journal doesn't have to be open to get the filename, for example when
-        * the file didn't exist and it was attempted opened in only read mode. */
-       return (const gchar*) writer.journal_filename;
-}
-
 static gboolean
 db_journal_writer_start_transaction (JournalWriter    *jwriter,
                                      time_t            time,
@@ -2198,6 +2190,74 @@ tracker_db_journal_rotate (GError **error)
        return ret;
 }
 
+void
+tracker_db_journal_remove (void)
+{
+       gchar *path;
+       gchar *directory;
+       const gchar *dirs[3] = { NULL, NULL, NULL };
+       guint i;
+       GError *error = NULL;
+
+       /* We duplicate the path here because later we shutdown the
+        * journal which frees this data. We want to survive that.
+        */
+       path = g_strdup (writer.journal_filename);
+       if (!path) {
+               return;
+       }
+
+       g_info ("  Removing journal:'%s'", path);
+
+       directory = g_path_get_dirname (path);
+       tracker_db_journal_shutdown (&error);
+
+       if (error) {
+               /* TODO: propagate error */
+               g_info ("Ignored error while shutting down journal during remove: %s",
+                       error->message ? error->message : "No error given");
+               g_error_free (error);
+       }
+
+       dirs[0] = directory;
+       dirs[1] = rotating_settings.do_rotating ? rotating_settings.rotate_to : NULL;
+
+       for (i = 0; dirs[i] != NULL; i++) {
+               GDir *journal_dir;
+               const gchar *f;
+
+               journal_dir = g_dir_open (dirs[i], 0, NULL);
+               if (!journal_dir) {
+                       continue;
+               }
+
+               /* Remove rotated chunks */
+               while ((f = g_dir_read_name (journal_dir)) != NULL) {
+                       gchar *fullpath;
+
+                       if (!g_str_has_prefix (f, TRACKER_DB_JOURNAL_FILENAME ".")) {
+                               continue;
+                       }
+
+                       fullpath = g_build_filename (dirs[i], f, NULL);
+                       if (g_unlink (fullpath) == -1) {
+                               g_info ("Could not unlink rotated journal: %m");
+                       }
+                       g_free (fullpath);
+               }
+
+               g_dir_close (journal_dir);
+       }
+
+       g_free (directory);
+
+       /* Remove active journal */
+       if (g_unlink (path) == -1) {
+               g_info ("%s", g_strerror (errno));
+       }
+       g_free (path);
+}
+
 #else /* DISABLE_JOURNAL */
 void
 tracker_db_journal_set_rotating (gboolean     do_rotating,
diff --git a/src/libtracker-data/tracker-db-journal.h b/src/libtracker-data/tracker-db-journal.h
index 30c064e..62d360c 100644
--- a/src/libtracker-data/tracker-db-journal.h
+++ b/src/libtracker-data/tracker-db-journal.h
@@ -66,7 +66,6 @@ gboolean     tracker_db_journal_init                         (GFile        *data
                                                               GError      **error);
 gboolean     tracker_db_journal_shutdown                     (GError      **error);
 
-const gchar* tracker_db_journal_get_filename                 (void);
 gsize        tracker_db_journal_get_size                     (void);
 
 void         tracker_db_journal_set_rotating                 (gboolean     do_rotating,
@@ -149,6 +148,8 @@ gdouble      tracker_db_journal_reader_get_progress          (TrackerDBJournalRe
 gboolean     tracker_db_journal_reader_verify_last           (GFile                   *data_location,
                                                               GError                 **error);
 
+void         tracker_db_journal_remove                       (void);
+
 G_END_DECLS
 
 #endif /* __LIBTRACKER_DB_JOURNAL_H__ */
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 6e955f2..3e857b2 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -381,82 +381,7 @@ db_interface_create (TrackerDB db,
 }
 
 static void
-db_manager_remove_journal (void)
-{
-#ifndef DISABLE_JOURNAL
-       gchar *path;
-       gchar *directory, *rotate_to = NULL;
-       gsize chunk_size;
-       gboolean do_rotate = FALSE;
-       const gchar *dirs[3] = { NULL, NULL, NULL };
-       guint i;
-       GError *error = NULL;
-
-       /* We duplicate the path here because later we shutdown the
-        * journal which frees this data. We want to survive that.
-        */
-       path = g_strdup (tracker_db_journal_get_filename ());
-       if (!path) {
-               return;
-       }
-
-       g_info ("  Removing journal:'%s'", path);
-
-       directory = g_path_get_dirname (path);
-
-       tracker_db_journal_get_rotating (&do_rotate, &chunk_size, &rotate_to);
-       tracker_db_journal_shutdown (&error);
-
-       if (error) {
-               /* TODO: propagate error */
-               g_info ("Ignored error while shutting down journal during remove: %s",
-                       error->message ? error->message : "No error given");
-               g_error_free (error);
-       }
-
-       dirs[0] = directory;
-       dirs[1] = do_rotate ? rotate_to : NULL;
-
-       for (i = 0; dirs[i] != NULL; i++) {
-               GDir *journal_dir;
-               const gchar *f;
-
-               journal_dir = g_dir_open (dirs[i], 0, NULL);
-               if (!journal_dir) {
-                       continue;
-               }
-
-               /* Remove rotated chunks */
-               while ((f = g_dir_read_name (journal_dir)) != NULL) {
-                       gchar *fullpath;
-
-                       if (!g_str_has_prefix (f, TRACKER_DB_JOURNAL_FILENAME ".")) {
-                               continue;
-                       }
-
-                       fullpath = g_build_filename (dirs[i], f, NULL);
-                       if (g_unlink (fullpath) == -1) {
-                               g_info ("Could not unlink rotated journal: %m");
-                       }
-                       g_free (fullpath);
-               }
-
-               g_dir_close (journal_dir);
-       }
-
-       g_free (rotate_to);
-       g_free (directory);
-
-       /* Remove active journal */
-       if (g_unlink (path) == -1) {
-               g_info ("%s", g_strerror (errno));
-       }
-       g_free (path);
-#endif /* DISABLE_JOURNAL */
-}
-
-static void
-db_manager_remove_all (gboolean rm_journal)
+db_manager_remove_all (void)
 {
        guint i;
 
@@ -486,14 +411,6 @@ db_manager_remove_all (gboolean rm_journal)
                g_free (filename);
        }
 
-       if (rm_journal) {
-               db_manager_remove_journal ();
-
-               /* If also the journal is gone, we can also remove db-version.txt, it
-                * would have no more relevance whatsoever. */
-               tracker_db_manager_remove_version_file ();
-       }
-
        /* Remove locale file also */
        db_remove_locale_file ();
 }
@@ -741,7 +658,7 @@ db_recreate_all (GError **error)
         */
        g_info ("Cleaning up database files for reindex");
 
-       db_manager_remove_all (FALSE);
+       db_manager_remove_all ();
 
        /* Now create the databases and close them */
        g_info ("Creating database files, this may take a few moments...");
@@ -1318,11 +1235,11 @@ tracker_db_manager_shutdown (void)
 }
 
 void
-tracker_db_manager_remove_all (gboolean rm_journal)
+tracker_db_manager_remove_all (void)
 {
        g_return_if_fail (initialized != FALSE);
 
-       db_manager_remove_all (rm_journal);
+       db_manager_remove_all ();
 }
 
 void
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index 7911e13..1e79713 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -65,7 +65,7 @@ gboolean            tracker_db_manager_init                   (TrackerDBManagerF
                                                                const gchar            *busy_operation,
                                                                GError                **error);
 void                tracker_db_manager_shutdown               (void);
-void                tracker_db_manager_remove_all             (gboolean               rm_journal);
+void                tracker_db_manager_remove_all             (void);
 void                tracker_db_manager_optimize               (void);
 const gchar *       tracker_db_manager_get_file               (TrackerDB              db);
 TrackerDBInterface *tracker_db_manager_get_db_interface       (void);
diff --git a/src/tracker/tracker-reset.c b/src/tracker/tracker-reset.c
index 0093182..75630e3 100644
--- a/src/tracker/tracker-reset.c
+++ b/src/tracker/tracker-reset.c
@@ -320,9 +320,11 @@ reset_run (void)
                }
 #ifndef DISABLE_JOURNAL
                tracker_db_journal_init (data_location, FALSE, NULL);
+               tracker_db_journal_remove ();
 #endif /* DISABLE_JOURNAL */
 
-               tracker_db_manager_remove_all (hard_reset);
+               tracker_db_manager_remove_version_file ();
+               tracker_db_manager_remove_all ();
                tracker_db_manager_shutdown ();
 #ifndef DISABLE_JOURNAL
                tracker_db_journal_shutdown (NULL);
diff --git a/tests/libtracker-data/tracker-db-journal.c b/tests/libtracker-data/tracker-db-journal.c
index 3034e62..22b4b0b 100644
--- a/tests/libtracker-data/tracker-db-journal.c
+++ b/tests/libtracker-data/tracker-db-journal.c
@@ -69,7 +69,6 @@ static void
 test_write_functions (void)
 {
        gchar *path;
-       const gchar *filename;
        gsize initial_size, actual_size;
        gboolean result;
        GError *error = NULL;
@@ -89,10 +88,6 @@ test_write_functions (void)
        g_object_unref (data_location);
        g_assert_no_error (error);
 
-       filename = tracker_db_journal_get_filename ();
-       g_assert (filename != NULL);
-       g_assert_cmpstr (filename, ==, path);
-
        /* Size is 8 due to header */
        actual_size = tracker_db_journal_get_size ();
        g_assert_cmpint (actual_size, ==, 8);


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