static void
process_file_cb (GObject      *object,
                 GAsyncResult *result,
                 gpointer      user_data)
{
	ProcessApplicationData *data;
	GFileInfo *file_info;
	GError *error = NULL;
	GFile *file;

	data = user_data;
	file = G_FILE (object);
	file_info = g_file_query_info_finish (file, result, &error);

	if (error) {
		tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), file, error);
		process_application_data_free (data);
		g_error_free (error);
		return;
	}

	if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) {
		process_directory (data, file_info, &error);
	} else {
		data->key_file = get_desktop_key_file (file, &data->type, &error);
		if (!data->key_file) {
			gchar *uri;

			uri = g_file_get_uri (file);
			g_warning ("Couldn't properly parse desktop file '%s': '%s'",
			           uri,
			           error ? error->message : "unknown error");
			g_free (uri);
			g_clear_error (&error);

			error = g_error_new_literal (miner_applications_error_quark, 0, "File is not a key file");
		} else if (g_key_file_get_boolean (data->key_file, GROUP_DESKTOP_ENTRY, "Hidden", NULL)) {
			error = g_error_new_literal (miner_applications_error_quark, 0, "Desktop file is 'hidden', not gathering metadata for it");
		} else {
			process_desktop_file (data, file_info, &error);
		}
	}

	tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, error);
	process_application_data_free (data);

	if (error) {
		g_error_free (error);
	}

	if (file_info) {
		g_object_unref (file_info);
	}
}
Beispiel #2
0
int 
main(int argc, char ** args) 
{
	struct dirent * current_entry;	
	char * dirpath;

	if (argc < 2) 
	{
		dirpath = strdup(DEFAULT_DIR);
	} else {
		dirpath = strdup(args[1]);
	}

	// copy environment, if needed
/*	if (argc > 2)
	{
		int n = 0;
		for (; environ[n]; ++n);
	
		new_environment = malloc(sizeof(char**)*(n+argc-1));

		memcpy(new_environment, environ, sizeof(char**)*n);
		memcpy(new_environment + n, args + 2, sizeof(char**)*(argc-2));
		new_environment[n+argc-2] = NULL;
	} else
		new_environment = NULL;

*/
	char * homeDir = envVar("HOME");
	if (*dirpath == '~' && homeDir)
	{
		char * oldpath = dirpath;
		int n1 = strlen(homeDir), n2 = strlen(oldpath)-1;

		dirpath = malloc(sizeof(char)*(n1+n2+1));
		memset(dirpath, 0, n1+n2+1);

		strncat(dirpath, homeDir, n1);
		strncat(dirpath, oldpath + 1, n2);
		free(oldpath);
	}

	repair_path(&dirpath);
	dir = opendir(dirpath);

	if (!dir)
		die("could not open dir \"%s\"\n", args[1]);

	char filename[512];

	while((current_entry = readdir(dir))) 
	{
		if (is_desktop_file(current_entry))
		{
			int pid;
			if ((pid = fork()) == 0)
			{
				strcpy(filename, dirpath);
				strcpy(filename + strlen(filename), current_entry->d_name);
				process_desktop_file(filename);
				break;
			}
			printf("cpid: %d\n", pid);
		}
	}

	free(dirpath);
	closedir(dir);
}