[evolution-data-server] Comply with XDG Base Directory Specification.



commit 2f00a805a78bb80729c5f7c801e31facc9123611
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Jun 7 09:17:44 2010 -0400

    Comply with XDG Base Directory Specification.
    
    This changes the output of the base directory functions:
    
    e_get_user_cache_dir()  now returns  "$XDG_CACHE_HOME/evolution"
    e_get_user_config_dir() now returns  "$XDG_CONFIG_HOME/evolution"
    e_get_user_data_dir()   now returns  "$XDG_DATA_HOME/evolution"
    
    Also, fix test cases with hard-coded directories.

 calendar/backends/file/e-cal-backend-file.c |    3 ++-
 calendar/tests/ecal/cleanup.sh              |    8 +++++++-
 calendar/tests/ecal/test-ecal.c             |    9 +++------
 calendar/tests/ecal/test-runner.sh          |   16 +++++++++++-----
 libedataserver/e-categories.c               |   17 ++++++++++++++++-
 libedataserver/e-data-server-util.c         |   18 +++++++++++++-----
 6 files changed, 52 insertions(+), 19 deletions(-)
---
diff --git a/calendar/backends/file/e-cal-backend-file.c b/calendar/backends/file/e-cal-backend-file.c
index 54e4942..e558eec 100644
--- a/calendar/backends/file/e-cal-backend-file.c
+++ b/calendar/backends/file/e-cal-backend-file.c
@@ -2707,10 +2707,11 @@ fetch_attachments (ECalBackendSync *backend, ECalComponent *comp)
 
 	e_cal_component_get_attachment_list (comp, &attach_list);
 	e_cal_component_get_uid (comp, &uid);
+
 	/*FIXME  get the uri rather than computing the path */
 	user_data_dir = e_get_user_data_dir ();
 	attach_store = g_build_filename (
-		user_data_dir, "calendar", "local", "system", NULL);
+		user_data_dir, "calendar", "system", NULL);
 
 	for (l = attach_list; l; l = l->next) {
 		gchar *sfname = (gchar *)l->data;
diff --git a/calendar/tests/ecal/cleanup.sh b/calendar/tests/ecal/cleanup.sh
index 5d2cd02..1a4cf74 100755
--- a/calendar/tests/ecal/cleanup.sh
+++ b/calendar/tests/ecal/cleanup.sh
@@ -1,4 +1,10 @@
 #! /bin/sh
-rm -rf $HOME/.evolution/calendar/local/OnThisComputer/Test*
+
+if [ -z $XDG_DATA_HOME ]
+then
+	XDG_DATA_HOME=$HOME/.local
+fi
+
+rm -rf $XDG_DATA_HOME/calendar/OnThisComputer/Test*
 rm -f tmp/*.out
 
diff --git a/calendar/tests/ecal/test-ecal.c b/calendar/tests/ecal/test-ecal.c
index f71f026..9a73841 100644
--- a/calendar/tests/ecal/test-ecal.c
+++ b/calendar/tests/ecal/test-ecal.c
@@ -455,8 +455,7 @@ test_new_system_calendar(void)
 
 	user_data_dir = e_get_user_data_dir ();
 	filename = g_build_filename (
-		user_data_dir, "calendar", "local",
-		"system", "calendar.ics", NULL);
+		user_data_dir, "calendar", "system", "calendar.ics", NULL);
 	created = g_file_test (filename, G_FILE_TEST_EXISTS);
 	g_free (filename);
 
@@ -477,8 +476,7 @@ test_new_system_tasks(void)
 
 	user_data_dir = e_get_user_data_dir ();
 	filename = g_build_filename (
-		user_data_dir, "tasks", "local",
-		"system", "tasks.ics", NULL);
+		user_data_dir, "tasks", "system", "tasks.ics", NULL);
 	created = g_file_test (filename, G_FILE_TEST_EXISTS);
 	g_free (filename);
 
@@ -499,8 +497,7 @@ test_new_system_memos(void)
 
 	user_data_dir = e_get_user_data_dir ();
 	filename = g_build_filename (
-		user_data_dir, "memos", "local",
-		"system", "journal.ics", NULL);
+		user_data_dir, "memos", "system", "journal.ics", NULL);
 	created = g_file_test (filename, G_FILE_TEST_EXISTS);
 	g_free (filename);
 
diff --git a/calendar/tests/ecal/test-runner.sh b/calendar/tests/ecal/test-runner.sh
index 17709ac..b9ea6c4 100755
--- a/calendar/tests/ecal/test-runner.sh
+++ b/calendar/tests/ecal/test-runner.sh
@@ -1,6 +1,12 @@
 #! /bin/sh
 # Usage : Argument 1 specifies the no. of libecal client instances would be
 # executed 
+
+if [ -z $XDG_DATA_HOME ]
+then
+	XDG_DATA_HOME=$HOME/.local
+fi
+
 i=0
 if [ ! -d tmp ] 
 then
@@ -9,13 +15,13 @@ fi
 while [ $i -ne $1 ] 
 do
 i=$(($i+1))
-if [ ! -d $HOME/.evolution/calendar/local/OnThisComputer/TestCal$i ] 
+if [ ! -d $XDG_DATA_HOME/calendar/local/OnThisComputer/TestCal$i ] 
 then
-	mkdir $HOME/.evolution/calendar/local/OnThisComputer/TestCal$i
+	mkdir $XDG_DATA_HOME/calendar/local/OnThisComputer/TestCal$i
 fi
-cp -f testdata.ics $HOME/.evolution/calendar/local/OnThisComputer/TestCal$i/calendar.ics
-./test-ecal $HOME/.evolution/calendar/local/OnThisComputer/TestCal $i | tee -i "tmp/$i.out" & 
-#./test-ecal $HOME/.evolution/calendar/local/OnThisComputer/TestCal $i > "tmp/$i.out" & 
+cp -f testdata.ics $XDG_DATA_HOME/calendar/local/OnThisComputer/TestCal$i/calendar.ics
+./test-ecal $XDG_DATA_HOME/calendar/local/OnThisComputer/TestCal $i | tee -i "tmp/$i.out" & 
+#./test-ecal $XDG_DATA_HOME/calendar/local/OnThisComputer/TestCal $i > "tmp/$i.out" & 
 done
 dateTest=`date`
 echo "End of testing at: $dateTest"
diff --git a/libedataserver/e-categories.c b/libedataserver/e-categories.c
index c087d15..b7988d8 100644
--- a/libedataserver/e-categories.c
+++ b/libedataserver/e-categories.c
@@ -20,6 +20,7 @@
 #include <config.h>
 #include <string.h>
 #include <libxml/parser.h>
+#include <glib/gstdio.h>
 #include <glib/gi18n-lib.h>
 #include <gconf/gconf-client.h>
 #include "e-data-server-util.h"
@@ -121,10 +122,24 @@ static gchar *
 build_categories_filename (void)
 {
 	const gchar *user_data_dir;
+	gchar *filename;
 
 	user_data_dir = e_get_user_data_dir ();
+	filename = g_build_filename (user_data_dir, "categories.xml", NULL);
+
+	if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
+		gchar *old_filename;
+
+		/* Try moving the file from its old 2.x location.
+		 * This is best effort; don't worry about errors. */
+		old_filename = g_build_filename (
+			g_get_home_dir (), ".evolution",
+			"categories.xml", NULL);
+		g_rename (old_filename, filename);
+		g_free (old_filename);
+	}
 
-	return g_build_filename (user_data_dir, "categories.xml", NULL);
+	return filename;
 }
 
 static void
diff --git a/libedataserver/e-data-server-util.c b/libedataserver/e-data-server-util.c
index a03221d..b2a5a61 100644
--- a/libedataserver/e-data-server-util.c
+++ b/libedataserver/e-data-server-util.c
@@ -51,8 +51,8 @@ e_get_user_cache_dir (void)
 	static gchar *dirname = NULL;
 
 	if (G_UNLIKELY (dirname == NULL)) {
-		const gchar *data_dir = e_get_user_data_dir ();
-		dirname = g_build_filename (data_dir, "cache", NULL);
+		const gchar *cache_dir = g_get_user_cache_dir ();
+		dirname = g_build_filename (cache_dir, "evolution", NULL);
 		g_mkdir_with_parents (dirname, 0700);
 	}
 
@@ -73,7 +73,15 @@ e_get_user_cache_dir (void)
 const gchar *
 e_get_user_config_dir (void)
 {
-	return e_get_user_data_dir ();
+	static gchar *dirname = NULL;
+
+	if (G_UNLIKELY (dirname == NULL)) {
+		const gchar *config_dir = g_get_user_config_dir ();
+		dirname = g_build_filename (config_dir, "evolution", NULL);
+		g_mkdir_with_parents (dirname, 0700);
+	}
+
+	return dirname;
 }
 
 /**
@@ -93,8 +101,8 @@ e_get_user_data_dir (void)
 	static gchar *dirname = NULL;
 
 	if (G_UNLIKELY (dirname == NULL)) {
-		const gchar *home_dir = g_get_home_dir ();
-		dirname = g_build_filename (home_dir, ".evolution", NULL);
+		const gchar *data_dir = g_get_user_data_dir ();
+		dirname = g_build_filename (data_dir, "evolution", NULL);
 		g_mkdir_with_parents (dirname, 0700);
 	}
 



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