[tracker/libtracker-miner] Make tracker_miner_fs_[add|remove]_directory() use GFile.
- From: Carlos Garnacho <carlosg src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/libtracker-miner] Make tracker_miner_fs_[add|remove]_directory() use GFile.
- Date: Wed, 26 Aug 2009 11:49:13 +0000 (UTC)
commit c02143b075e54135fd0b461f8a87c22053861427
Author: Carlos Garnacho <carlos lanedo com>
Date: Wed Aug 26 12:51:28 2009 +0200
Make tracker_miner_fs_[add|remove]_directory() use GFile.
src/libtracker-miner/test/tracker-main.c | 66 ++++++++++++++----------
src/libtracker-miner/tracker-miner-fs.c | 76 +++++++++++++++++-----------
src/libtracker-miner/tracker-miner-fs.h | 4 +-
src/tracker-miner-fs/tracker-miner-files.c | 29 +++++++----
4 files changed, 107 insertions(+), 68 deletions(-)
---
diff --git a/src/libtracker-miner/test/tracker-main.c b/src/libtracker-miner/test/tracker-main.c
index 391003b..156cf11 100644
--- a/src/libtracker-miner/test/tracker-main.c
+++ b/src/libtracker-miner/test/tracker-main.c
@@ -164,6 +164,18 @@ monitor_directory_cb (TrackerMinerFS *fs,
return TRUE;
}
+static void
+add_directory_path (TrackerMinerFS *fs,
+ const gchar *path,
+ gboolean recurse)
+{
+ GFile *file;
+
+ file = g_file_new_for_path (path);
+ tracker_miner_fs_add_directory (fs, file, recurse);
+ g_object_unref (file);
+}
+
int
main (int argc, char *argv[])
{
@@ -193,33 +205,33 @@ main (int argc, char *argv[])
G_CALLBACK (monitor_directory_cb),
NULL);
- tracker_miner_fs_add_directory (TRACKER_MINER_FS (miner),
- g_get_home_dir (),
- FALSE);
- tracker_miner_fs_add_directory (TRACKER_MINER_FS (miner),
- g_get_tmp_dir (),
- TRUE);
- tracker_miner_fs_add_directory (TRACKER_MINER_FS (miner),
- g_get_current_dir (),
- TRUE);
- tracker_miner_fs_add_directory (TRACKER_MINER_FS (miner),
- g_get_user_special_dir (G_USER_DIRECTORY_PICTURES),
- TRUE);
- tracker_miner_fs_add_directory (TRACKER_MINER_FS (miner),
- g_get_user_special_dir (G_USER_DIRECTORY_MUSIC),
- TRUE);
- tracker_miner_fs_add_directory (TRACKER_MINER_FS (miner),
- g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS),
- TRUE);
- tracker_miner_fs_add_directory (TRACKER_MINER_FS (miner),
- g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD),
- FALSE);
- tracker_miner_fs_add_directory (TRACKER_MINER_FS (miner),
- g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
- TRUE);
- tracker_miner_fs_add_directory (TRACKER_MINER_FS (miner),
- g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP),
- TRUE);
+ add_directory_path (TRACKER_MINER_FS (miner),
+ g_get_home_dir (),
+ FALSE);
+ add_directory_path (TRACKER_MINER_FS (miner),
+ g_get_tmp_dir (),
+ TRUE);
+ add_directory_path (TRACKER_MINER_FS (miner),
+ g_get_current_dir (),
+ TRUE);
+ add_directory_path (TRACKER_MINER_FS (miner),
+ g_get_user_special_dir (G_USER_DIRECTORY_PICTURES),
+ TRUE);
+ add_directory_path (TRACKER_MINER_FS (miner),
+ g_get_user_special_dir (G_USER_DIRECTORY_MUSIC),
+ TRUE);
+ add_directory_path (TRACKER_MINER_FS (miner),
+ g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS),
+ TRUE);
+ add_directory_path (TRACKER_MINER_FS (miner),
+ g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD),
+ FALSE);
+ add_directory_path (TRACKER_MINER_FS (miner),
+ g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
+ TRUE);
+ add_directory_path (TRACKER_MINER_FS (miner),
+ g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP),
+ TRUE);
g_signal_connect (miner, "terminated",
G_CALLBACK (miner_terminated_cb),
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 16dd6fb..d04e79c 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -35,7 +35,7 @@ typedef struct {
} ItemMovedData;
typedef struct {
- gchar *path;
+ GFile *file;
gboolean recurse;
} DirectoryData;
@@ -99,7 +99,7 @@ static void fs_finalize (GObject *object);
static gboolean fs_defaults (TrackerMinerFS *fs,
GFile *file);
static void miner_started (TrackerMiner *miner);
-static DirectoryData *directory_data_new (const gchar *path,
+static DirectoryData *directory_data_new (GFile *file,
gboolean recurse);
static void directory_data_free (DirectoryData *dd);
static ItemMovedData *item_moved_data_new (GFile *file,
@@ -373,14 +373,14 @@ miner_started (TrackerMiner *miner)
}
static DirectoryData *
-directory_data_new (const gchar *path,
- gboolean recurse)
+directory_data_new (GFile *file,
+ gboolean recurse)
{
DirectoryData *dd;
dd = g_slice_new (DirectoryData);
- dd->path = g_strdup (path);
+ dd->file = g_object_ref (file);
dd->recurse = recurse;
return dd;
@@ -393,7 +393,7 @@ directory_data_free (DirectoryData *dd)
return;
}
- g_free (dd->path);
+ g_object_unref (dd->file);
g_slice_free (DirectoryData, dd);
}
@@ -880,7 +880,7 @@ monitor_item_created_cb (TrackerMonitor *monitor,
}
/* Add to the list */
- tracker_miner_fs_add_directory (fs, path, TRUE);
+ tracker_miner_fs_add_directory (fs, file, TRUE);
}
g_queue_push_tail (fs->private->items_created,
@@ -1150,6 +1150,7 @@ static gboolean
crawl_directories_cb (gpointer user_data)
{
TrackerMinerFS *fs = user_data;
+ gchar *path;
if (fs->private->current_directory) {
g_critical ("One directory is already being processed, bailing out");
@@ -1171,15 +1172,18 @@ crawl_directories_cb (gpointer user_data)
fs->private->directories = g_list_remove (fs->private->directories,
fs->private->current_directory);
+ path = g_file_get_path (miner->private->current_directory->file);
+
g_debug ("Processing %s path '%s'\n",
fs->private->current_directory->recurse ? "recursive" : "single",
- fs->private->current_directory->path);
+ path);
- if (tracker_crawler_start (fs->private->crawler,
- fs->private->current_directory->path,
+ if (tracker_crawler_start (fs->private->crawler, path,
fs->private->current_directory->recurse)) {
/* Crawler when restart the idle function when done */
- fs->private->crawl_directories_id = 0;
+ fs->private->process_dirs_id = 0;
+ g_free (path);
+
return FALSE;
}
@@ -1187,6 +1191,8 @@ crawl_directories_cb (gpointer user_data)
directory_data_free (fs->private->current_directory);
fs->private->current_directory = NULL;
+ g_free (path);
+
return TRUE;
}
@@ -1247,44 +1253,56 @@ crawl_directories_stop (TrackerMinerFS *fs)
void
tracker_miner_fs_add_directory (TrackerMinerFS *fs,
- const gchar *path,
+ GFile *file,
gboolean recurse)
{
g_return_if_fail (TRACKER_IS_MINER_FS (fs));
- g_return_if_fail (path != NULL);
+ g_return_if_fail (G_IS_FILE (file));
fs->private->directories =
g_list_append (fs->private->directories,
- directory_data_new (path, recurse));
+ directory_data_new (file, recurse));
crawl_directories_start (fs);
}
gboolean
tracker_miner_fs_remove_directory (TrackerMinerFS *fs,
- const gchar *path)
+ GFile *file)
{
gboolean return_val = FALSE;
- GList *l;
+ GList *dirs;
g_return_val_if_fail (TRACKER_IS_MINER_FS (fs), FALSE);
- g_return_val_if_fail (path != NULL, FALSE);
+ g_return_val_if_fail (G_IS_FILE (file), FALSE);
- if (fs->private->current_directory &&
- strcmp (fs->private->current_directory->path, path) == 0) {
- /* Dir is being processed currently, cancel crawler */
- tracker_crawler_stop (fs->private->crawler);
- return_val = TRUE;
+ if (fs->private->current_directory) {
+ GFile *current_file;
+
+ current_file = fs->private->current_directory->file;
+
+ if (g_file_equal (file, current_file) ||
+ g_file_has_prefix (file, current_file)) {
+ /* Dir is being processed currently, cancel crawler */
+ tracker_crawler_stop (fs->private->crawler);
+ return_val = TRUE;
+ }
}
- l = g_list_find_custom (fs->private->directories, path,
- (GCompareFunc) g_strcmp0);
+ dirs = fs->private->directories;
- if (l) {
- directory_data_free (l->data);
- fs->private->directories =
- g_list_delete_link (fs->private->directories, l);
- return_val = TRUE;
+ while (dirs) {
+ DirectoryData *data = dirs->data;
+ GList *link = dirs;
+
+ dirs = dirs->next;
+
+ if (g_file_equal (file, data->file) ||
+ g_file_has_prefix (file, data->file)) {
+ directory_data_free (data);
+ fs->private->directories = g_list_delete_link (fs->private->directories, link);
+ return_val = TRUE;
+ }
}
return return_val;
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 854b20c..fc24fce 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -64,10 +64,10 @@ struct TrackerMinerFSClass {
GType tracker_miner_fs_get_type (void) G_GNUC_CONST;
void tracker_miner_fs_add_directory (TrackerMinerFS *fs,
- const gchar *path,
+ GFile *file,
gboolean recurse);
gboolean tracker_miner_fs_remove_directory (TrackerMinerFS *fs,
- const gchar *path);
+ GFile *file);
G_END_DECLS
diff --git a/src/tracker-miner-fs/tracker-miner-files.c b/src/tracker-miner-fs/tracker-miner-files.c
index 460c51c..65ee494 100644
--- a/src/tracker-miner-fs/tracker-miner-files.c
+++ b/src/tracker-miner-fs/tracker-miner-files.c
@@ -200,14 +200,24 @@ miner_files_constructed (GObject *object)
dirs = tracker_config_get_index_single_directories (priv->config);
while (dirs) {
- tracker_miner_fs_add_directory (fs, dirs->data, FALSE);
+ GFile *file;
+
+ file = g_file_new_for_path (dirs->data);
+ tracker_miner_fs_add_directory (fs, file, FALSE);
+ g_object_unref (file);
+
dirs = dirs->next;
}
dirs = tracker_config_get_index_recursive_directories (priv->config);
while (dirs) {
- tracker_miner_fs_add_directory (fs, dirs->data, TRUE);
+ GFile *file;
+
+ file = g_file_new_for_path (dirs->data);
+ tracker_miner_fs_add_directory (fs, file, TRUE);
+ g_object_unref (file);
+
dirs = dirs->next;
}
@@ -232,9 +242,13 @@ mount_point_added_cb (TrackerStorage *storage,
index_removable_devices = tracker_config_get_index_removable_devices (priv->config);
if (index_removable_devices) {
- tracker_miner_fs_add_directory (TRACKER_MINER_FS (user_data),
- mount_point,
+ GFile *file;
+
+ file = g_file_new_for_path (mount_point);
+ tracker_miner_fs_add_directory (TRACKER_MINER_FS (user_data),
+ file,
TRUE);
+ g_object_unref (file);
}
}
@@ -266,14 +280,9 @@ mount_pre_unmount_cb (GVolumeMonitor *volume_monitor,
TrackerMinerFiles *mf)
{
GFile *mount_root;
- gchar *path;
mount_root = g_mount_get_root (mount);
- path = g_file_get_path (mount_root);
-
- tracker_miner_fs_remove_directory (TRACKER_MINER_FS (mf), path);
-
- g_free (path);
+ tracker_miner_fs_remove_directory (TRACKER_MINER_FS (mf), mount_root);
g_object_unref (mount_root);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]