tracker-0.16.2/examples/libtracker-miner/tracker-main.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found tracker-main.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * Copyright (C) 2009, Nokia <ivan.frade@nokia.com>
  3  *
  4  * This library is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) any later version.
  8  *
  9  * This library is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU General Public
 15  * License along with this library; if not, write to the
 16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17  * Boston, MA  02110-1301, USA.
 18  */
 19 
 20 #include "config.h"
 21 
 22 #include <string.h>
 23 #include <stdlib.h>
 24 
 25 #include <glib.h>
 26 
 27 #include <libtracker-common/tracker-utils.h>
 28 
 29 #include "tracker-miner-test.h"
 30 
 31 static void
 32 miner_finished_cb (TrackerMiner *miner,
 33                    gdouble       seconds_elapsed,
 34                    guint         total_directories_found,
 35                    guint         total_directories_ignored,
 36                    guint         total_files_found,
 37                    guint         total_files_ignored,
 38                    gpointer      user_data)
 39 {
 40 	GMainLoop *main_loop = user_data;
 41 
 42 	g_message ("Finished mining in seconds:%f, total directories:%d, total files:%d",
 43 	           seconds_elapsed,
 44 	           total_directories_found + total_directories_ignored,
 45 	           total_files_found + total_files_ignored);
 46 
 47 	g_main_loop_quit (main_loop);
 48 }
 49 
 50 static gboolean
 51 miner_start_cb (gpointer user_data)
 52 {
 53 	TrackerMiner *miner = user_data;
 54 
 55 	g_message ("Starting miner");
 56 	tracker_miner_start (miner);
 57 
 58 	return FALSE;
 59 }
 60 
 61 static gboolean
 62 check_directory_cb (TrackerMinerFS *fs,
 63                     GFile          *file,
 64                     gpointer        user_data)
 65 {
 66 	gchar *path;
 67 	gchar *basename;
 68 	gboolean should_process;
 69 
 70 	should_process = FALSE;
 71 	basename = NULL;
 72 	path = g_file_get_path (file);
 73 
 74 	if (tracker_is_empty_string (path)) {
 75 		goto done;
 76 	}
 77 
 78 	if (!g_utf8_validate (path, -1, NULL)) {
 79 		g_message ("Ignoring path:'%s', not valid UTF-8", path);
 80 		goto done;
 81 	}
 82 
 83 	/* Most common things to ignore */
 84 	if (strcmp (path, "/dev") == 0 ||
 85 	    strcmp (path, "/lib") == 0 ||
 86 	    strcmp (path, "/proc") == 0 ||
 87 	    strcmp (path, "/sys") == 0) {
 88 		goto done;
 89 	}
 90 
 91 	if (g_str_has_prefix (path, g_get_tmp_dir ())) {
 92 		goto done;
 93 	}
 94 
 95 	/* Check ignored directories in config */
 96 	basename = g_file_get_basename (file);
 97 
 98 	if (!basename) {
 99 		goto done;
100 	}
101 
102 	/* If directory begins with ".", check it isn't one of
103 	 * the top level directories to watch/crawl if it
104 	 * isn't we ignore it. If it is, we don't.
105 	 */
106 	if (basename[0] == '.') {
107 		goto done;
108 	}
109 
110 	/* Check module directory ignore patterns */
111 	should_process = TRUE;
112 
113  done:
114 	g_free (path);
115 	g_free (basename);
116 
117 	return should_process;
118 }
119 
120 static gboolean
121 check_file_cb (TrackerMinerFS *fs,
122                GFile          *file,
123                gpointer                user_data)
124 {
125 	gchar *path;
126 	gchar *basename;
127 	gboolean should_process;
128 
129 	should_process = FALSE;
130 	basename = NULL;
131 	path = g_file_get_path (file);
132 
133 	if (tracker_is_empty_string (path)) {
134 		goto done;
135 	}
136 
137 	if (!g_utf8_validate (path, -1, NULL)) {
138 		g_message ("Ignoring path:'%s', not valid UTF-8", path);
139 		goto done;
140 	}
141 
142 	/* Check basename against pattern matches */
143 	basename = g_file_get_basename (file);
144 
145 	if (!basename || basename[0] == '.') {
146 		goto done;
147 	}
148 
149 	should_process = TRUE;
150 
151  done:
152 	g_free (path);
153 	g_free (basename);
154 
155 	return should_process;
156 }
157 
158 static void
159 process_file_cb (TrackerMinerFS *fs,
160                  GFile          *file,
161                  gpointer        user_data)
162 {
163 	gchar *path;
164 
165 	path = g_file_get_path (file);
166 	g_print ("** PROCESSING FILE:'%s'\n", path);
167 	g_free (path);
168 }
169 
170 static gboolean
171 monitor_directory_cb (TrackerMinerFS *fs,
172                       GFile          *file,
173                       gpointer        user_data)
174 {
175 	return TRUE;
176 }
177 
178 static void
179 add_directory_path (TrackerMinerFS *fs,
180                     const gchar    *path,
181                     gboolean        recurse)
182 {
183 	GFile *file;
184 
185 	file = g_file_new_for_path (path);
186 	tracker_miner_fs_directory_add (fs, file, recurse);
187 	g_object_unref (file);
188 }
189 
190 int
191 main (int argc, char *argv[])
192 {
193 	TrackerMiner *miner;
194 	GMainLoop *main_loop;
195 
196 	main_loop = g_main_loop_new (NULL, FALSE);
197 
198 	miner = tracker_miner_test_new ("test");
199 
200 	g_signal_connect (TRACKER_MINER_FS (miner), "check-file",
201 	                  G_CALLBACK (check_file_cb),
202 	                  NULL);
203 	g_signal_connect (TRACKER_MINER_FS (miner), "check-directory",
204 	                  G_CALLBACK (check_directory_cb),
205 	                  NULL);
206 	g_signal_connect (TRACKER_MINER_FS (miner), "process-file",
207 	                  G_CALLBACK (process_file_cb),
208 	                  NULL);
209 	g_signal_connect (TRACKER_MINER_FS (miner), "monitor-directory",
210 	                  G_CALLBACK (monitor_directory_cb),
211 	                  NULL);
212 
213 	add_directory_path (TRACKER_MINER_FS (miner),
214 	                    g_get_home_dir (),
215 	                    FALSE);
216 	add_directory_path (TRACKER_MINER_FS (miner),
217 	                    g_get_tmp_dir (),
218 	                    TRUE);
219 	add_directory_path (TRACKER_MINER_FS (miner),
220 	                    g_get_user_special_dir (G_USER_DIRECTORY_PICTURES),
221 	                    TRUE);
222 	add_directory_path (TRACKER_MINER_FS (miner),
223 	                    g_get_user_special_dir (G_USER_DIRECTORY_MUSIC),
224 	                    TRUE);
225 	add_directory_path (TRACKER_MINER_FS (miner),
226 	                    g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS),
227 	                    TRUE);
228 	add_directory_path (TRACKER_MINER_FS (miner),
229 	                    g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD),
230 	                    FALSE);
231 	add_directory_path (TRACKER_MINER_FS (miner),
232 	                    g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
233 	                    TRUE);
234 	add_directory_path (TRACKER_MINER_FS (miner),
235 	                    g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP),
236 	                    TRUE);
237 
238 	g_signal_connect (miner, "finished",
239 	                  G_CALLBACK (miner_finished_cb),
240 	                  main_loop);
241 	g_timeout_add_seconds (1, miner_start_cb, miner);
242 
243 	g_main_loop_run (main_loop);
244 
245 	return EXIT_SUCCESS;
246 }