tracker r2212 - in branches/indexer-split: . src/libtracker-common src/libtracker-db src/tracker-indexer src/trackerd



Author: mr
Date: Wed Sep 10 15:04:18 2008
New Revision: 2212
URL: http://svn.gnome.org/viewvc/tracker?rev=2212&view=rev

Log:
	* src/libtracker-common/tracker-file-utils.[ch]:
	* src/tracker-indexer/tracker-main.c: 
	* src/trackerd/tracker-main.c: 
	(tracker_env_check_xdg_dirs): Added this function to make sure we
	have write access to XDG_DATA_HOME. On the Maemo platform, this is
	/usr/share, on Ubuntu this is $HOME/.local/share. We default to
	the later in cases where we don't have write access and can't
	create the XDG_DATA_HOME location.


Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/libtracker-common/tracker-file-utils.c
   branches/indexer-split/src/libtracker-common/tracker-file-utils.h
   branches/indexer-split/src/libtracker-db/tracker-db-manager.c
   branches/indexer-split/src/tracker-indexer/tracker-main.c
   branches/indexer-split/src/trackerd/tracker-main.c

Modified: branches/indexer-split/src/libtracker-common/tracker-file-utils.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-file-utils.c	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-file-utils.c	Wed Sep 10 15:04:18 2008
@@ -707,3 +707,118 @@
 
 	return final_path;
 }
+
+static gboolean
+path_has_write_access (const gchar *path,
+		       gboolean    *exists)
+{
+	GFile     *file;
+	GFileInfo *info;
+	GError    *error = NULL;
+        gboolean   writable;
+
+        g_return_val_if_fail (path != NULL, FALSE);
+        g_return_val_if_fail (path[0] != '\0', FALSE);
+
+        file = g_file_new_for_path (path);
+	info = g_file_query_info (file,
+                                  G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
+                                  0,
+                                  NULL, 
+                                  &error);
+        g_object_unref (file);
+      
+	if (error) {
+                if (error->code == G_IO_ERROR_NOT_FOUND) {
+                        if (exists) {
+                                *exists = FALSE;
+                        }
+                } else {
+			g_warning ("Could not check if we have write access for "
+				   "path '%s', %s",
+				   path,
+				   error->message);
+		}
+
+		g_error_free (error);
+                       
+		return FALSE;
+	}
+
+        if (exists) {
+                *exists = TRUE;
+        }
+
+        writable = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+        g_object_unref (info);
+
+        return writable;
+}
+
+static gboolean
+path_has_write_access_or_was_created (const gchar *path)
+{
+        gboolean writable;
+        gboolean exists;
+
+        writable = path_has_write_access (path, &exists);
+        if (exists) {
+                if (writable) {
+                        g_message ("  Path is OK");
+                        return TRUE;
+                } 
+                  
+                g_message ("  Path can not be written to");
+        } else {
+                g_message ("  Path does not exist, attempting to create...");
+
+                if (g_mkdir_with_parents (path, 0700) == 0) {
+                        g_message ("  Path was created");
+                        return TRUE;
+                }
+
+                g_message ("  Path could not be created");
+        }
+	
+	return FALSE;
+}
+
+gboolean
+tracker_env_check_xdg_dirs (void)
+{
+        const gchar *user_data_dir;
+        gchar       *new_dir;
+        gboolean     success;
+
+        g_message ("Checking XDG_DATA_HOME is writable and exists");
+
+	/* NOTE: We don't use g_get_user_data_dir() here because as
+	 * soon as we do, it sets the result and doesn't re-fetch the
+	 * XDG_DATA_HOME environment variable which we set below.
+	 */
+	user_data_dir = g_getenv ("XDG_DATA_HOME");
+
+	/* Check the default XDG_DATA_HOME location */
+        g_message ("  XDG_DATA_HOME is '%s'", user_data_dir);
+
+	if (path_has_write_access_or_was_created (user_data_dir)) {
+		return TRUE;
+	}
+
+        /* Change environment, this is actually what we have on Ubuntu. */
+        new_dir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".local", "share", NULL);
+
+	/* Check the new XDG_DATA_HOME location */
+	success = g_setenv ("XDG_DATA_HOME", new_dir, TRUE);
+
+	if (success) {
+		g_message ("  XDG_DATA_HOME set to '%s'", new_dir);
+		success = path_has_write_access_or_was_created (new_dir);
+	} else {
+		g_message ("  XDG_DATA_HOME could not be set");
+	}
+
+	g_free (new_dir);
+
+	return success;
+}

Modified: branches/indexer-split/src/libtracker-common/tracker-file-utils.h
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-file-utils.h	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-file-utils.h	Wed Sep 10 15:04:18 2008
@@ -44,5 +44,6 @@
 void     tracker_path_hash_table_filter_duplicates (GHashTable  *roots);
 GSList * tracker_path_list_filter_duplicates       (GSList      *roots);
 gchar *  tracker_path_evaluate_name                (const gchar *uri);
+gboolean tracker_env_check_xdg_dirs                (void);
 
 #endif /* __LIBTRACKER_COMMON_FILE_UTILS_H__ */

Modified: branches/indexer-split/src/libtracker-db/tracker-db-manager.c
==============================================================================
--- branches/indexer-split/src/libtracker-db/tracker-db-manager.c	(original)
+++ branches/indexer-split/src/libtracker-db/tracker-db-manager.c	Wed Sep 10 15:04:18 2008
@@ -2289,13 +2289,13 @@
 	g_message ("Setting database locations");
 
 	services_dir = g_build_filename (SHAREDIR, 
-					    "tracker", 
-					    "services", 
-					    NULL);
+					 "tracker", 
+					 "services", 
+					 NULL);
 	sql_dir = g_build_filename (SHAREDIR, 
-				       "tracker", 
-				       NULL);
-
+				    "tracker", 
+				    NULL);
+	
 	user_data_dir = g_build_filename (g_get_user_data_dir (), 
                                           "tracker", 
                                           "data", 

Modified: branches/indexer-split/src/tracker-indexer/tracker-main.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-main.c	(original)
+++ branches/indexer-split/src/tracker-indexer/tracker-main.c	Wed Sep 10 15:04:18 2008
@@ -229,7 +229,6 @@
         }
 
         if (!run_forever) {
-
                 g_message ("Waiting another %d seconds for more items before quitting...",
                            QUIT_TIMEOUT);
 
@@ -280,6 +279,11 @@
 
 	initialize_signal_handler ();
 
+        /* Check XDG spec locations XDG_DATA_HOME _MUST_ be writable. */
+        if (!tracker_env_check_xdg_dirs ()) {
+                return EXIT_FAILURE;
+        }
+
         /* Initialize logging */
         config = tracker_config_new ();
 

Modified: branches/indexer-split/src/trackerd/tracker-main.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-main.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-main.c	Wed Sep 10 15:04:18 2008
@@ -705,6 +705,11 @@
 
 	initialize_signal_handler ();
 
+        /* Check XDG spec locations XDG_DATA_HOME _MUST_ be writable. */
+        if (!tracker_env_check_xdg_dirs ()) {
+                return EXIT_FAILURE;
+        }
+
 	/* Set IO priority */
 	tracker_ioprio_init ();
 



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