int main (int argc, char *argv[]) { TrackerConfig *config; TrackerController *controller; GOptionContext *context; GMainLoop *loop; GError *error = NULL; gchar *log_filename; guint shutdown_timeout; g_type_init (); /* Set up locale */ setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Translators: this messagge will apper immediately after the * usage string - Usage: COMMAND <THIS_MESSAGE> */ context = g_option_context_new (_("- start the tracker writeback service")); g_option_context_add_main_entries (context, entries, NULL); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (version) { g_print ("\n" ABOUT "\n" LICENSE "\n"); return EXIT_SUCCESS; } /* Initialize logging */ config = tracker_config_new (); if (verbosity > -1) { tracker_config_set_verbosity (config, verbosity); } tracker_log_init (tracker_config_get_verbosity (config), &log_filename); g_print ("Starting log:\n File:'%s'\n", log_filename); g_free (log_filename); sanity_check_option_values (config); if (disable_shutdown) { shutdown_timeout = 0; } else { shutdown_timeout = QUIT_TIMEOUT; } controller = tracker_controller_new (shutdown_timeout, &error); if (error) { g_critical ("Error creating controller: %s", error->message); g_error_free (error); return EXIT_FAILURE; } g_message ("Main thread is: %p", g_thread_self ()); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); tracker_log_shutdown (); g_object_unref (controller); g_main_loop_unref (loop); g_object_unref (config); return EXIT_SUCCESS; }
int main (gint argc, gchar *argv[]) { TrackerConfig *config; TrackerMiner *miner_files; TrackerMinerFilesIndex *miner_files_index; GOptionContext *context; GError *error = NULL; gchar *log_filename = NULL; gboolean do_mtime_checking; gboolean do_crawling; gboolean force_mtime_checking = FALSE; gboolean store_available; g_type_init(); main_loop = NULL; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Set timezone info */ tzset (); /* Translators: this messagge will apper immediately after the * usage string - Usage: COMMAND <THIS_MESSAGE> */ context = g_option_context_new (_("- start the tracker indexer")); disable_options = g_array_new (FALSE, FALSE, sizeof (gint)); g_option_context_add_main_entries (context, entries, NULL); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error) { g_printerr ("%s\n", error->message); g_error_free (error); g_array_free (disable_options, TRUE); return EXIT_FAILURE; } if (version) { g_print ("\n" ABOUT "\n" LICENSE "\n"); g_array_free (disable_options, TRUE); return EXIT_SUCCESS; } if (eligible) { check_eligible (); g_array_free (disable_options, TRUE); return EXIT_SUCCESS; } initialize_signal_handler (); /* Initialize logging */ config = tracker_config_new (); if (verbosity > -1) { tracker_config_set_verbosity (config, verbosity); } if (initial_sleep > -1) { tracker_config_set_initial_sleep (config, initial_sleep); } tracker_log_init (tracker_config_get_verbosity (config), &log_filename); if (log_filename) { g_message ("Using log file:'%s'", log_filename); g_free (log_filename); } sanity_check_option_values (config); /* This makes sure we don't steal all the system's resources */ initialize_priority_and_scheduling (tracker_config_get_sched_idle (config), tracker_db_manager_get_first_index_done () == FALSE); main_loop = g_main_loop_new (NULL, FALSE); g_message ("Checking if we're running as a daemon:"); g_message (" %s %s", no_daemon ? "No" : "Yes", no_daemon ? "(forced by command line)" : ""); /* Create new TrackerMinerFiles object */ miner_files = tracker_miner_files_new (config, &error); if (!miner_files) { g_critical ("Couldn't create new Files miner: '%s'", error ? error->message : "unknown error"); g_object_unref (config); tracker_log_shutdown (); g_array_free (disable_options, TRUE); return EXIT_FAILURE; } tracker_writeback_init (TRACKER_MINER_FILES (miner_files), config, &error); if (error) { g_critical ("Couldn't create writeback handling: '%s'", error ? error->message : "unknown error"); g_object_unref (config); g_object_unref (miner_files); tracker_log_shutdown (); g_array_free (disable_options, TRUE); return EXIT_FAILURE; } /* Create new TrackerMinerFilesIndex object */ miner_files_index = tracker_miner_files_index_new (TRACKER_MINER_FILES (miner_files)); if (!miner_files_index) { g_object_unref (miner_files); tracker_writeback_shutdown (); g_object_unref (config); tracker_log_shutdown (); g_array_free (disable_options, TRUE); return EXIT_FAILURE; } /* Check if we should crawl and if we should force mtime * checking based on the config. */ do_crawling = should_crawl (config, &force_mtime_checking); /* Get the last shutdown state to see if we need to perform a * full mtime check against the db or not. * * Set to TRUE here in case we crash and miss file system * events. */ g_message ("Checking whether to force mtime checking during crawling (based on last clean shutdown):"); /* Override the shutdown state decision based on the config */ if (force_mtime_checking) { do_mtime_checking = TRUE; } else { do_mtime_checking = tracker_db_manager_get_need_mtime_check (); } g_message (" %s %s", do_mtime_checking ? "Yes" : "No", force_mtime_checking ? "(forced from config)" : ""); /* Set the need for an mtime check to TRUE so we check in the * event of a crash, this is changed back on shutdown if * everything appears to be fine. */ tracker_db_manager_set_need_mtime_check (TRUE); /* Configure files miner */ tracker_miner_fs_set_initial_crawling (TRACKER_MINER_FS (miner_files), do_crawling); tracker_miner_fs_set_mtime_checking (TRACKER_MINER_FS (miner_files), do_mtime_checking); g_signal_connect (miner_files, "finished", G_CALLBACK (miner_finished_cb), NULL); miners = g_slist_prepend (miners, miner_files); tracker_thumbnailer_init (); miner_handle_first (config, do_mtime_checking); /* Go, go, go! */ g_main_loop_run (main_loop); g_message ("Shutdown started"); store_available = store_is_available (); if (miners_timeout_id == 0 && !miner_needs_check (miner_files, store_available)) { tracker_db_manager_set_need_mtime_check (FALSE); } g_main_loop_unref (main_loop); g_object_unref (config); g_object_unref (miner_files_index); tracker_thumbnailer_shutdown (); g_slist_foreach (miners, (GFunc) finalize_miner, NULL); g_slist_free (miners); tracker_writeback_shutdown (); tracker_log_shutdown (); g_array_free (disable_options, TRUE); g_print ("\nOK\n\n"); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; TrackerExtract *extract; TrackerDecorator *decorator; TrackerExtractController *controller; gchar *log_filename = NULL; GMainLoop *my_main_loop; bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Translators: this message will appear immediately after the */ /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE> */ context = g_option_context_new (_("- Extract file meta data")); g_option_context_add_main_entries (context, entries, NULL); g_option_context_parse (context, &argc, &argv, &error); if (!filename && mime_type) { gchar *help; g_printerr ("%s\n\n", _("Filename and mime type must be provided together")); help = g_option_context_get_help (context, TRUE, NULL); g_option_context_free (context); g_printerr ("%s", help); g_free (help); return EXIT_FAILURE; } g_option_context_free (context); if (version) { g_print ("\n" ABOUT "\n" LICENSE "\n"); return EXIT_SUCCESS; } g_set_application_name ("tracker-extract"); setlocale (LC_ALL, ""); config = tracker_config_new (); /* Set conditions when we use stand alone settings */ if (filename) { return run_standalone (config); } /* Initialize subsystems */ initialize_directories (); /* Extractor command line arguments */ if (verbosity > -1) { tracker_config_set_verbosity (config, verbosity); } tracker_log_init (tracker_config_get_verbosity (config), &log_filename); if (log_filename != NULL) { g_message ("Using log file:'%s'", log_filename); g_free (log_filename); } sanity_check_option_values (config); /* This makes sure we don't steal all the system's resources */ initialize_priority_and_scheduling (tracker_config_get_sched_idle (config), tracker_db_manager_get_first_index_done () == FALSE); extract = tracker_extract_new (TRUE, force_module); if (!extract) { g_object_unref (config); tracker_log_shutdown (); return EXIT_FAILURE; } decorator = tracker_extract_decorator_new (extract, NULL, &error); if (error) { g_critical ("Could not start decorator: %s\n", error->message); g_object_unref (config); tracker_log_shutdown (); return EXIT_FAILURE; } #ifdef THREAD_ENABLE_TRACE g_debug ("Thread:%p (Main) --- Waiting for extract requests...", g_thread_self ()); #endif /* THREAD_ENABLE_TRACE */ tracker_locale_init (); controller = tracker_extract_controller_new (decorator); tracker_miner_start (TRACKER_MINER (decorator)); /* Main loop */ main_loop = g_main_loop_new (NULL, FALSE); initialize_signal_handler (); g_main_loop_run (main_loop); my_main_loop = main_loop; main_loop = NULL; g_main_loop_unref (my_main_loop); tracker_miner_stop (TRACKER_MINER (decorator)); /* Shutdown subsystems */ tracker_locale_shutdown (); g_object_unref (extract); g_object_unref (decorator); g_object_unref (controller); tracker_log_shutdown (); g_object_unref (config); return EXIT_SUCCESS; }
static void check_eligible (void) { TrackerConfig *config; GFile *file; GFileInfo *info; GError *error = NULL; gchar *path; guint log_handler_id; gboolean exists = TRUE; gboolean is_dir; gboolean print_dir_check; gboolean print_dir_check_with_content; gboolean print_file_check; gboolean print_monitor_check; gboolean would_index = TRUE; gboolean would_notice = TRUE; /* Set log handler for library messages */ log_handler_id = g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL, dummy_log_handler, NULL); g_log_set_default_handler (dummy_log_handler, NULL); /* Start check */ file = g_file_new_for_commandline_arg (eligible); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error) { if (error->code == G_IO_ERROR_NOT_FOUND) { exists = FALSE; } g_error_free (error); } if (info) { is_dir = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY; g_object_unref (info); } else { /* Assume not a dir */ is_dir = FALSE; } config = tracker_config_new (); path = g_file_get_path (file); if (exists) { if (is_dir) { print_dir_check = TRUE; print_dir_check_with_content = TRUE; print_file_check = FALSE; print_monitor_check = TRUE; } else { print_dir_check = FALSE; print_dir_check_with_content = FALSE; print_file_check = TRUE; print_monitor_check = TRUE; } } else { print_dir_check = TRUE; print_dir_check_with_content = FALSE; print_file_check = TRUE; print_monitor_check = TRUE; } g_print (exists ? _("Data object '%s' currently exists") : _("Data object '%s' currently does not exist"), path); g_print ("\n"); if (print_dir_check) { gboolean check; check = tracker_miner_files_check_directory (file, tracker_config_get_index_recursive_directories (config), tracker_config_get_index_single_directories (config), tracker_config_get_ignored_directory_paths (config), tracker_config_get_ignored_directory_patterns (config)); g_print (" %s\n", check ? _("Directory is eligible to be mined (based on rules)") : _("Directory is NOT eligible to be mined (based on rules)")); would_index &= check; } if (print_dir_check_with_content) { GList *children; gboolean check; children = get_dir_children_as_gfiles (path); check = tracker_miner_files_check_directory_contents (file, children, tracker_config_get_ignored_directories_with_content (config)); g_list_foreach (children, (GFunc) g_object_unref, NULL); g_list_free (children); g_print (" %s\n", check ? _("Directory is eligible to be mined (based on contents)") : _("Directory is NOT eligible to be mined (based on contents)")); would_index &= check; } if (print_monitor_check) { gboolean check = TRUE; check &= tracker_config_get_enable_monitors (config); if (check) { GSList *dirs_to_check, *l; gboolean is_covered_single; gboolean is_covered_recursive; is_covered_single = FALSE; dirs_to_check = tracker_config_get_index_single_directories (config); for (l = dirs_to_check; l && !is_covered_single; l = l->next) { GFile *dir; GFile *parent; parent = g_file_get_parent (file); dir = g_file_new_for_path (l->data); is_covered_single = g_file_equal (parent, dir) || g_file_equal (file, dir); g_object_unref (dir); g_object_unref (parent); } is_covered_recursive = FALSE; dirs_to_check = tracker_config_get_index_recursive_directories (config); for (l = dirs_to_check; l && !is_covered_recursive; l = l->next) { GFile *dir; dir = g_file_new_for_path (l->data); is_covered_recursive = g_file_has_prefix (file, dir) || g_file_equal (file, dir); g_object_unref (dir); } check &= is_covered_single || is_covered_recursive; } if (exists && is_dir) { g_print (" %s\n", check ? _("Directory is eligible to be monitored (based on config)") : _("Directory is NOT eligible to be monitored (based on config)")); } else if (exists && !is_dir) { g_print (" %s\n", check ? _("File is eligible to be monitored (based on config)") : _("File is NOT eligible to be monitored (based on config)")); } else { g_print (" %s\n", check ? _("File or Directory is eligible to be monitored (based on config)") : _("File or Directory is NOT eligible to be monitored (based on config)")); } would_notice &= check; } if (print_file_check) { gboolean check; check = tracker_miner_files_check_file (file, tracker_config_get_ignored_file_paths (config), tracker_config_get_ignored_file_patterns (config)); g_print (" %s\n", check ? _("File is eligible to be mined (based on rules)") : _("File is NOT eligible to be mined (based on rules)")); would_index &= check; } g_print ("\n" "%s: %s\n" "%s: %s\n" "\n", _("Would be indexed"), would_index ? _("Yes") : _("No"), _("Would be monitored"), would_notice ? _("Yes") : _("No")); if (log_handler_id != 0) { /* Unset log handler */ g_log_remove_handler (NULL, log_handler_id); } g_free (path); g_object_unref (config); g_object_unref (file); }