Example #1
0
static xmmsv_t *
scan_path (const gchar *path, xmms_path_predicate predicate)
{
	const gchar *filename;
	xmmsv_t *list;
	GDir *dir;

	g_debug ("Scanning path: %s", path);

	list = xmmsv_new_list ();

	if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) {
		predicate (path, list);
		return list;
	}

	dir = g_dir_open (path, 0, NULL);
	if (dir == NULL) {
		g_print ("Could not open directory: %s\n", path);
		exit (EXIT_FAILURE);
	}

	while ((filename = g_dir_read_name (dir)) != NULL) {
		gchar *filepath;

		filepath = g_build_filename (path, filename, NULL);

		g_debug ("Found file: %s", filepath);
		predicate (filepath, list);

		g_free (filepath);
	}

	g_dir_close (dir);

	return list;
}
static GList *
category_list_get_from_dir_list (GSList *dir_list)
{
	GList *categories = NULL;
	GSList *dir_iterator;

	g_return_val_if_fail (dir_list != NULL, NULL);

	for (dir_iterator = dir_list; dir_iterator != NULL; dir_iterator = dir_iterator->next) {
		gchar *dir_name = dir_iterator->data;
		GDir *dir;
		char const *d_name;

		dir = g_dir_open (dir_name, 0, NULL);
		if (dir == NULL)
			continue;

		while ((d_name = g_dir_read_name (dir)) != NULL) {
			gchar *full_entry_name;

			full_entry_name = g_build_filename (dir_name, d_name, NULL);
			if (d_name[0] != '.' && g_file_test (full_entry_name, G_FILE_TEST_IS_DIR)) {
				FormatTemplateCategory *category;

				category = gnumeric_xml_read_format_template_category (full_entry_name);
				if (category != NULL) {
					categories = g_list_prepend (categories, category);
				}
			}
			g_free (full_entry_name);
		}

		g_dir_close (dir);
	}

	return categories;
}
Example #3
0
static gchar *
load_cert_from_dir (const gchar *dir_name,
                    GError **error)
{
  gchar *ret = NULL;
  GDir *dir;
  const gchar *name;
  GPtrArray *p;

  p = g_ptr_array_new ();

  dir = g_dir_open (dir_name, 0, error);
  if (dir == NULL)
    goto out;

  while ((name = g_dir_read_name (dir)) != NULL)
    {
      if (!g_str_has_suffix (name, ".cert"))
        continue;
      g_ptr_array_add (p, g_strdup_printf ("%s/%s", dir_name, name));
    }

  g_ptr_array_sort (p, (GCompareFunc)ptr_strcmp);

  if (p->len > 0)
    {
      ret = p->pdata[p->len - 1];
      p->pdata[p->len - 1] = NULL;
    }

out:
  if (dir != NULL)
    g_dir_close (dir);
  g_ptr_array_foreach (p, (GFunc)g_free, NULL);
  g_ptr_array_free (p, TRUE);
  return ret;
}
Example #4
0
static void foreach_file(const gchar *song_dir_path, const GRegex *cRegex, GlyrQuery *query, GList **retv_list)
{
    if(song_dir_path != NULL) {
        GError *dir_error = NULL;
        GDir *song_dir = g_dir_open(song_dir_path, 0, &dir_error);
        if(song_dir != NULL) {
            const gchar *entry = NULL;
            while((entry = g_dir_read_name(song_dir)) != NULL) {
                if(regex_match_compiled(entry, cRegex) == TRUE) {

                    gsize size = 0;
                    gchar *absolute_path = g_strdup_printf("%s%c%s", song_dir_path, G_DIR_SEPARATOR, entry);

                    if(absolute_path != NULL) {
                        /* Read file */
                        gchar *file_path = g_filename_from_utf8(absolute_path, -1, NULL, NULL, NULL);
                        gchar *retv = get_file_contents(file_path, &size);
                        g_free(file_path);
                        g_free(absolute_path);

                        /* Add file to result list if not null */
                        file_to_cache(retv_list, query, retv, size);

                        /* Not requested more? */
                        if(g_list_length(*retv_list) >= (gsize) query->number) {
                            break;
                        }
                    }
                }
            }
            g_dir_close(song_dir);
        } else {
            glyr_message(-1, NULL, "Opening %s failed: %s\n", song_dir_path, dir_error->message);
            g_error_free(dir_error);
        }
    }
}
Example #5
0
static GList *
log_manager_get_all_files (EmpathyLogManager *manager,
			   const gchar       *dir)
{
	GDir        *gdir;
	GList       *files = NULL;
	const gchar *name;
	
	if (!dir) {
		dir = log_manager_get_basedir (manager);
	}

	gdir = g_dir_open (dir, 0, NULL);
	if (!gdir) {
		return NULL;
	}

	while ((name = g_dir_read_name (gdir)) != NULL) {
		gchar *filename;

		filename = g_build_filename (dir, name, NULL);
		if (g_str_has_suffix (filename, LOG_FILENAME_SUFFIX)) {
			files = g_list_prepend (files, filename);
			continue;
		}

		if (g_file_test (filename, G_FILE_TEST_IS_DIR)) {
			/* Recursively get all log files */
			files = g_list_concat (files, log_manager_get_all_files (manager, filename));
		}
		g_free (filename);
	}

	g_dir_close (gdir);

	return files;
}
Example #6
0
void restore_databases(struct configuration *conf, MYSQL *conn) {
	GError *error= NULL;
	GDir* dir= g_dir_open(directory, 0, &error);

	if (error) {
		g_critical("cannot open directory %s, %s\n", directory, error->message);
		errors++;
		return;
	}

	const gchar* filename= NULL;

	while((filename= g_dir_read_name(dir))) {
		if (!source_db || g_str_has_prefix(filename, g_strdup_printf("%s.", source_db))){
			if (g_strrstr(filename, "-schema.sql")) {
				add_schema(filename, conn);
			}
		}
	}

	g_dir_rewind(dir);

	while((filename= g_dir_read_name(dir))) {
		if (!source_db || g_str_has_prefix(filename, g_strdup_printf("%s.", source_db))){
			if (!g_strrstr(filename, "-schema.sql")
			 && !g_strrstr(filename, "-schema-view.sql")
			 && !g_strrstr(filename, "-schema-triggers.sql")
			 && !g_strrstr(filename, "-schema-post.sql")
			 && !g_strrstr(filename, "-schema-create.sql")
			 && g_strrstr(filename, ".sql")) {
				add_table(filename, conf);
			}
		}
	}

	g_dir_close(dir);
}
static int dt_imageio_load_modules_format(dt_imageio_t *iio)
{
  iio->plugins_format = NULL;
  GList *res = NULL;
  dt_imageio_module_format_t *module;
  char plugindir[PATH_MAX] = { 0 }, plugin_name[256];
  const gchar *d_name;
  dt_loc_get_plugindir(plugindir, sizeof(plugindir));
  g_strlcat(plugindir, "/plugins/imageio/format", sizeof(plugindir));
  GDir *dir = g_dir_open(plugindir, 0, NULL);
  if(!dir) return 1;
  const int name_offset = strlen(SHARED_MODULE_PREFIX),
            name_end = strlen(SHARED_MODULE_PREFIX) + strlen(SHARED_MODULE_SUFFIX);
  while((d_name = g_dir_read_name(dir)))
  {
    // get lib*.so
    if(!g_str_has_prefix(d_name, SHARED_MODULE_PREFIX)) continue;
    if(!g_str_has_suffix(d_name, SHARED_MODULE_SUFFIX)) continue;
    strncpy(plugin_name, d_name + name_offset, strlen(d_name) - name_end);
    plugin_name[strlen(d_name) - name_end] = '\0';
    module = (dt_imageio_module_format_t *)malloc(sizeof(dt_imageio_module_format_t));
    gchar *libname = g_module_build_path(plugindir, (const gchar *)plugin_name);
    if(dt_imageio_load_module_format(module, libname, plugin_name))
    {
      free(module);
      continue;
    }
    module->gui_data = NULL;
    module->gui_init(module);
    if(module->widget) g_object_ref(module->widget);
    g_free(libname);
    res = g_list_insert_sorted(res, module, dt_imageio_sort_modules_format);
  }
  g_dir_close(dir);
  iio->plugins_format = res;
  return 0;
}
Example #8
0
G_MODULE_EXPORT void
plugin_init (PlannerPlugin *plugin)
{
	PlannerPluginPriv *priv;
	GDir              *dir;
	gchar             *dirname, *full_filename;
	const gchar       *filename;

	priv = g_new0 (PlannerPluginPriv, 1);
	plugin->priv = priv;

	priv->scripts = g_hash_table_new (g_str_hash, g_str_equal);

	Py_Initialize ();

	/* Look in ~/.gnome2/planner/python/  and run the scripts that we find */
	dirname = g_build_filename (g_get_home_dir(), ".gnome2", "planner", "python", NULL);
	dir = g_dir_open (dirname, 0, NULL);
	if (dir == NULL) {
		g_free (dirname);
		return;
	}

	filename = g_dir_read_name (dir);
	while (filename != NULL) {
		if (g_str_has_suffix (filename, ".py")) {
			full_filename = g_build_filename (dirname, filename, NULL);
			python_plugin_execute (full_filename, plugin->main_window, priv->scripts);
			g_free (full_filename);
		}

		filename = g_dir_read_name (dir);
	}

	g_free (dirname);
	g_dir_close (dir);
}
Example #9
0
static void
hashfs_hash_dir (hashfs_backend_t *backend, gchar *path)
{
	GDir *dir;
	GError *error;
	const gchar *filename;
	gchar *fullpath;

	HASHFS_LOG("Searching directory: %s", path);

	error = NULL;
	dir = g_dir_open(path, 0, &error);

	if (error) {
		HASHFS_DEBUG("Failed to open directory (%s): %s", path, error->message);
		g_error_free(error);

		return;
	}

	while ((filename = g_dir_read_name(dir))) {
		if (!g_strcmp0(filename, ".") || !g_strcmp0(filename, ".."))
			continue;

		fullpath = g_build_filename(path, filename, NULL);

		if (g_file_test(fullpath, G_FILE_TEST_IS_REGULAR)) {
			hashfs_hash_file(backend, fullpath);
		} else if (g_file_test(fullpath, G_FILE_TEST_IS_DIR)) {
			hashfs_hash_dir(backend, fullpath);
		}

		g_free(fullpath);
	}

	g_dir_close(dir);
}
// Check new files in given directory, updates the entry. New files
// are prepended to the given list and a new list is returned as 
// return value. Calls recursively itself for subdirectories.
bool CNewFilesChecker::FindNewFiles(const gchar *dirpath, CDirEntry *entry)
{
	bool retval = true;
	CDirEntry *child;

	GDir *dir = g_dir_open(dirpath, 0, NULL);
	if (dir) {
		const gchar *filename = g_dir_read_name(dir);
		while (filename && retval) {
			gchar *filepath = g_build_filename(dirpath, filename, NULL);
			if (!entry->Lookup(filename, &child)) {
				// New item
				if (m_Recursive && g_file_test(filepath, G_FILE_TEST_IS_DIR)) {
					// Recursive call for new subdirectories
					CDirEntry *child = entry->AddDir(filename);
					retval = FindNewFiles(filepath, child);
				} else 
				if (g_file_test(filepath, G_FILE_TEST_IS_REGULAR)) {
					// Test regular files
					bool try_again = FALSE;
					retval = CheckNewFile(filepath, &try_again);
					if (!try_again)
						entry->AddFile(filename);
				}
			} else {
				if (m_Recursive && child && g_file_test(filepath, G_FILE_TEST_IS_DIR)) {
					// Recursive call for old subdirectories
					retval = FindNewFiles(filepath, child);
				}
			}
			g_free(filepath);
			filename = g_dir_read_name(dir);
		}
		g_dir_close(dir);
	}
	return retval;
}
Example #11
0
static void
install_scripts (const gchar *into_dir)
{
	GDir *dir;
	GError *err = NULL;
	gchar path[PATH_MAX];
	const gchar *f;
	gchar *s;

	s = strrchr (into_dir, G_DIR_SEPARATOR);
	if (!s)
		return;

	s++;

	g_snprintf (path, PATH_MAX, "%s/scripts/%s", SHAREDDIR, s);
	xmms_log_info ("Installing scripts from %s", path);
	dir = g_dir_open (path, 0, &err);
	if (!dir) {
		xmms_log_error ("Global script directory not found");
		return;
	}

	while ((f = g_dir_read_name (dir))) {
		gchar *source = g_strdup_printf ("%s/%s", path, f);
		gchar *dest = g_strdup_printf ("%s/%s", into_dir, f);
		if (!xmms_symlink_file (source, dest)) {
			g_free (source);
			g_free (dest);
			break;
		}
		g_free (source);
		g_free (dest);
	}

	g_dir_close (dir);
}
Example #12
0
void
CChoosebook::create_tree_model(gchar *dir,GtkTreeStore *model, GtkTreeIter *iter)
{
	GDir *dp;
	if (!(dp = g_dir_open(dir,0,NULL))) return;

	const gchar *item;
	gchar fullname[256], dirnamefile[256],*tmp1;

	while ((item = g_dir_read_name(dp)) != NULL)
	{
		strcpy(fullname, dir);
		if (fullname[strlen(fullname) - 1] != G_DIR_SEPARATOR) strcat(fullname,G_DIR_SEPARATOR_S);
		strcat(fullname, item);
		if (g_file_test(fullname,G_FILE_TEST_IS_DIR))
		{
			GtkTreeIter child_iter;
			gtk_tree_store_append (model, &child_iter,iter);
			sprintf(dirnamefile, "%s/dirname", fullname);
			if (g_file_test(dirnamefile, G_FILE_TEST_EXISTS)) {
				if (g_file_get_contents(dirnamefile, &tmp1, NULL, NULL))
					g_strstrip(tmp1);
				else
					tmp1 = NULL;
			} else {
				tmp1 = g_filename_to_utf8(item,-1,NULL,NULL,NULL);
			}
			gtk_tree_store_set (model, &child_iter,
				  0,Skin->choosebook.dir.p[0],1, tmp1,2,fullname,
				  -1);
			if (tmp1)
				g_free(tmp1);
			create_tree_model(fullname,model, &child_iter);
		}
	}
	g_dir_close(dp);
}
Example #13
0
static void update_recordings_list(Data* data) {
	GList *children, *iter;
	children = gtk_container_get_children(GTK_CONTAINER(data->recordings_list_box));
	for(iter = children; iter != NULL; iter = g_list_next(iter)) {
		gtk_widget_destroy(GTK_WIDGET(iter->data));
	}
	g_list_free(children);

	if (!g_file_test(data->recordings_dir_path, G_FILE_TEST_IS_DIR)) {
		g_mkdir_with_parents(data->recordings_dir_path, 0666);
	}
	GDir* dir = g_dir_open(data->recordings_dir_path, 0, NULL);
	data->index = 0;
	GtkWidget* inner_box;
	GtkWidget* play_button;

	for (const gchar* filename = g_dir_read_name(dir); filename != NULL; filename = g_dir_read_name(dir)) {
		// only display .mp3 files
		if (strcmp(strrchr(filename, '.'), ".mp3") != 0) {
			continue;
		}
		data->index++;
		inner_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
		play_button = gtk_button_new_from_icon_name("media-playback-start", GTK_ICON_SIZE_BUTTON);
		gtk_button_set_relief(GTK_BUTTON(play_button), GTK_RELIEF_NONE);
		char* full_filename = (char*) malloc((strlen(data->recordings_dir_path) + 1 + strlen(filename)) * sizeof(char));
		sprintf(full_filename, "%s/%s", data->recordings_dir_path, filename);
		g_object_set_data(G_OBJECT(play_button), "full_filename", full_filename);
		g_signal_connect(GTK_BUTTON(play_button), "clicked", G_CALLBACK(on_play_button_clicked), data);

		gtk_box_pack_start(GTK_BOX(inner_box), gtk_label_new(filename), TRUE, TRUE, 0);
		gtk_box_pack_start(GTK_BOX(inner_box), play_button, FALSE, FALSE, 0);
		gtk_container_add(GTK_CONTAINER(data->recordings_list_box), inner_box);
	}
	g_dir_close(dir);
	gtk_widget_show_all(data->recordings_list_box);
}
Example #14
0
/**
 * @internal Execute all programs or scripts in a directory. Used when starting
 * up and shutting down the daemon.
 *
 * @param[in] scriptdir Directory to search for executable programs/scripts.
 * started.
 * @param     arg1 value passed to executed scripts as argument 1. This makes
 * it possible to handle start and stop in one script
 */
static void
do_scriptdir (const gchar *scriptdir, const gchar *arg1)
{
	GError *err = NULL;
	GDir *dir;
	const gchar *f;
	gchar *argv[3] = {NULL, NULL, NULL};

	XMMS_DBG ("Running scripts in %s", scriptdir);
	if (!g_file_test (scriptdir, G_FILE_TEST_IS_DIR)) {
		g_mkdir_with_parents (scriptdir, 0755);
		install_scripts (scriptdir);
	}

	dir = g_dir_open (scriptdir, 0, &err);
	if (!dir) {
		xmms_log_error ("Could not open script dir '%s' error: %s", scriptdir, err->message);
		return;
	}

	argv[1] = g_strdup (arg1);
	while ((f = g_dir_read_name (dir))) {
		argv[0] = g_strdup_printf ("%s/%s", scriptdir, f);
		if (g_file_test (argv[0], G_FILE_TEST_IS_EXECUTABLE)) {
			if (!g_spawn_async (g_get_home_dir (), argv, NULL, 0,
			                    spawn_script_setup, NULL, NULL, &err)) {
				xmms_log_error ("Could not run script '%s', error: %s",
				                argv[0], err->message);
			}
		}
		g_free (argv[0]);
	}
	g_free (argv[1]);

	g_dir_close (dir);

}
Example #15
0
GSList *
tracker_process_get_pids (void)
{
    GError *error = NULL;
    GDir *dir;
    GSList *pids = NULL;
    const gchar *name;

    dir = g_dir_open ("/proc", 0, &error);
    if (error) {
        g_printerr ("%s: %s\n",
                    _("Could not open /proc"),
                    error ? error->message : _("No error given"));
        g_clear_error (&error);
        return NULL;
    }

    while ((name = g_dir_read_name (dir)) != NULL) {
        gchar c;
        gboolean is_pid = TRUE;

        for (c = *name; c && c != ':' && is_pid; c++) {
            is_pid &= g_ascii_isdigit (c);
        }

        if (!is_pid) {
            continue;
        }

        pids = g_slist_prepend (pids, g_strdup (name));
    }

    g_dir_close (dir);

    return g_slist_reverse (pids);
}
Example #16
0
/**
 * removes directory recursively. 
 */
void mud_dir_remove (const char * path) {
	GError * gerr = NULL;
	GDir * d = g_dir_open (path, 0, &gerr);
	const char * n = NULL;

	if (gerr) {
		fprintf (stderr, "%s\n", gerr->message);
		g_error_free (gerr);
	} else {
		struct stat buf;
		while ((n = g_dir_read_name (d))) {
			gchar * x = g_build_path (G_DIR_SEPARATOR_S, path, n, NULL);
			if (g_lstat (x, &buf)) {
				fprintf (stderr, "lstat failed on '%s'\n", x);
			} else {
				if (S_ISDIR (buf.st_mode)) mud_dir_remove (x);
				else if (g_remove (x)) fprintf (stderr, "unable to remove file '%s'\n", x);
			}
			g_free (x);
		}
		g_dir_close (d);
	}
	if (g_rmdir (path)) fprintf (stderr, "unable to remove directory '%s'\n", path);
}
Example #17
0
gchar* remmina_file_manager_get_groups(void)
{
	gchar dirname[MAX_PATH_LEN];
	gchar filename[MAX_PATH_LEN];
	GDir* dir;
	const gchar* name;
	RemminaFile* remminafile;
	RemminaStringArray* array;
	const gchar* group;
	gchar* groups;

	array = remmina_string_array_new();

	g_snprintf(dirname, MAX_PATH_LEN, "%s/.remmina", g_get_home_dir());
	dir = g_dir_open(dirname, 0, NULL);
	if (dir == NULL)
		return 0;
	while ((name = g_dir_read_name(dir)) != NULL)
	{
		if (!g_str_has_suffix(name, ".remmina"))
			continue;
		g_snprintf(filename, MAX_PATH_LEN, "%s/%s", dirname, name);
		remminafile = remmina_file_load(filename);
		group = remmina_file_get_string(remminafile, "group");
		if (group && remmina_string_array_find(array, group) < 0)
		{
			remmina_string_array_add(array, group);
		}
		remmina_file_free(remminafile);
	}
	g_dir_close(dir);
	remmina_string_array_sort(array);
	groups = remmina_string_array_to_string(array);
	remmina_string_array_free(array);
	return groups;
}
Example #18
0
static GList *
log_manager_get_chats (EmpathyLogManager *manager,
		       const gchar       *dir,
		       gboolean           is_chatroom)
{
	GDir        *gdir;
	GList       *hits = NULL;
	const gchar *name;

	gdir = g_dir_open (dir, 0, NULL);
	if (!gdir) {
		return NULL;
	}

	while ((name = g_dir_read_name (gdir)) != NULL) {
		EmpathyLogSearchHit *hit;
		gchar *filename;

		filename = g_build_filename (dir, name, NULL);
		if (strcmp (name, LOG_DIR_CHATROOMS) == 0) {
			hits = g_list_concat (hits, log_manager_get_chats (manager, filename, TRUE));
			g_free (filename);
			continue;
		}

		hit = g_slice_new0 (EmpathyLogSearchHit);
		hit->chat_id = g_strdup (name);
		hit->is_chatroom = is_chatroom;

		hits = g_list_prepend (hits, hit);
	}

	g_dir_close (gdir);

	return hits;
}
Example #19
0
static void swap_clean (void)
{
  const gchar  *swap_dir = gegl_swap_dir ();
  GDir         *dir;

  if (! swap_dir)
    return;

  dir = g_dir_open (gegl_swap_dir (), 0, NULL);

  if (dir != NULL)
    {
      GPatternSpec *pattern = g_pattern_spec_new ("*");
      const gchar  *name;

      while ((name = g_dir_read_name (dir)) != NULL)
        {
          if (g_pattern_match_string (pattern, name))
            {
              gint readpid = atoi (name);

              if (!pid_is_running (readpid))
                {
                  gchar *fname = g_build_filename (gegl_swap_dir (),
                                                   name,
                                                   NULL);
                  g_unlink (fname);
                  g_free (fname);
                }
            }
         }

      g_pattern_spec_free (pattern);
      g_dir_close (dir);
    }
}
Example #20
0
static int
dt_imageio_load_modules_storage (dt_imageio_t *iio)
{
    iio->plugins_storage = NULL;
    GList *res = NULL;
    dt_imageio_module_storage_t *module;
    char plugindir[1024], plugin_name[256];
    const gchar *d_name;
    dt_loc_get_plugindir(plugindir, 1024);
    g_strlcat(plugindir, "/plugins/imageio/storage", 1024);
    GDir *dir = g_dir_open(plugindir, 0, NULL);
    if(!dir) return 1;
    while((d_name = g_dir_read_name(dir)))
    {
        // get lib*.so
        if(strncmp(d_name, "lib", 3)) continue;
        if(strncmp(d_name + strlen(d_name) - 3, ".so", 3)) continue;
        strncpy(plugin_name, d_name+3, strlen(d_name)-6);
        plugin_name[strlen(d_name)-6] = '\0';
        module = (dt_imageio_module_storage_t *)malloc(sizeof(dt_imageio_module_storage_t));
        gchar *libname = g_module_build_path(plugindir, (const gchar *)plugin_name);
        if(dt_imageio_load_module_storage(module, libname, plugin_name))
        {
            free(module);
            continue;
        }
        module->gui_data = NULL;
        module->gui_init(module);
        if(module->widget) gtk_widget_ref(module->widget);
        g_free(libname);
        res = g_list_insert_sorted(res, module, dt_imageio_sort_modules_storage);
    }
    g_dir_close(dir);
    iio->plugins_storage = res;
    return 0;
}
Example #21
0
void
test_clear_dir (const gchar *path)
{
  GDir *dir;
  const gchar *name;
  gchar *filename;

  dir = g_dir_open (path, 0, NULL);
  if (dir == NULL)
    return;

  while ((name = g_dir_read_name (dir)) != NULL)
    {
      filename = g_build_filename (path, name, NULL);
      if (g_file_test (filename, G_FILE_TEST_IS_DIR))
        test_clear_dir (filename);

      g_remove (filename);
      g_free (filename);
    }

  g_remove (path);
  g_dir_close (dir);
}
Example #22
0
static void __for_each_file(const std::string& dirname, const std::string& suff,
                            const List& order_list, const List& disable_list, 
                            const std::function<void (const std::string&, bool)>& f)
{
	GDir *dir = g_dir_open(dirname.c_str(), 0, nullptr);	
    if (dir) {
		const gchar *filename;

        while ((filename = g_dir_read_name(dir))!=nullptr) {	
			const std::string fullfilename(dirname+G_DIR_SEPARATOR_S+filename);
			if (g_file_test(fullfilename.c_str(), G_FILE_TEST_IS_DIR))
				__for_each_file(fullfilename, suff, order_list, disable_list, f);
            else if (g_str_has_suffix(filename, suff.c_str()) &&
                     std::find(order_list.begin(), order_list.end(), 
                               fullfilename)==order_list.end()) { 
                const bool disable = std::find(disable_list.begin(), 
                                         disable_list.end(), 
                                         fullfilename)!=disable_list.end();
                f(fullfilename, disable);
			}
		}
		g_dir_close(dir);
	}
}
Example #23
0
static gboolean
ev_backends_manager_load (void)
{
	GDir        *dir;
	const gchar *dirent;
	GError      *error = NULL;

	dir = g_dir_open (backends_dir(), 0, &error);
	if (!dir) {
		g_warning ("%s", error->message);
		g_error_free (error);

		return FALSE;
	}

	while ((dirent = g_dir_read_name (dir))) {
		EvBackendInfo *info;
		gchar         *file;
		
		if (!g_str_has_suffix (dirent, EV_BACKENDS_EXTENSION))
			continue;

		file = g_build_filename (backends_dir(), dirent, NULL);
		info = ev_backends_manager_load_backend (file);
		g_free (file);

		if (!info)
			continue;
		
		ev_backends_list = g_list_prepend (ev_backends_list, info);
	}

	g_dir_close (dir);

	return ev_backends_list != NULL;
}
Example #24
0
File: util.c Project: robtimus/bbbm
GList *bbbm_util_listdir(const gchar *dir) {
    GList *files = NULL;
    GError *error = NULL;
    const gchar *entry;
    GDir *d;

    d = g_dir_open(dir, 0, &error);
    if (d == NULL) {
        g_critical("could not open dir '%s' for reading: %s", dir, error->message);
        g_error_free(error);
        return NULL;
    }
    while ((entry = g_dir_read_name(d)) != NULL) {
        gchar *file;

        file = g_strjoin("/", dir, entry, NULL);
        if (g_file_test(file, G_FILE_TEST_IS_REGULAR)) {
            files = g_list_append(files, bbbm_util_absolute_path(file));
        }
        g_free(file);
    }
    g_dir_close(d);
    return files;
}
/*
 * returned list contents must be freed
 */
static GList *
get_matching_filenames (gchar * path, gchar * filename)
{
  GList *res = NULL;
  GDir *topdir;
  const gchar *subdirname;
  gchar *tmp;

  topdir = g_dir_open (path, 0, NULL);
  if (G_UNLIKELY (topdir == NULL))
    return NULL;

  tmp = g_build_filename (path, filename, NULL);
  if (g_file_test (tmp, G_FILE_TEST_EXISTS))
    res = g_list_append (res, tmp);
  else
    g_free (tmp);

  while ((subdirname = g_dir_read_name (topdir))) {
    gchar *ltmp = g_build_filename (path, subdirname, NULL);

    if (g_file_test (ltmp, G_FILE_TEST_IS_DIR)) {
      gchar *tmp = g_build_filename (path, subdirname, filename, NULL);
      /* Test to see if we have a file named like that in that directory */
      if (g_file_test (tmp, G_FILE_TEST_EXISTS))
        res = g_list_append (res, tmp);
      else
        g_free (tmp);
    }
    g_free (ltmp);
  }

  g_dir_close (topdir);

  return res;
}
static GList *
get_categories (gchar * path)
{
  GList *res = NULL;
  GDir *topdir;
  const gchar *subdirname;

  topdir = g_dir_open (path, 0, NULL);
  if (G_UNLIKELY (topdir == NULL))
    return NULL;

  while ((subdirname = g_dir_read_name (topdir))) {
    gchar *ltmp = g_build_filename (path, subdirname, NULL);

    if (g_file_test (ltmp, G_FILE_TEST_IS_DIR)) {
      res = g_list_append (res, (gpointer) g_strdup (subdirname));
    }
    g_free (ltmp);
  }

  g_dir_close (topdir);

  return res;
}
Example #27
0
static void init_custom_filetypes(const gchar *path)
{
	return;
	GDir *dir;
	const gchar *filename;

	g_return_if_fail(path);

	dir = g_dir_open(path, 0, NULL);
	if (dir == NULL)
		return;

	foreach_dir(filename, dir)
	{
		const gchar prefix[] = "filetypes.";

		if (g_str_has_prefix(filename, prefix) &&
			g_str_has_suffix(filename + strlen(prefix), ".conf"))
		{
			add_custom_filetype(filename);
		}
	}
	g_dir_close(dir);
}
Example #28
0
static void
g_local_file_enumerator_finalize (GObject *object)
{
  GLocalFileEnumerator *local;

  local = G_LOCAL_FILE_ENUMERATOR (object);

  g_free (local->filename);
  g_file_attribute_matcher_unref (local->matcher);
  if (local->dir)
    {
#ifdef USE_GDIR
      g_dir_close (local->dir);
#else
      closedir (local->dir);
#endif      
      local->dir = NULL;
    }

  free_entries (local);
  
  if (G_OBJECT_CLASS (g_local_file_enumerator_parent_class)->finalize)
    (*G_OBJECT_CLASS (g_local_file_enumerator_parent_class)->finalize) (object);
}
void cairo_dock_preload_module_from_directory (gchar *cModuleDirPath, GHashTable *pModuleTable, GError **erreur)
{
	cd_message ("%s (%s)", __func__, cModuleDirPath);
	GError *tmp_erreur = NULL;
	GDir *dir = g_dir_open (cModuleDirPath, 0, &tmp_erreur);
	if (tmp_erreur != NULL)
	{
		g_propagate_error (erreur, tmp_erreur);
		return ;
	}

	const gchar *cFileName;
	gchar *cFilePath;
	CairoDockModule *pModule;
	do
	{
		cFileName = g_dir_read_name (dir);
		if (cFileName == NULL)
			break ;

		cFilePath = g_strdup_printf ("%s/%s", cModuleDirPath, cFileName);
		if (g_str_has_suffix (cFilePath, ".so"))
		{
			pModule = cairo_dock_load_module (cFilePath, pModuleTable, &tmp_erreur);
			if (tmp_erreur != NULL)
			{
				cd_warning ("Attention : %s", tmp_erreur->message);
				g_error_free (tmp_erreur);
				tmp_erreur = NULL;
			}
			g_free (cFilePath);
		}
	}
	while (1);
	g_dir_close (dir);
}
Example #30
0
static void
iterate_over_input(const gchar **knw,
		   ifile_iterator_t iter, void *data) {
  unsigned idx = 0;
  const gchar *inp;

  while ((inp = knw[idx++])) {
    GDir *dir = g_dir_open(inp, 0, NULL);
    const gchar *file;

    if (!dir)
      continue;

    /* Iterate over elements in the directory */
    while ((file = g_dir_read_name (dir)))
      if (g_str_has_suffix(file, ".dat")) {
	gchar *filename = g_build_filename(inp,file,NULL);
	iter(filename, data);
	g_free(filename);
      }

    g_dir_close(dir);
  }
}