tracker r1789 - in branches/indexer-split: . src/libtracker-common
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r1789 - in branches/indexer-split: . src/libtracker-common
- Date: Fri, 27 Jun 2008 10:14:32 +0000 (UTC)
Author: mr
Date: Fri Jun 27 10:14:32 2008
New Revision: 1789
URL: http://svn.gnome.org/viewvc/tracker?rev=1789&view=rev
Log:
* src/libtracker-common/tracker-file-utils.[ch]:
* src/libtracker-common/tracker-config.c:
* src/libtracker-common/tracker-module-config.c: Added
tracker_path_evaluate_name() to convert $HOME and "~/foo" into
real paths. This is now used by the module config and the main
config module when loading directory strings or string lists.
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/src/libtracker-common/tracker-config.c
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-common/tracker-module-config.c
Modified: branches/indexer-split/src/libtracker-common/tracker-config.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-config.c (original)
+++ branches/indexer-split/src/libtracker-common/tracker-config.c Fri Jun 27 10:14:32 2008
@@ -30,6 +30,7 @@
#include "tracker-language.h"
#include "tracker-config.h"
+#include "tracker-file-utils.h"
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_CONFIG, TrackerConfigPriv))
@@ -906,31 +907,6 @@
return directory;
}
-static gchar *
-config_dir_validate_name (const gchar *original_path)
-{
- gchar resolved_path[PATH_MAX + 2];
-
- if (!original_path || original_path[0] == '\0') {
- return NULL;
- }
-
- if (original_path[0] == '~') {
- const char *home = g_get_home_dir ();
-
- if (!home || home[0] == '\0') {
- return NULL;
- }
-
- return g_build_path (G_DIR_SEPARATOR_S,
- home,
- original_path + 1,
- NULL);
- }
-
- return g_strdup (realpath (original_path, resolved_path));
-}
-
static gboolean
config_dir_is_child_of (const char *dir,
const char *dir_to_test)
@@ -1255,7 +1231,7 @@
/* For directories we validate any special characters,
* for example '~' and '../../'
*/
- validated = config_dir_validate_name (str);
+ validated = tracker_path_evaluate_name (str);
if (validated) {
list = g_slist_prepend (list, validated);
}
@@ -2483,7 +2459,7 @@
priv = GET_PRIV (config);
for (p = roots; *p; p++) {
- validated_root = config_dir_validate_name (*p);
+ validated_root = tracker_path_evaluate_name (*p);
if (!validated_root) {
g_print ("Root '%s' is not valid to add to watch directory list\n",
validated_root);
@@ -2516,7 +2492,7 @@
priv = GET_PRIV (config);
for (p = roots; *p; p++) {
- validated_root = config_dir_validate_name (*p);
+ validated_root = tracker_path_evaluate_name (*p);
if (!validated_root) {
g_print ("Root '%s' is not valid to add to crawl directory list\n",
validated_root);
@@ -2544,7 +2520,7 @@
priv = GET_PRIV (config);
for (p = roots; *p; p++) {
- validated_root = config_dir_validate_name (*p);
+ validated_root = tracker_path_evaluate_name (*p);
if (!validated_root) {
g_print ("Root '%s' is not valid to add to no_watch directory list\n",
validated_root);
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 Fri Jun 27 10:14:32 2008
@@ -27,8 +27,10 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <limits.h>
#include <glib.h>
+#include <gio/gio.h>
#include <xdgmime/xdgmime.h>
@@ -536,3 +538,87 @@
return checked_roots;
}
+
+gchar *
+tracker_path_evaluate_name (const gchar *uri)
+{
+ gchar *final_path;
+ gchar **tokens;
+ gchar **token;
+ gchar *start;
+ gchar *end;
+ const gchar *env;
+ gchar *expanded;
+
+ if (!uri || uri[0] == '\0') {
+ return NULL;
+ }
+
+ /* First check the simple case of using tilder */
+ if (uri[0] == '~') {
+ const char *home = g_get_home_dir ();
+
+ if (!home || home[0] == '\0') {
+ return NULL;
+ }
+
+ return g_build_path (G_DIR_SEPARATOR_S,
+ home,
+ uri + 1,
+ NULL);
+ }
+
+ /* Second try to find any environment variables and expand
+ * them, like $HOME or ${FOO}
+ */
+ tokens = g_strsplit (uri, G_DIR_SEPARATOR_S, -1);
+
+ for (token = tokens; *token; token++) {
+ if (**token != '$') {
+ continue;
+ }
+
+ start = *token + 1;
+
+ if (*start == '{') {
+ start++;
+ end = start + (strlen (start)) - 1;
+ *end='\0';
+ }
+
+ env = g_getenv (start);
+ g_free (*token);
+
+ /* Don't do g_strdup (s?s1:s2) as that doesn't work
+ * with certain gcc 2.96 versions.
+ */
+ *token = env ? g_strdup (env) : g_strdup ("");
+ }
+
+ /* Third get the real path removing any "../" and other
+ * symbolic links to other places, returning only the REAL
+ * location.
+ */
+ if (tokens) {
+ expanded = g_strjoinv (G_DIR_SEPARATOR_S, tokens);
+ g_strfreev (tokens);
+ } else {
+ expanded = g_strdup (uri);
+ }
+
+ /* Only resolve relative paths if there is a directory
+ * separator in the path, otherwise it is just a name.
+ */
+ if (strchr (expanded, G_DIR_SEPARATOR)) {
+ GFile *file;
+
+ file = g_file_new_for_commandline_arg (expanded);
+ final_path = g_file_get_path (file);
+ g_object_unref (file);
+ g_free (expanded);
+ } else {
+ final_path = expanded;
+ }
+
+ return final_path;
+}
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 Fri Jun 27 10:14:32 2008
@@ -39,5 +39,6 @@
gchar * tracker_file_get_vfs_name (const gchar *uri);
void tracker_path_remove (const gchar *uri);
GSList * tracker_path_list_filter_duplicates (GSList *roots);
+gchar * tracker_path_evaluate_name (const gchar *uri);
#endif /* __LIBTRACKER_COMMON_FILE_UTILS_H__ */
Modified: branches/indexer-split/src/libtracker-common/tracker-module-config.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-module-config.c (original)
+++ branches/indexer-split/src/libtracker-common/tracker-module-config.c Fri Jun 27 10:14:32 2008
@@ -27,6 +27,7 @@
#include <gio/gio.h>
#include "tracker-module-config.h"
+#include "tracker-file-utils.h"
#include "tracker-type-utils.h"
#define GROUP_GENERAL "General"
@@ -124,7 +125,8 @@
gchar *
module_config_load_string (GKeyFile *key_file,
const gchar *group,
- const gchar *key)
+ const gchar *key,
+ gboolean expand_string_as_path)
{
GError *error = NULL;
gchar *str;
@@ -144,16 +146,28 @@
return NULL;
}
+ if (expand_string_as_path) {
+ gchar *real_path;
+
+ real_path = tracker_path_evaluate_name (str);
+ g_free (str);
+
+ return real_path;
+ }
+
return str;
}
GSList *
module_config_load_string_list (GKeyFile *key_file,
const gchar *group,
- const gchar *key)
+ const gchar *key,
+ gboolean expand_strings_as_paths)
{
GError *error = NULL;
+ GSList *list;
gchar **str;
+ gchar **p;
gsize size;
str = g_key_file_get_string_list (key_file, group, key, &size, &error);
@@ -171,7 +185,25 @@
return NULL;
}
- return tracker_string_list_to_gslist (str, size);
+ if (!expand_strings_as_paths) {
+ list = tracker_string_list_to_gslist (str, size);
+ } else {
+ list = NULL;
+
+ for (p = str; *p; p++) {
+ gchar *real_path;
+
+ real_path = tracker_path_evaluate_name (*p);
+ list = g_slist_prepend (list, real_path);
+ g_debug ("Got real path:'%s' for '%s'", real_path, *p);
+ }
+
+ list = g_slist_reverse (list);
+ }
+
+ g_strfreev (str);
+
+ return list;
}
static ModuleConfig *
@@ -203,7 +235,8 @@
mc->description =
module_config_load_string (key_file,
GROUP_GENERAL,
- "Description");
+ "Description",
+ FALSE);
mc->enabled =
module_config_load_boolean (key_file,
GROUP_GENERAL,
@@ -213,35 +246,42 @@
mc->monitor_directories =
module_config_load_string_list (key_file,
GROUP_MONITORS,
- "Directories");
+ "Directories",
+ TRUE);
mc->monitor_recurse_directories =
module_config_load_string_list (key_file,
GROUP_MONITORS,
- "RecurseDirectories");
+ "RecurseDirectories",
+ TRUE);
/* Ignored */
mc->ignored_directories =
module_config_load_string_list (key_file,
GROUP_IGNORED,
- "Directories");
+ "Directories",
+ TRUE);
mc->ignored_files =
module_config_load_string_list (key_file,
GROUP_IGNORED,
- "Files");
+ "Files",
+ FALSE);
/* Index */
mc->service =
module_config_load_string (key_file,
GROUP_INDEX,
- "Service");
+ "Service",
+ FALSE);
mc->mime_types =
module_config_load_string_list (key_file,
GROUP_INDEX,
- "MimeTypes");
+ "MimeTypes",
+ FALSE);
mc->files =
module_config_load_string_list (key_file,
GROUP_INDEX,
- "Files");
+ "Files",
+ FALSE);
/* FIXME: Specific options */
@@ -292,7 +332,7 @@
name = g_file_info_get_name (info);
- if (!g_str_has_suffix (name, ".xml")) {
+ if (!g_str_has_suffix (name, ".module")) {
g_object_unref (info);
continue;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]