[tracker] create the journal location



commit bccea0c0b76d8208c73aa937bcf72c72bcc3fffe
Author: Saleem Abdulrasool <compnerd compnerd org>
Date:   Thu Jan 21 23:25:22 2010 -0800

    create the journal location
    
    If the base directory where the journal is being written to does not exist, when
    trying to create the journal file, the call will fail as the parent directory
    does not exist.  To prevent this failure scenario, first create the directory
    structure before attempting to create the journal.

 src/libtracker-db/tracker-db-journal.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-db/tracker-db-journal.c b/src/libtracker-db/tracker-db-journal.c
index 836577f..1f84c48 100644
--- a/src/libtracker-db/tracker-db-journal.c
+++ b/src/libtracker-db/tracker-db-journal.c
@@ -192,6 +192,7 @@ tracker_db_journal_error_quark (void)
 gboolean
 tracker_db_journal_init (const gchar *filename)
 {
+	gchar *directory;
 	struct stat st;
 	int flags;
 	int mode;
@@ -215,6 +216,23 @@ tracker_db_journal_init (const gchar *filename)
 		                                            NULL);
 	}
 
+	directory = g_path_get_dirname (writer.journal_filename);
+	if (g_strcmp0 (directory, ".")) {
+		mode = S_IRWXU | S_IRWXG | S_IRWXO;
+		if (g_mkdir_with_parents (directory, mode)) {
+			g_critical ("tracker data directory does not exist and "
+				    "could not be created: %s",
+				    g_strerror (errno));
+
+			g_free (directory);
+			g_free (writer.journal_filename);
+			writer.journal_filename = NULL;
+
+			return FALSE;
+		}
+	}
+	g_free (directory);
+
 	mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
 	flags = O_WRONLY | O_APPEND | O_CREAT;
 	writer.journal = g_open (writer.journal_filename, flags, mode);



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