tracker r2148 - in branches/indexer-split: . src/libtracker-common src/trackerd tests/libtracker-common
- From: ifrade svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2148 - in branches/indexer-split: . src/libtracker-common src/trackerd tests/libtracker-common
- Date: Mon, 25 Aug 2008 15:47:13 +0000 (UTC)
Author: ifrade
Date: Mon Aug 25 15:47:13 2008
New Revision: 2148
URL: http://svn.gnome.org/viewvc/tracker?rev=2148&view=rev
Log:
Fixed handling of URIs with multiple slashes together like /x//y
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/trackerd/tracker-db.c
branches/indexer-split/src/trackerd/tracker-files.c
branches/indexer-split/tests/libtracker-common/tracker-file-utils-test.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 Mon Aug 25 15:47:13 2008
@@ -280,7 +280,8 @@
return content_type;
}
-gchar *
+
+static gchar *
tracker_file_get_vfs_path (const gchar *uri)
{
gchar *p;
@@ -321,7 +322,7 @@
}
}
-gchar *
+static gchar *
tracker_file_get_vfs_name (const gchar *uri)
{
gchar *p, *res, *tmp, *result;
@@ -357,6 +358,47 @@
return g_strdup (" ");
}
+
+static gchar *
+normalize_uri (const gchar *uri) {
+
+ GFile *f;
+ gchar *normalized;
+
+ f = g_file_new_for_path (uri);
+ normalized = g_file_get_path (f);
+ g_object_unref (f);
+
+ return normalized;
+}
+
+void
+tracker_file_get_path_and_name (const gchar *uri,
+ gchar **path,
+ gchar **name)
+{
+
+ g_return_if_fail (uri);
+ g_return_if_fail (path);
+ g_return_if_fail (name);
+
+ if (uri[0] == G_DIR_SEPARATOR) {
+ gchar *checked_uri;
+
+ checked_uri = normalize_uri (uri);
+ *name = g_path_get_basename (checked_uri);
+ *path = g_path_get_dirname (checked_uri);
+
+ g_free (checked_uri);
+ } else {
+ *name = tracker_file_get_vfs_name (uri);
+ *path = tracker_file_get_vfs_path (uri);
+ }
+
+}
+
+
+
void
tracker_path_remove (const gchar *uri)
{
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 Mon Aug 25 15:47:13 2008
@@ -35,8 +35,9 @@
guint32 tracker_file_get_size (const gchar *uri);
gint32 tracker_file_get_mtime (const gchar *uri);
gchar * tracker_file_get_mime_type (const gchar *uri);
-gchar * tracker_file_get_vfs_path (const gchar *uri);
-gchar * tracker_file_get_vfs_name (const gchar *uri);
+void tracker_file_get_path_and_name (const gchar *uri,
+ gchar **path,
+ gchar **name);
void tracker_path_remove (const gchar *uri);
gboolean tracker_path_is_in_path (const gchar *path,
const gchar *in_path);
Modified: branches/indexer-split/src/trackerd/tracker-db.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db.c (original)
+++ branches/indexer-split/src/trackerd/tracker-db.c Mon Aug 25 15:47:13 2008
@@ -2535,8 +2535,8 @@
gchar *str_aux;
gint service_type_id;
gchar *str_service_type_id;
- gchar *path;
- gchar *name;
+ gchar *path = NULL;
+ gchar *name = NULL;
g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), 0);
g_return_val_if_fail (info, 0);
@@ -2547,14 +2547,8 @@
private = g_static_private_get (&private_key);
g_return_val_if_fail (private != NULL, 0);
- if (info->uri[0] == G_DIR_SEPARATOR) {
- name = g_path_get_basename (info->uri);
- path = g_path_get_dirname (info->uri);
- } else {
- name = tracker_file_get_vfs_name (info->uri);
- path = tracker_file_get_vfs_path (info->uri);
- }
-
+ tracker_file_get_path_and_name (info->uri, &path, &name);
+
/* Get a new unique ID for the service - use mutex to prevent race conditions */
result_set = tracker_db_exec_proc (iface, "GetNewID", NULL);
@@ -2708,6 +2702,7 @@
return result;
}
+
guint32
tracker_db_file_get_id (TrackerDBInterface *iface,
const gchar *uri)
@@ -2719,13 +2714,7 @@
g_return_val_if_fail (TRACKER_IS_DB_INTERFACE (iface), 0);
g_return_val_if_fail (uri != NULL, 0);
- if (uri[0] == G_DIR_SEPARATOR) {
- name = g_path_get_basename (uri);
- path = g_path_get_dirname (uri);
- } else {
- name = tracker_file_get_vfs_name (uri);
- path = tracker_file_get_vfs_path (uri);
- }
+ tracker_file_get_path_and_name (uri, &path, &name);
result_set = tracker_db_exec_proc (iface,
"GetServiceID",
Modified: branches/indexer-split/src/trackerd/tracker-files.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-files.c (original)
+++ branches/indexer-split/src/trackerd/tracker-files.c Mon Aug 25 15:47:13 2008
@@ -418,8 +418,8 @@
TrackerDBInterface *iface;
TrackerDBResultSet *result_set = NULL;
guint request_id;
- gchar *name;
- gchar *path;
+ gchar *name = NULL;
+ gchar *path = NULL;
gchar *max_length_str;
gchar *value = NULL;
GError *actual_error = NULL;
@@ -439,13 +439,7 @@
iface = tracker_db_manager_get_db_interface_by_service (TRACKER_DB_FOR_FILE_SERVICE);
- if (uri[0] == G_DIR_SEPARATOR) {
- name = g_path_get_basename (uri);
- path = g_path_get_dirname (uri);
- } else {
- name = tracker_file_get_vfs_name (uri);
- path = tracker_file_get_vfs_path (uri);
- }
+ tracker_file_get_path_and_name (uri, &path, &name);
max_length_str = tracker_gint_to_string (max_length);
@@ -656,8 +650,8 @@
TrackerDBInterface *iface;
TrackerDBResultSet *result_set;
guint request_id;
- gchar *path;
- gchar *name;
+ gchar *path = NULL;
+ gchar *name = NULL;
gint mtime;
GError *actual_error = NULL;
@@ -672,13 +666,7 @@
iface = tracker_db_manager_get_db_interface_by_service (TRACKER_DB_FOR_FILE_SERVICE);
- if (uri[0] == G_DIR_SEPARATOR) {
- name = g_path_get_basename (uri);
- path = g_path_get_dirname (uri);
- } else {
- name = tracker_file_get_vfs_name (uri);
- path = tracker_file_get_vfs_path (uri);
- }
+ tracker_file_get_path_and_name (uri, &path, &name);
result_set = tracker_db_exec_proc (iface,
"GetFileMTime",
Modified: branches/indexer-split/tests/libtracker-common/tracker-file-utils-test.c
==============================================================================
--- branches/indexer-split/tests/libtracker-common/tracker-file-utils-test.c (original)
+++ branches/indexer-split/tests/libtracker-common/tracker-file-utils-test.c Mon Aug 25 15:47:13 2008
@@ -68,9 +68,9 @@
result = tracker_path_list_filter_duplicates (input_as_list);
g_assert_cmpint (3, ==, g_slist_length (result));
- g_assert (string_in_list (result, "/home/"));
- g_assert (string_in_list (result, "/tmp/"));
- g_assert (string_in_list (result, "/usr/"));
+ g_assert (string_in_list (result, "/home"));
+ g_assert (string_in_list (result, "/tmp"));
+ g_assert (string_in_list (result, "/usr"));
g_slist_foreach (input_as_list, (GFunc) g_free, NULL);
}
@@ -78,7 +78,7 @@
static void
test_path_evaluate_name (void)
{
- gchar *result;
+ gchar *result, *expected;
const gchar *home = g_getenv ("HOME");
const gchar *pwd = g_getenv ("PWD");
@@ -100,38 +100,53 @@
tracker_test_helpers_cmpstr_equal (result, "/home/user/all/dir");
g_free (result);
- result = tracker_path_evaluate_name ("~/all/dir/");
- tracker_test_helpers_cmpstr_equal (result,
- g_build_path (G_DIR_SEPARATOR_S, home, "/all/dir/", NULL));
+
+ /*
+ * TODO: In valgrind this test shows a memory leak
+ */
+ result = tracker_path_evaluate_name ("~/all/dir/");
+ expected = g_build_path (G_DIR_SEPARATOR_S, home, "/all/dir/", NULL);
+ tracker_test_helpers_cmpstr_equal (result, expected);
+
g_free (result);
+ g_free (expected);
result = tracker_path_evaluate_name ("$HOME/all/dir/");
- tracker_test_helpers_cmpstr_equal (result,
- g_build_path (G_DIR_SEPARATOR_S, home, "/all/dir", NULL));
+ expected = g_build_path (G_DIR_SEPARATOR_S, home, "/all/dir", NULL);
+ tracker_test_helpers_cmpstr_equal (result, expected);
+
g_free (result);
+ g_free (expected);
result = tracker_path_evaluate_name ("${HOME}/all/dir/");
- tracker_test_helpers_cmpstr_equal (result,
- g_build_path (G_DIR_SEPARATOR_S, home, "/all/dir", NULL));
+ expected = g_build_path (G_DIR_SEPARATOR_S, home, "/all/dir", NULL);
+ tracker_test_helpers_cmpstr_equal (result, expected);
+
g_free (result);
+ g_free (expected);
result = tracker_path_evaluate_name ("./test/current/dir");
- tracker_test_helpers_cmpstr_equal (result,
- g_build_path (G_DIR_SEPARATOR_S, pwd, "/test/current/dir", NULL));
+ expected = g_build_path (G_DIR_SEPARATOR_S, pwd, "/test/current/dir", NULL);
+ tracker_test_helpers_cmpstr_equal (result, expected);
+
g_free (result);
+ g_free (expected);
result = tracker_path_evaluate_name ("$TEST_TRACKER_DIR/test/dir");
- tracker_test_helpers_cmpstr_equal (result,
- g_build_path (G_DIR_SEPARATOR_S, test, "/test/dir", NULL));
- g_free (result);
+ expected = g_build_path (G_DIR_SEPARATOR_S, test, "/test/dir", NULL);
+ tracker_test_helpers_cmpstr_equal (result, expected);
+ g_free (result);
+ g_free (expected);
result = tracker_path_evaluate_name ("../test/dir");
parent_dir = g_path_get_dirname (pwd);
- tracker_test_helpers_cmpstr_equal (result,
- g_build_path (G_DIR_SEPARATOR_S, parent_dir, "/test/dir", NULL));
+ expected = g_build_path (G_DIR_SEPARATOR_S, parent_dir, "/test/dir", NULL);
+ tracker_test_helpers_cmpstr_equal (result, expected);
+
g_free (result);
g_free (parent_dir);
+ g_free (expected);
result = tracker_path_evaluate_name ("");
g_assert (!result);
@@ -142,6 +157,7 @@
result = tracker_path_evaluate_name (tracker_test_helpers_get_nonutf8 ());
tracker_test_helpers_cmpstr_equal (result,
tracker_test_helpers_get_nonutf8 ());
+
g_unsetenv ("TEST_TRACKER_DIR");
}
@@ -159,7 +175,7 @@
result = tracker_file_get_mime_type (dir_name);
- g_assert (tracker_test_helpers_cmpstr_equal (result, "x-directory/normal"));
+ g_assert (tracker_test_helpers_cmpstr_equal (result, "inode/directory"));
/* Remove test directory */
g_file_delete (dir, NULL, NULL);
@@ -167,6 +183,55 @@
g_free (dir_name);
}
+static void
+test_file_get_path_and_name ()
+{
+
+ gchar *name = NULL;
+ gchar *path = NULL;
+
+ tracker_file_get_path_and_name ("/home/ivan/test/file.txt",
+ &path,
+ &name);
+
+ g_assert_cmpint (g_strcmp0 (name, "file.txt"), ==, 0);
+ g_assert_cmpint (g_strcmp0 (path, "/home/ivan/test"), ==, 0);
+
+ g_free (name);
+ g_free (path);
+ name = NULL;
+ path = NULL;
+
+ tracker_file_get_path_and_name ("/home/ivan//test/file.txt",
+ &path,
+ &name);
+
+ g_assert_cmpint (g_strcmp0 (name, "file.txt"), ==, 0);
+ g_assert_cmpint (g_strcmp0 (path, "/home/ivan/test"), ==, 0);
+
+ g_free (name);
+ g_free (path);
+ name = NULL;
+ path = NULL;
+/*
+ * TODO: Fix this case
+ *
+ tracker_file_get_path_and_name ("file:///home/ivan//test/file.txt",
+ &path,
+ &name);
+
+ g_assert_cmpint (g_strcmp0 (name, "file.txt"), ==, 0);
+ g_print ("%s\n", path);
+ g_assert_cmpint (g_strcmp0 (path, "file:///home/ivan/test"), ==, 0);
+
+ g_free (name);
+ g_free (path);
+ name = NULL;
+ path = NULL;
+*/
+
+}
+
int
main (int argc, char **argv)
{
@@ -185,6 +250,9 @@
g_test_add_func ("/tracker/libtracker-common/tracker-file-utils/file_get_mime_type",
test_file_get_mime_type);
+ g_test_add_func ("/libtracker_common/tracker-file-utils/file_get_path_and_name",
+ test_file_get_path_and_name);
+
result = g_test_run ();
return result;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]