[tracker/journal-rotating] libtracker-db: Support for moving rotated chunks to another location



commit 5e1a35da9eb7a4c6113593d38a430d839372902c
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon May 10 17:51:48 2010 +0200

    libtracker-db: Support for moving rotated chunks to another location

 src/libtracker-common/tracker-keyfile-object.c    |   21 ++
 src/libtracker-common/tracker-keyfile-object.h    |    2 +
 src/libtracker-data/tracker-data-backup.c         |    9 +-
 src/libtracker-data/tracker-data-manager.c        |   10 +-
 src/libtracker-data/tracker-data-manager.h        |    1 +
 src/libtracker-data/tracker-data-update.c         |    7 +-
 src/libtracker-db/tracker-db-journal.c            |   63 ++++++-
 src/libtracker-db/tracker-db-journal.h            |    6 +-
 src/libtracker-db/tracker-db-manager.c            |  205 +++++++++++++--------
 src/tracker-control/tracker-control.c             |   39 ++++-
 src/tracker-store/tracker-config.c                |   98 +++++++++--
 src/tracker-store/tracker-config.h                |    3 +
 src/tracker-store/tracker-main.c                  |    6 +
 tests/libtracker-data/tracker-backup-test.c       |    4 +-
 tests/libtracker-data/tracker-ontology-test.c     |   12 +-
 tests/libtracker-data/tracker-sparql-blank-test.c |    2 +-
 tests/libtracker-data/tracker-sparql-test.c       |    2 +-
 tests/libtracker-db/tracker-db-journal.c          |    8 +-
 tests/libtracker-fts/tracker-fts-test.c           |    2 +-
 19 files changed, 382 insertions(+), 118 deletions(-)
---
diff --git a/src/libtracker-common/tracker-keyfile-object.c b/src/libtracker-common/tracker-keyfile-object.c
index 422eb0a..8db76f8 100644
--- a/src/libtracker-common/tracker-keyfile-object.c
+++ b/src/libtracker-common/tracker-keyfile-object.c
@@ -93,6 +93,27 @@ tracker_keyfile_object_default_boolean (gpointer     object,
 	return bspec->default_value;
 }
 
+const gchar*
+tracker_keyfile_object_default_string (gpointer     object,
+                                       const gchar *property)
+{
+	GObjectClass *klass;
+	GParamSpec *spec;
+	GParamSpecString *bspec;
+
+	g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
+	g_return_val_if_fail (property != NULL, FALSE);
+
+	klass = G_OBJECT_GET_CLASS (object);
+	spec = g_object_class_find_property (G_OBJECT_CLASS (klass), property);
+	g_return_val_if_fail (spec != NULL, FALSE);
+
+	bspec = G_PARAM_SPEC_STRING (spec);
+	g_return_val_if_fail (bspec != NULL, FALSE);
+
+	return bspec->default_value;
+}
+
 gint
 tracker_keyfile_object_default_int (gpointer     object,
                                     const gchar *property)
diff --git a/src/libtracker-common/tracker-keyfile-object.h b/src/libtracker-common/tracker-keyfile-object.h
index c06cfcb..18135ab 100644
--- a/src/libtracker-common/tracker-keyfile-object.h
+++ b/src/libtracker-common/tracker-keyfile-object.h
@@ -34,6 +34,8 @@ gboolean     tracker_keyfile_object_default_boolean  (gpointer      object,
                                                       const gchar  *property);
 gint         tracker_keyfile_object_default_int      (gpointer      object,
                                                       const gchar  *property);
+const gchar* tracker_keyfile_object_default_string   (gpointer      object,
+                                                      const gchar  *property);
 gboolean     tracker_keyfile_object_validate_int     (gpointer      object,
                                                       const gchar  *property,
                                                       gint          value);
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index f08f4d0..9862d5b 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -349,6 +349,7 @@ tracker_data_backup_restore (GFile *journal,
 		gboolean is_first;
 		gsize chunk_size = 0;
 		gboolean do_rotating = FALSE;
+		gchar *rotate_to = NULL;
 		GFile *parent = g_file_get_parent (info->destination);
 		gchar *tmp_stdout = NULL;
 		gchar *tmp_stderr = NULL;
@@ -393,8 +394,8 @@ tracker_data_backup_restore (GFile *journal,
 		g_strfreev (argv);
 
 		tracker_db_manager_init_locations ();
-		tracker_db_journal_get_rotating (&do_rotating, &chunk_size);
-		tracker_db_journal_init (NULL, FALSE, do_rotating, chunk_size);
+		tracker_db_journal_get_rotating (&do_rotating, &chunk_size, &rotate_to);
+		tracker_db_journal_init (NULL, FALSE, do_rotating, chunk_size, rotate_to);
 
 		if (info->error) {
 			tracker_db_manager_restore_from_temp ();
@@ -404,11 +405,13 @@ tracker_data_backup_restore (GFile *journal,
 
 		tracker_db_journal_shutdown ();
 
-		tracker_data_manager_init (flags, do_rotating, chunk_size,
+		tracker_data_manager_init (flags, do_rotating, chunk_size, rotate_to,
 		                           test_schemas, &is_first, TRUE,
 		                           busy_callback, busy_user_data,
 		                           "Restoring backup");
 
+		g_free (rotate_to);
+
 	} else {
 		g_set_error (&info->error, TRACKER_DATA_BACKUP_ERROR, 0, 
 		             "Backup file doesn't exist");
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index ddc5ea6..13c806d 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -2030,6 +2030,7 @@ gboolean
 tracker_data_manager_init (TrackerDBManagerFlags  flags,
                            gboolean               do_journal_rotating,
                            gsize                  chunk_size,
+                           const gchar           *rotate_to,
                            const gchar          **test_schemas,
                            gboolean              *first_time,
                            gboolean               journal_check,
@@ -2121,7 +2122,8 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 		in_journal_replay = FALSE;
 
 		/* open journal for writing */
-		tracker_db_journal_init (NULL, FALSE, do_journal_rotating, chunk_size);
+		tracker_db_journal_init (NULL, FALSE, do_journal_rotating, chunk_size,
+		                         rotate_to);
 
 		check_ontology = TRUE;
 
@@ -2134,7 +2136,8 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 
 		/* Truncate journal as it does not even contain a single valid transaction
 		 * or is explicitly ignored (journal_check == FALSE, only for test cases) */
-		tracker_db_journal_init (NULL, TRUE, do_journal_rotating, chunk_size);
+		tracker_db_journal_init (NULL, TRUE, do_journal_rotating, chunk_size,
+		                         rotate_to);
 
 		/* load ontology from files into memory (max_id starts at zero: first-time) */
 
@@ -2195,7 +2198,8 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 		/* First time, no need to check ontology */
 		check_ontology = FALSE;
 	} else {
-		tracker_db_journal_init (NULL, FALSE, do_journal_rotating, chunk_size);
+		tracker_db_journal_init (NULL, FALSE, do_journal_rotating, chunk_size,
+		                         rotate_to);
 
 		/* Load ontology from database into memory */
 		db_get_static_data (iface);
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index e8876fb..2c7f331 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -42,6 +42,7 @@ G_BEGIN_DECLS
 gboolean tracker_data_manager_init                (TrackerDBManagerFlags  flags,
                                                    gboolean               do_journal_rotating,
                                                    gsize                  chunk_size,
+                                                   const gchar           *rotate_to,
                                                    const gchar          **test_schema,
                                                    gboolean              *first_time,
                                                    gboolean               journal_check,
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 485eed6..ff8132c 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2800,16 +2800,19 @@ tracker_data_replay_journal (GHashTable          *classes,
 		gsize size;
 		gsize chunk_size = 0;
 		gboolean do_rotating = FALSE;
+		gchar *rotate_to = NULL;
 
 		size = tracker_db_journal_reader_get_size_of_correct ();
 		tracker_db_journal_reader_shutdown ();
 
-		tracker_db_journal_get_rotating (&do_rotating, &chunk_size);
+		tracker_db_journal_get_rotating (&do_rotating, &chunk_size, &rotate_to);
 
-		tracker_db_journal_init (NULL, FALSE, do_rotating, chunk_size);
+		tracker_db_journal_init (NULL, FALSE, do_rotating, chunk_size, rotate_to);
 		tracker_db_journal_truncate (size);
 		tracker_db_journal_shutdown ();
 
+		g_free (rotate_to);
+
 		g_clear_error (&journal_error);
 	} else {
 		tracker_db_journal_reader_shutdown ();
diff --git a/src/libtracker-db/tracker-db-journal.c b/src/libtracker-db/tracker-db-journal.c
index 5db144d..be81059 100644
--- a/src/libtracker-db/tracker-db-journal.c
+++ b/src/libtracker-db/tracker-db-journal.c
@@ -98,6 +98,7 @@ static struct {
 	guint cur_pos;
 	gsize chunk_size;
 	gboolean do_rotating;
+	gchar *rotate_to;
 } writer;
 
 static guint32
@@ -276,7 +277,8 @@ gboolean
 tracker_db_journal_init (const gchar *filename,
                          gboolean     truncate,
                          gboolean     do_rotating,
-                         gsize        chunk_size)
+                         gsize        chunk_size,
+                         const gchar *rotate_to)
 {
 	gchar *directory;
 	int mode;
@@ -314,6 +316,11 @@ tracker_db_journal_init (const gchar *filename,
 	writer.do_rotating = do_rotating;
 	writer.chunk_size = chunk_size;
 
+	if (rotate_to)
+		writer.rotate_to = g_strdup (rotate_to);
+	else
+		writer.rotate_to = NULL;
+
 	return tracker_db_journal_init_file (truncate);
 }
 
@@ -332,6 +339,9 @@ tracker_db_journal_shutdown (void)
 
 	writer.journal = 0;
 
+	g_free (writer.rotate_to);
+	writer.rotate_to = NULL;
+
 	g_free (writer.journal_filename);
 	writer.journal_filename = NULL;
 
@@ -625,10 +635,33 @@ tracker_db_journal_truncate (gsize new_size)
 
 void
 tracker_db_journal_get_rotating (gboolean *do_rotating,
-                                 gsize    *chunk_size)
+                                 gsize    *chunk_size,
+                                 gchar   **rotate_to)
 {
 	*do_rotating = writer.do_rotating;
 	*chunk_size = writer.chunk_size;
+	if (writer.rotate_to)
+		*rotate_to = g_strdup (writer.rotate_to);
+	else
+		*rotate_to = NULL;
+}
+
+static void
+on_chunk_copied_delete (GObject      *source_object,
+                        GAsyncResult *res,
+                        gpointer      user_data)
+{
+	GFile *source = G_FILE (source_object);
+	GError *error = NULL;
+
+	if (g_file_copy_finish (source, res, &error)) {
+		g_file_delete (G_FILE (source_object), NULL, &error);
+	}
+
+	if (error) {
+		g_critical ("Error moving rotated journal chunk: '%s'", error->message);
+		g_error_free (error);
+	}
 }
 
 static gboolean
@@ -636,6 +669,7 @@ tracker_db_journal_rotate (void)
 {
 	gchar *fullpath;
 	static guint max = 0;
+	static gboolean needs_move = FALSE;
 
 	if (max == 0) {
 		gchar *directory;
@@ -644,6 +678,10 @@ tracker_db_journal_rotate (void)
 
 		directory = g_path_get_dirname (writer.journal_filename);
 
+		if (!needs_move) {
+			needs_move = (g_strcmp0 (writer.rotate_to, directory) != 0);
+		}
+
 		journal_dir = g_dir_open (directory, 0, NULL);
 
 		f_name = g_dir_read_name (journal_dir);
@@ -688,6 +726,27 @@ tracker_db_journal_rotate (void)
 
 	g_free (fullpath);
 
+	if (max > 1 && needs_move) {
+		GFile *source, *destination;
+		GFile *dest_dir;
+		gchar *filename;
+
+		fullpath = g_strdup_printf ("%s.%d", writer.journal_filename, max - 1);
+		source = g_file_new_for_path (fullpath);
+		dest_dir = g_file_new_for_path (writer.rotate_to);
+		filename = g_path_get_basename (fullpath);
+		destination = g_file_get_child (dest_dir, filename);
+		g_object_unref (dest_dir);
+		g_free (filename);
+
+		g_file_copy_async (source, destination, G_FILE_COPY_OVERWRITE, 0,
+		                   NULL, NULL, NULL, on_chunk_copied_delete, NULL);
+
+		g_object_unref (destination);
+		g_object_unref (source);
+		g_free (fullpath);
+	}
+
 	return tracker_db_journal_init_file (TRUE);
 }
 
diff --git a/src/libtracker-db/tracker-db-journal.h b/src/libtracker-db/tracker-db-journal.h
index fefd515..2f4a441 100644
--- a/src/libtracker-db/tracker-db-journal.h
+++ b/src/libtracker-db/tracker-db-journal.h
@@ -51,13 +51,15 @@ GQuark       tracker_db_journal_error_quark                  (void);
 gboolean     tracker_db_journal_init                         (const gchar *filename,
                                                               gboolean     truncate,
                                                               gboolean     do_rotating,
-                                                              gsize        chunk_size);
+                                                              gsize        chunk_size,
+                                                              const gchar *journal_to);
 gboolean     tracker_db_journal_shutdown                     (void);
 
 const gchar* tracker_db_journal_get_filename                 (void);
 gsize        tracker_db_journal_get_size                     (void);
 void         tracker_db_journal_get_rotating                 (gboolean    *do_rotating,
-                                                              gsize       *chunk_size);
+                                                              gsize       *chunk_size,
+                                                              gchar      **rotate_to);
 
 gboolean     tracker_db_journal_start_transaction            (time_t       time);
 gboolean     tracker_db_journal_start_ontology_transaction   (time_t       time);
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index 7bcdfdb..e30dacb 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -422,9 +422,10 @@ db_manager_remove_all (gboolean rm_journal)
 		if (opath) {
 			GFile *file;
 			gchar *cpath;
-			gchar *directory;
-			GDir *journal_dir;
-			const gchar *f_name;
+			gchar *directory, *rotate_to = NULL;
+			gsize chunk_size;
+			gboolean do_rotate = FALSE;
+			const gchar *dirs[3] = { NULL, NULL, NULL };
 
 			cpath = g_strdup (opath);
 			tracker_db_journal_shutdown ();
@@ -432,30 +433,43 @@ db_manager_remove_all (gboolean rm_journal)
 			g_message ("  Removing journal:'%s'", cpath);
 
 			directory = g_path_get_dirname (cpath);
-			journal_dir = g_dir_open (directory, 0, NULL);
-			f_name = g_dir_read_name (journal_dir);
 
-			/* Remove rotated chunks */
-			while (f_name) {
-				gchar *fullpath;
+			tracker_db_journal_get_rotating (&do_rotate, &chunk_size, &rotate_to);
 
-				if (f_name) {
-					if (!g_str_has_prefix (f_name, TRACKER_DB_JOURNAL_FILENAME ".")) {
-						f_name = g_dir_read_name (journal_dir);
-						continue;
-					}
-				}
+			dirs[0] = directory;
+			dirs[1] = do_rotate ? rotate_to : NULL;
 
-				fullpath = g_build_filename (directory, f_name, NULL);
-				file = g_file_new_for_path (fullpath);
-				g_file_delete (file, NULL, NULL);
-				g_object_unref (file);
-				g_free (fullpath);
+			for (i = 0; dirs[i] != NULL; i++) {
+				GDir *journal_dir;
+				const gchar *f_name;
 
+				journal_dir = g_dir_open (dirs[i], 0, NULL);
 				f_name = g_dir_read_name (journal_dir);
+
+				/* Remove rotated chunks */
+				while (f_name) {
+					gchar *fullpath;
+
+					if (f_name) {
+						if (!g_str_has_prefix (f_name, TRACKER_DB_JOURNAL_FILENAME ".")) {
+							f_name = g_dir_read_name (journal_dir);
+							continue;
+						}
+					}
+
+					fullpath = g_build_filename (directory, f_name, NULL);
+					file = g_file_new_for_path (fullpath);
+					g_file_delete (file, NULL, NULL);
+					g_object_unref (file);
+					g_free (fullpath);
+
+					f_name = g_dir_read_name (journal_dir);
+				}
+
+				g_dir_close (journal_dir);
 			}
 
-			g_dir_close (journal_dir);
+			g_free (rotate_to);
 			g_free (directory);
 
 			/* Remove active journal */
@@ -1049,9 +1063,10 @@ tracker_db_manager_move_to_temp (void)
 {
 	guint i;
 	gchar *cpath, *new_filename;
-	gchar *directory;
-	GDir *journal_dir;
-	const gchar *f_name;
+	gchar *directory, *rotate_to = NULL;
+	const gchar *dirs[3] = { NULL, NULL, NULL };
+	gsize chunk_size = 0;
+	gboolean do_rotate = FALSE;
 
 	g_return_if_fail (initialized != FALSE);
 
@@ -1068,28 +1083,41 @@ tracker_db_manager_move_to_temp (void)
 	cpath = g_strdup (tracker_db_journal_get_filename ());
 
 	directory = g_path_get_dirname (cpath);
-	journal_dir = g_dir_open (directory, 0, NULL);
-	f_name = g_dir_read_name (journal_dir);
 
-	while (f_name) {
-		gchar *fullpath;
+	tracker_db_journal_get_rotating (&do_rotate, &chunk_size, &rotate_to);
 
-		if (f_name) {
-			if (!g_str_has_prefix (f_name, TRACKER_DB_JOURNAL_FILENAME ".")) {
-				f_name = g_dir_read_name (journal_dir);
-				continue;
+	dirs[0] = directory;
+	dirs[1] = do_rotate ? rotate_to : NULL;
+
+	for (i = 0; dirs[i] != NULL; i++) {
+		GDir *journal_dir;
+		const gchar *f_name;
+
+		journal_dir = g_dir_open (dirs[i], 0, NULL);
+		f_name = g_dir_read_name (journal_dir);
+
+		while (f_name) {
+			gchar *fullpath;
+
+			if (f_name) {
+				if (!g_str_has_prefix (f_name, TRACKER_DB_JOURNAL_FILENAME ".")) {
+					f_name = g_dir_read_name (journal_dir);
+					continue;
+				}
 			}
+
+			fullpath = g_build_filename (dirs[i], f_name, NULL);
+			new_filename = g_strdup_printf ("%s.tmp", fullpath);
+			g_rename (fullpath, new_filename);
+			g_free (new_filename);
+			g_free (fullpath);
+			f_name = g_dir_read_name (journal_dir);
 		}
 
-		fullpath = g_build_filename (directory, f_name, NULL);
-		new_filename = g_strdup_printf ("%s.tmp", fullpath);
-		g_rename (fullpath, new_filename);
-		g_free (new_filename);
-		g_free (fullpath);
-		f_name = g_dir_read_name (journal_dir);
+		g_dir_close (journal_dir);
 	}
 
-	g_dir_close (journal_dir);
+	g_free (rotate_to);
 	g_free (directory);
 
 	new_filename = g_strdup_printf ("%s.tmp", cpath);
@@ -1106,9 +1134,10 @@ tracker_db_manager_restore_from_temp (void)
 {
 	guint i;
 	gchar *cpath, *new_filename;
-	gchar *directory;
-	GDir *journal_dir;
-	const gchar *f_name;
+	gchar *directory, *rotate_to = NULL;
+	const gchar *dirs[3] = { NULL, NULL, NULL };
+	gsize chunk_size = 0;
+	gboolean do_rotate = FALSE;
 
 	g_return_if_fail (locations_initialized != FALSE);
 
@@ -1130,32 +1159,43 @@ tracker_db_manager_restore_from_temp (void)
 	g_free (new_filename);
 
 	directory = g_path_get_dirname (cpath);
-	journal_dir = g_dir_open (directory, 0, NULL);
-	f_name = g_dir_read_name (journal_dir);
+	tracker_db_journal_get_rotating (&do_rotate, &chunk_size, &rotate_to);
 
-	while (f_name) {
-		gchar *fullpath, *ptr;
+	dirs[0] = directory;
+	dirs[1] = do_rotate ? rotate_to : NULL;
 
-		if (f_name) {
-			if (!g_str_has_suffix (f_name, ".tmp")) {
-				f_name = g_dir_read_name (journal_dir);
-				continue;
+	for (i = 0; dirs[i] != NULL; i++) {
+		GDir *journal_dir;
+		const gchar *f_name;
+
+		journal_dir = g_dir_open (dirs[i], 0, NULL);
+		f_name = g_dir_read_name (journal_dir);
+
+		while (f_name) {
+			gchar *fullpath, *ptr;
+
+			if (f_name) {
+				if (!g_str_has_suffix (f_name, ".tmp")) {
+					f_name = g_dir_read_name (journal_dir);
+					continue;
+				}
 			}
-		}
 
-		fullpath = g_build_filename (directory, f_name, NULL);
-		new_filename = g_strdup (fullpath);
-		ptr = strstr (new_filename, ".tmp");
-		if (ptr) {
-			*ptr = '\0';
-			g_rename (fullpath, new_filename);
+			fullpath = g_build_filename (dirs[i], f_name, NULL);
+			new_filename = g_strdup (fullpath);
+			ptr = strstr (new_filename, ".tmp");
+			if (ptr) {
+				*ptr = '\0';
+				g_rename (fullpath, new_filename);
+			}
+			g_free (new_filename);
+			g_free (fullpath);
+			f_name = g_dir_read_name (journal_dir);
 		}
-		g_free (new_filename);
-		g_free (fullpath);
-		f_name = g_dir_read_name (journal_dir);
+		g_dir_close (journal_dir);
 	}
 
-	g_dir_close (journal_dir);
+	g_free (rotate_to);
 	g_free (directory);
 	g_free (cpath);
 }
@@ -1165,9 +1205,10 @@ tracker_db_manager_remove_temp (void)
 {
 	guint i;
 	gchar *cpath, *new_filename;
-	gchar *directory;
-	GDir *journal_dir;
-	const gchar *f_name;
+	gchar *directory, *rotate_to = NULL;
+	gsize chunk_size = 0;
+	gboolean do_rotate = FALSE;
+	const gchar *dirs[3] = { NULL, NULL, NULL };
 
 	g_return_if_fail (locations_initialized != FALSE);
 
@@ -1189,25 +1230,37 @@ tracker_db_manager_remove_temp (void)
 	g_free (new_filename);
 
 	directory = g_path_get_dirname (cpath);
-	journal_dir = g_dir_open (directory, 0, NULL);
-	f_name = g_dir_read_name (journal_dir);
+	tracker_db_journal_get_rotating (&do_rotate, &chunk_size, &rotate_to);
 
-	while (f_name) {
-		if (f_name) {
-			if (!g_str_has_suffix (f_name, ".tmp")) {
-				f_name = g_dir_read_name (journal_dir);
-				continue;
-			}
-		}
+	dirs[0] = directory;
+	dirs[1] = do_rotate ? rotate_to : NULL;
 
-		new_filename = g_build_filename (directory, f_name, NULL);
-		g_unlink (new_filename);
-		g_free (new_filename);
+	for (i = 0; dirs[i] != NULL; i++) {
+		GDir *journal_dir;
+		const gchar *f_name;
 
+		journal_dir = g_dir_open (dirs[i], 0, NULL);
 		f_name = g_dir_read_name (journal_dir);
+
+		while (f_name) {
+			if (f_name) {
+				if (!g_str_has_suffix (f_name, ".tmp")) {
+					f_name = g_dir_read_name (journal_dir);
+					continue;
+				}
+			}
+
+			new_filename = g_build_filename (dirs[i], f_name, NULL);
+			g_unlink (new_filename);
+			g_free (new_filename);
+
+			f_name = g_dir_read_name (journal_dir);
+		}
+
+		g_dir_close (journal_dir);
 	}
 
-	g_dir_close (journal_dir);
+	g_free (rotate_to);
 	g_free (directory);
 	g_free (cpath);
 }
diff --git a/src/tracker-control/tracker-control.c b/src/tracker-control/tracker-control.c
index 380b121..0e2be7e 100644
--- a/src/tracker-control/tracker-control.c
+++ b/src/tracker-control/tracker-control.c
@@ -401,6 +401,15 @@ main (int argc, char **argv)
 
 	if (hard_reset || soft_reset) {
 		guint log_handler_id;
+		gboolean do_rotating = FALSE;
+		gsize chunk_size = G_MAXSIZE;
+		gchar *rotate_to = NULL;
+		GKeyFile *key_file;
+		gchar *tracker_store_config;
+
+		tracker_store_config = g_build_filename (g_get_user_config_dir (),
+		                                         "tracker", "tracker-store.cfg",
+		                                         NULL);
 
 		/* Set log handler for library messages */
 		log_handler_id = g_log_set_handler (NULL,
@@ -410,8 +419,36 @@ main (int argc, char **argv)
 
 		g_log_set_default_handler (log_handler, NULL);
 
+		key_file = g_key_file_new ();
+
+		if (g_key_file_load_from_file (key_file, tracker_store_config,
+		                               G_KEY_FILE_NONE, NULL)) {
+			gint chunk_size;
+			GError *error = NULL;
+
+			chunk_size = g_key_file_get_integer (key_file, "Journal",
+			                                     "JournalChunkSize", &error);
+
+			if (error) {
+				g_clear_error (&error);
+			} else if (chunk_size > 0) {
+				do_rotating = TRUE;
+			}
+
+			rotate_to = g_key_file_get_string (key_file, "Journal",
+			                                   "JournalRotateDestination", &error);
+
+			if (error) {
+				g_error_free (error);
+				rotate_to = NULL;
+			}
+		}
+		
 		/* This call is needed to set the journal's filename */
-		tracker_db_journal_init (NULL, FALSE, FALSE, G_MAXSIZE);
+		tracker_db_journal_init (NULL, FALSE, do_rotating, chunk_size, rotate_to);
+
+		g_free (tracker_store_config);
+		g_key_file_free (key_file);
 
 		/* Clean up */
 		if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL, NULL, FALSE)) {
diff --git a/src/tracker-store/tracker-config.c b/src/tracker-store/tracker-config.c
index 5a5321a..bcd5d2d 100644
--- a/src/tracker-store/tracker-config.c
+++ b/src/tracker-store/tracker-config.c
@@ -36,9 +36,9 @@
 #define GROUP_JOURNAL     "Journal"
 
 /* Default values */
-#define DEFAULT_VERBOSITY                 2
-#define DEFAULT_JOURNAL_CHUNK_SIZE        500
-#define DEFAULT_ENABLE_JOURNAL_ROTATING   TRUE
+#define DEFAULT_VERBOSITY                    2
+#define DEFAULT_JOURNAL_CHUNK_SIZE           500
+#define DEFAULT_JOURNAL_ROTATE_DESTINATION   ""
 
 /* typedef struct TrackerConfigPrivate TrackerConfigPrivate; */
 
@@ -48,6 +48,7 @@ typedef struct {
 
 	/* Journal */
 	gint journal_chunk_size;
+	gchar *journal_rotate_destination;
 } TrackerConfigPrivate;
 
 typedef struct {
@@ -77,14 +78,20 @@ enum {
 
 	/* General */
 	PROP_VERBOSITY,
+
 	/* Journal */
 	PROP_JOURNAL_CHUNK_SIZE,
-	PROP_ENABLE_JOURNAL_ROTATING
+	PROP_JOURNAL_ROTATE_DESTINATION
 };
 
+/* If you change these values, please also check
+ * ../src/tracker-control/tracker-control.c~417 */
+
 static ObjectToKeyFile conversions[] = {
-	{ G_TYPE_INT,     "verbosity",               GROUP_GENERAL,  "Verbosity"             },
-	{ G_TYPE_INT,     "journal-chunk-size",      GROUP_JOURNAL,  "JournalChunkSize"      },
+	{ G_TYPE_INT,     "verbosity",                  GROUP_GENERAL,  "Verbosity"                },
+	{ G_TYPE_INT,     "journal-chunk-size",         GROUP_JOURNAL,  "JournalChunkSize"         },
+	{ G_TYPE_STRING,  "journal-rotate-destination", GROUP_JOURNAL,  "JournalRotateDestination" },
+
 };
 
 G_DEFINE_TYPE (TrackerConfig, tracker_config, TRACKER_TYPE_CONFIG_FILE);
@@ -112,12 +119,20 @@ tracker_config_class_init (TrackerConfigClass *klass)
 
 	g_object_class_install_property (object_class,
 	                                 PROP_JOURNAL_CHUNK_SIZE,
-	                                 g_param_spec_int    ("journal-chunk-size",
-	                                                      "Journal chunk size",
-	                                                      " Size of the journal at rotation in MB. Use -1 to disable rotating",
-	                                                      -1,
-	                                                      G_MAXINT,
-	                                                      DEFAULT_JOURNAL_CHUNK_SIZE,
+	                                 g_param_spec_int ("journal-chunk-size",
+	                                                   "Journal chunk size",
+	                                                   " Size of the journal at rotation in MB. Use -1 to disable rotating",
+	                                                   -1,
+	                                                   G_MAXINT,
+	                                                   DEFAULT_JOURNAL_CHUNK_SIZE,
+	                                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+	g_object_class_install_property (object_class,
+	                                 PROP_JOURNAL_ROTATE_DESTINATION,
+	                                 g_param_spec_string ("journal-rotate-destination",
+	                                                      "Journal rotate destination",
+	                                                      " Destination to rotate journal chunks to",
+	                                                      DEFAULT_JOURNAL_ROTATE_DESTINATION,
 	                                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
 	g_type_class_add_private (object_class, sizeof (TrackerConfigPrivate));
@@ -145,6 +160,10 @@ config_set_property (GObject      *object,
 		tracker_config_set_journal_chunk_size (TRACKER_CONFIG (object),
 		                                       g_value_get_int(value));
 		break;
+	case PROP_JOURNAL_ROTATE_DESTINATION:
+		tracker_config_set_journal_rotate_destination (TRACKER_CONFIG (object),
+		                                               g_value_get_string(value));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 		break;
@@ -169,6 +188,9 @@ config_get_property (GObject    *object,
 	case PROP_JOURNAL_CHUNK_SIZE:
 		g_value_set_int (value, priv->journal_chunk_size);
 		break;
+	case PROP_JOURNAL_ROTATE_DESTINATION:
+		g_value_set_string (value, priv->journal_rotate_destination);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 		break;
@@ -178,9 +200,11 @@ config_get_property (GObject    *object,
 static void
 config_finalize (GObject *object)
 {
-	/* For now we do nothing here, we left this override in for
-	 * future expansion.
-	 */
+	TrackerConfigPrivate *priv;
+
+	priv = TRACKER_CONFIG_GET_PRIVATE (object);
+
+	g_free (priv->journal_rotate_destination);
 
 	(G_OBJECT_CLASS (tracker_config_parent_class)->finalize) (object);
 }
@@ -230,6 +254,14 @@ config_create_with_defaults (TrackerConfig *config,
 			                                                                conversions[i].property));
 			break;
 
+		case G_TYPE_STRING:
+			g_key_file_set_string (key_file,
+			                       conversions[i].group,
+			                       conversions[i].key,
+			                       tracker_keyfile_object_default_string (config,
+			                                                              conversions[i].property));
+			break;
+
 		default:
 			g_assert_not_reached ();
 			break;
@@ -282,6 +314,14 @@ config_load (TrackerConfig *config)
 			                                     conversions[i].key);
 			break;
 
+		case G_TYPE_STRING:
+			tracker_keyfile_object_load_string (G_OBJECT (file),
+			                                    conversions[i].property,
+			                                    file->key_file,
+			                                    conversions[i].group,
+			                                    conversions[i].key);
+			break;
+
 		default:
 			g_assert_not_reached ();
 			break;
@@ -370,6 +410,18 @@ tracker_config_get_journal_chunk_size (TrackerConfig *config)
 	return priv->journal_chunk_size;
 }
 
+const gchar *
+tracker_config_get_journal_rotate_destination (TrackerConfig *config)
+{
+	TrackerConfigPrivate *priv;
+
+	g_return_val_if_fail (TRACKER_IS_CONFIG (config), DEFAULT_JOURNAL_ROTATE_DESTINATION);
+
+	priv = TRACKER_CONFIG_GET_PRIVATE (config);
+
+	return priv->journal_rotate_destination;
+}
+
 void
 tracker_config_set_journal_chunk_size (TrackerConfig *config,
                                        gint           value)
@@ -405,3 +457,19 @@ tracker_config_set_verbosity (TrackerConfig *config,
 	priv->verbosity = value;
 	g_object_notify (G_OBJECT (config), "verbosity");
 }
+
+void
+tracker_config_set_journal_rotate_destination (TrackerConfig *config,
+                                               const gchar   *value)
+{
+	TrackerConfigPrivate *priv;
+
+	g_return_if_fail (TRACKER_IS_CONFIG (config));
+
+	priv = TRACKER_CONFIG_GET_PRIVATE (config);
+
+	g_free (priv->journal_rotate_destination);
+	priv->journal_rotate_destination = g_strdup (value);
+
+	g_object_notify (G_OBJECT (config), "journal-rotate-destination");
+}
diff --git a/src/tracker-store/tracker-config.h b/src/tracker-store/tracker-config.h
index bde3cbc..2d56e4b 100644
--- a/src/tracker-store/tracker-config.h
+++ b/src/tracker-store/tracker-config.h
@@ -50,11 +50,14 @@ TrackerConfig *tracker_config_new                                  (void);
 gboolean       tracker_config_save                                 (TrackerConfig *config);
 gint           tracker_config_get_verbosity                        (TrackerConfig *config);
 gint           tracker_config_get_journal_chunk_size               (TrackerConfig *config);
+const gchar *  tracker_config_get_journal_rotate_destination       (TrackerConfig *config);
 
 void           tracker_config_set_verbosity                        (TrackerConfig *config,
                                                                     gint           value);
 void           tracker_config_set_journal_chunk_size               (TrackerConfig *config,
                                                                     gint           value);
+void           tracker_config_set_journal_rotate_destination       (TrackerConfig *config,
+                                                                    const gchar   *value);
 
 G_END_DECLS
 
diff --git a/src/tracker-store/tracker-main.c b/src/tracker-store/tracker-main.c
index 7006377..415f0d0 100644
--- a/src/tracker-store/tracker-main.c
+++ b/src/tracker-store/tracker-main.c
@@ -335,6 +335,7 @@ main (gint argc, gchar *argv[])
 	TrackerBusyCallback busy_callback;
 	gint chunk_size_mb;
 	gsize chunk_size;
+	const gchar *rotate_to;
 
 	g_type_init ();
 
@@ -441,10 +442,15 @@ main (gint argc, gchar *argv[])
 
 	chunk_size_mb = tracker_config_get_journal_chunk_size (config);
 	chunk_size = (gsize) ((gsize) chunk_size_mb * (gsize) 1024 * (gsize) 1024);
+	rotate_to = tracker_config_get_journal_rotate_destination (config);
+
+	if (rotate_to[0] == '\0')
+		rotate_to = NULL;
 
 	if (!tracker_data_manager_init (flags,
 	                                chunk_size_mb != -1,
 	                                chunk_size,
+	                                rotate_to,
 	                                NULL,
 	                                &is_first_time_index,
 	                                TRUE,
diff --git a/tests/libtracker-data/tracker-backup-test.c b/tests/libtracker-data/tracker-backup-test.c
index 01e0277..a668da6 100644
--- a/tests/libtracker-data/tracker-backup-test.c
+++ b/tests/libtracker-data/tracker-backup-test.c
@@ -106,7 +106,7 @@ test_backup_and_restore_helper (gboolean journal)
 	test_schemas[3] = data_prefix;
 
 	tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
-	                           FALSE, G_MAXSIZE,
+	                           FALSE, G_MAXSIZE, NULL,
 	                           (const gchar **) test_schemas,
 	                           NULL, FALSE, NULL, NULL, NULL);
 
@@ -159,7 +159,7 @@ test_backup_and_restore_helper (gboolean journal)
 	g_free (meta_db);
 
 	tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
-	                           FALSE, G_MAXSIZE,
+	                           FALSE, G_MAXSIZE, NULL,
 	                           (const gchar **) test_schemas,
 	                           NULL, FALSE, NULL, NULL, NULL);
 	check_content_in_db (0, 0);
diff --git a/tests/libtracker-data/tracker-ontology-test.c b/tests/libtracker-data/tracker-ontology-test.c
index 86ddf44..00a86db 100644
--- a/tests/libtracker-data/tracker-ontology-test.c
+++ b/tests/libtracker-data/tracker-ontology-test.c
@@ -264,7 +264,8 @@ test_ontology_change (void)
 
                 g_chmod (ontology_file, 0666);
 
-		tracker_data_manager_init (0, FALSE, G_MAXSIZE, (const gchar **) test_schemas,
+		tracker_data_manager_init (0, FALSE, G_MAXSIZE, NULL,
+		                           (const gchar **) test_schemas,
 		                           NULL, FALSE, NULL, NULL, NULL);
 
 		if (g_file_get_contents (update, &queries, NULL, NULL)) {
@@ -290,7 +291,8 @@ test_ontology_change (void)
 
 	delete_db (FALSE);
 
-	tracker_data_manager_init (0, FALSE, G_MAXSIZE, (const gchar **) test_schemas,
+	tracker_data_manager_init (0, FALSE, G_MAXSIZE, NULL,
+	                           (const gchar **) test_schemas,
 	                           NULL, TRUE, NULL, NULL, NULL);
 
 	for (i = 0; change_tests[i].test_name != NULL; i++) {
@@ -326,7 +328,7 @@ test_ontology_init (void)
 {
 	/* first-time initialization */
 	tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
-	                           FALSE, G_MAXSIZE,
+	                           FALSE, G_MAXSIZE, NULL,
 	                           NULL,
 	                           NULL,
 	                           FALSE,
@@ -337,7 +339,7 @@ test_ontology_init (void)
 	tracker_data_manager_shutdown ();
 
 	/* initialization from existing database */
-	tracker_data_manager_init (0, FALSE, G_MAXSIZE,
+	tracker_data_manager_init (0, FALSE, G_MAXSIZE, NULL,
 	                           NULL,
 	                           NULL,
 	                           FALSE,
@@ -369,7 +371,7 @@ test_query (gconstpointer test_data)
 
 	/* initialization */
 	tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
-	                           FALSE, G_MAXSIZE,
+	                           FALSE, G_MAXSIZE, NULL,
 	                           NULL,
 	                           NULL, 
 	                           FALSE,
diff --git a/tests/libtracker-data/tracker-sparql-blank-test.c b/tests/libtracker-data/tracker-sparql-blank-test.c
index ecdbf6c..bfa0ace 100644
--- a/tests/libtracker-data/tracker-sparql-blank-test.c
+++ b/tests/libtracker-data/tracker-sparql-blank-test.c
@@ -42,7 +42,7 @@ test_blank (void)
 
 	/* initialization */
 	tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
-	                           FALSE, G_MAXSIZE,
+	                           FALSE, G_MAXSIZE, NULL,
 	                           NULL,
 	                           NULL,
 	                           FALSE,
diff --git a/tests/libtracker-data/tracker-sparql-test.c b/tests/libtracker-data/tracker-sparql-test.c
index da9b78b..5299c5d 100644
--- a/tests/libtracker-data/tracker-sparql-test.c
+++ b/tests/libtracker-data/tracker-sparql-test.c
@@ -235,7 +235,7 @@ test_sparql_query (gconstpointer test_data)
 
 	test_schemas[0] = data_prefix;
 	tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
-	                           FALSE, G_MAXSIZE,
+	                           FALSE, G_MAXSIZE, NULL,
 	                           test_schemas,
 	                           NULL, FALSE, NULL, NULL, NULL);
 
diff --git a/tests/libtracker-db/tracker-db-journal.c b/tests/libtracker-db/tracker-db-journal.c
index 5a2c623..85d3606 100644
--- a/tests/libtracker-db/tracker-db-journal.c
+++ b/tests/libtracker-db/tracker-db-journal.c
@@ -29,13 +29,13 @@ test_init_and_shutdown (void)
 	gboolean result;
 
 	/* check double init/shutdown */
-	result = tracker_db_journal_init (NULL, FALSE, FALSE, G_MAXSIZE);
+	result = tracker_db_journal_init (NULL, FALSE, FALSE, G_MAXSIZE, NULL);
 	g_assert (result == TRUE);
 
 	result = tracker_db_journal_shutdown ();
 	g_assert (result == TRUE);
 
-	result = tracker_db_journal_init (NULL, FALSE, FALSE, G_MAXSIZE);
+	result = tracker_db_journal_init (NULL, FALSE, FALSE, G_MAXSIZE, NULL);
 	g_assert (result == TRUE);
 
 	result = tracker_db_journal_shutdown ();
@@ -53,9 +53,9 @@ test_write_functions (void)
 	path = g_build_filename (TOP_BUILDDIR, "tests", "libtracker-db", "tracker-store.journal", NULL);
 	g_unlink (path);
 
-	tracker_db_journal_init (path, FALSE, FALSE, G_MAXSIZE);
+	tracker_db_journal_init (path, FALSE, FALSE, G_MAXSIZE, NULL);
 
-        filename = tracker_db_journal_get_filename ();
+	filename = tracker_db_journal_get_filename ();
 	g_assert (filename != NULL);
 	g_assert_cmpstr (filename, ==, path);
 
diff --git a/tests/libtracker-fts/tracker-fts-test.c b/tests/libtracker-fts/tracker-fts-test.c
index 503dfdb..a66bdcb 100644
--- a/tests/libtracker-fts/tracker-fts-test.c
+++ b/tests/libtracker-fts/tracker-fts-test.c
@@ -73,7 +73,7 @@ test_sparql_query (gconstpointer test_data)
 
 	test_schemas[0] = data_prefix;
 	tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
-	                           FALSE, G_MAXSIZE,
+	                           FALSE, G_MAXSIZE, NULL,
 	                           test_schemas,
 	                           NULL, FALSE, NULL, NULL, NULL);
 



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