static void delete_batch (GObject *source, GAsyncResult *res, gpointer user_data) { GFileEnumerator *enumerator = G_FILE_ENUMERATOR (source); DeleteData *data = user_data; GList *files, *f; GFile *child_file; DeleteData *child; GFileInfo *info; GError *error = NULL; files = g_file_enumerator_next_files_finish (enumerator, res, &error); g_debug ("GsdHousekeeping: purging %d children of %s", g_list_length (files), data->name); if (files) { for (f = files; f; f = f->next) { if (g_cancellable_is_cancelled (data->cancellable)) break; info = f->data; child_file = g_file_get_child (data->file, g_file_info_get_name (info)); child = delete_data_new (child_file, data->cancellable, data->old, data->dry_run, data->trash, data->depth + 1); delete_recursively_by_age (child); delete_data_unref (child); g_object_unref (child_file); } g_list_free_full (files, g_object_unref); if (!g_cancellable_is_cancelled (data->cancellable)) { g_file_enumerator_next_files_async (enumerator, 20, 0, data->cancellable, delete_batch, data); return; } } g_file_enumerator_close (enumerator, data->cancellable, NULL); g_object_unref (enumerator); if (data->depth > 0 && !g_cancellable_is_cancelled (data->cancellable)) { if ((data->trash && data->depth > 1) || should_purge_file (data->file, data->cancellable, data->old)) { g_debug ("GsdHousekeeping: purging %s\n", data->name); if (!data->dry_run) { g_file_delete (data->file, data->cancellable, NULL); } } } delete_data_unref (data); }
static void plugin_manager_next_files_ready (GObject *object, GAsyncResult *result, gpointer user_data) { GigglePluginManager *manager = user_data; GigglePluginManagerPriv *priv = GET_PRIV (manager); GFileEnumerator *children = G_FILE_ENUMERATOR (object); GError *error = NULL; GList *files, *l; files = g_file_enumerator_next_files_finish (children, result, &error); if (error) { g_warning ("%s: %s", G_STRFUNC, error->message); g_clear_error (&error); } for (l = files; l; l = g_list_delete_link (l, l)) { const char *name = g_file_info_get_name (l->data); char *filename; GigglePlugin *plugin; GFile *file; if (g_str_has_suffix (name, ".xml")) { file = g_file_get_child (priv->plugin_dir, name); filename = g_file_get_path (file); plugin = giggle_plugin_new_from_file (filename, &error); g_object_unref (file); g_free (filename); if (plugin) { giggle_plugin_set_manager (plugin, manager); priv->plugins = g_list_prepend (priv->plugins, plugin); g_signal_emit (manager, signals[PLUGIN_ADDED], 0, plugin); } else { g_warning ("%s: %s", G_STRFUNC, error->message); g_clear_error (&error); } } g_object_unref (l->data); } if (files) { g_file_enumerator_next_files_async (children, 16, G_PRIORITY_DEFAULT, priv->cancellable, plugin_manager_next_files_ready, user_data); } }
static VALUE fileenumerator_next_files_finish(VALUE self, VALUE result) { GError *error = NULL; GList *files = g_file_enumerator_next_files_finish(_SELF(self), RVAL2GASYNCRESULT(result), &error); if (error != NULL) rbgio_raise_error(error); return GLIST2ARY_FREE(files); }
static void enumerate_next_files_ready_cb (GObject *source, GAsyncResult *res, gpointer user_data) { GFileEnumerator *enumerator = G_FILE_ENUMERATOR (source); BijiNoteBook *self; GList *files, *l; GError *error = NULL; gchar *base_path; files = g_file_enumerator_next_files_finish (enumerator, res, &error); if (error != NULL) { load_location_error (g_file_enumerator_get_container (enumerator), error); return; } self = user_data; base_path = g_file_get_path (self->priv->location); // now load the notes for (l = files; l != NULL; l = l->next) { GFileInfo *info; const gchar *name; gchar *path; BijiNoteObj *note; info = l->data; name = g_file_info_get_name (info); if (!g_str_has_suffix (name, ".note")) continue; path = g_build_filename (base_path, name, NULL); note = biji_note_get_new_from_file (path); _biji_note_book_add_one_note (self, note); g_free (path); } g_free (base_path); g_list_free_full (files, g_object_unref); }
static void file_info_async_ready (GObject *source, GAsyncResult *res, gpointer user_data) { BgPicturesSource *bg_source; GList *files, *l; GError *err = NULL; GFile *parent; files = g_file_enumerator_next_files_finish (G_FILE_ENUMERATOR (source), res, &err); if (err) { if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Could not get pictures file information: %s", err->message); g_error_free (err); g_list_foreach (files, (GFunc) g_object_unref, NULL); g_list_free (files); return; } bg_source = BG_PICTURES_SOURCE (user_data); parent = g_file_enumerator_get_container (G_FILE_ENUMERATOR (source)); files = g_list_sort (files, file_sort_func); /* iterate over the available files */ for (l = files; l; l = g_list_next (l)) { GFileInfo *info = l->data; GFile *file; file = g_file_get_child (parent, g_file_info_get_name (info)); add_single_file_from_info (bg_source, file, info, NULL); } g_list_foreach (files, (GFunc) g_object_unref, NULL); g_list_free (files); }
static void on_files_listed (GObject *source_object, GAsyncResult *res, gpointer user_data) { GError *error = NULL; JsonObject *options; GList *files; files = g_file_enumerator_next_files_finish (G_FILE_ENUMERATOR (source_object), res, &error); if (error) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { CockpitFslist *self = COCKPIT_FSLIST (user_data); g_message ("%s: couldn't process files %s", COCKPIT_FSLIST(user_data)->path, error->message); options = cockpit_channel_close_options (COCKPIT_CHANNEL (self)); json_object_set_string_member (options, "message", error->message); cockpit_channel_close (COCKPIT_CHANNEL (self), "internal-error"); } g_clear_error (&error); return; } CockpitFslist *self = COCKPIT_FSLIST (user_data); if (files == NULL) { JsonObject *msg; GBytes *msg_bytes; msg = json_object_new (); json_object_set_string_member (msg, "event", "present-done"); msg_bytes = cockpit_json_write_bytes (msg); json_object_unref (msg); cockpit_channel_send (COCKPIT_CHANNEL(self), msg_bytes, FALSE); g_bytes_unref (msg_bytes); g_clear_object (&self->cancellable); g_object_unref (source_object); if (self->monitor == NULL) { cockpit_channel_done (COCKPIT_CHANNEL (self)); cockpit_channel_close (COCKPIT_CHANNEL (self), NULL); } return; } for (GList *l = files; l; l = l->next) { GFileInfo *info = G_FILE_INFO (l->data); JsonObject *msg; GBytes *msg_bytes; msg = json_object_new (); json_object_set_string_member (msg, "event", "present"); json_object_set_string_member (msg, "path", g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_STANDARD_NAME)); json_object_set_string_member (msg, "type", cockpit_file_type_to_string (g_file_info_get_file_type (info))); msg_bytes = cockpit_json_write_bytes (msg); json_object_unref (msg); cockpit_channel_send (COCKPIT_CHANNEL(self), msg_bytes, FALSE); g_bytes_unref (msg_bytes); } g_list_free_full (files, g_object_unref); g_file_enumerator_next_files_async (G_FILE_ENUMERATOR (source_object), 10, G_PRIORITY_DEFAULT, self->cancellable, on_files_listed, self); }
static void enumerate_next_files_async_cb (GObject *source, GAsyncResult *res, gpointer user_data) { EnumerateJob *job = user_data; GList *enumerated_files, *l; GFileInfo *info; GSList *logs; const char *content_type, *name; char *parse_string, *container_path; GFileType type; GFile *container; enumerated_files = g_file_enumerator_next_files_finish (G_FILE_ENUMERATOR (source), res, NULL); if (!enumerated_files) { enumerate_job_finish (job); return; } logs = job->logs; container = g_file_enumerator_get_container (G_FILE_ENUMERATOR (source)); container_path = g_file_get_path (container); /* TODO: we don't support grouping rotated logs yet, skip gzipped files * and those which name contains a formatted date. */ for (l = enumerated_files; l; l = l->next) { info = l->data; type = g_file_info_get_file_type (info); content_type = g_file_info_get_content_type (info); name = g_file_info_get_name (info); if (!g_file_info_get_attribute_boolean (info, "access::can-read")) { g_object_unref (info); continue; } if (type != (G_FILE_TYPE_REGULAR || G_FILE_TYPE_SYMBOLIC_LINK) || !g_content_type_is_a (content_type, "text/plain")) { g_object_unref (info); continue; } if (g_content_type_is_a (content_type, "application/x-gzip")) { g_object_unref (info); continue; } if (g_regex_match_simple ("\\d{8}$", name, 0, 0)) { g_object_unref (info); continue; } parse_string = g_build_filename (container_path, name, NULL); if (g_slist_find_custom (logs, parse_string, (GCompareFunc) g_ascii_strcasecmp) == NULL) { logs = g_slist_append (logs, parse_string); } else { g_free (parse_string); } g_object_unref (info); parse_string = NULL; } g_list_free (enumerated_files); g_object_unref (container); g_free (container_path); job->logs = logs; enumerate_job_finish (job); }
static void got_more_files (GObject *source_object, GAsyncResult *res, gpointer user_data) { LoadBasenamesData *data = user_data; GList *infos, *l; GFileInfo *info; const char *name; gboolean append_slash; char *t; char *basename; if (data->completer == NULL) { /* Was cancelled */ load_basenames_data_free (data); return; } infos = g_file_enumerator_next_files_finish (data->enumerator, res, NULL); for (l = infos; l != NULL; l = l->next) { info = l->data; if (data->dirs_only && g_file_info_get_file_type (info) != G_FILE_TYPE_DIRECTORY) { g_object_unref (info); continue; } append_slash = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY; name = g_file_info_get_name (info); if (name == NULL) { g_object_unref (info); continue; } if (data->should_escape) basename = g_uri_escape_string (name, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE); else /* If not should_escape, must be a local filename, convert to utf8 */ basename = g_filename_to_utf8 (name, -1, NULL, NULL, NULL); if (basename) { if (append_slash) { t = basename; basename = g_strconcat (basename, "/", NULL); g_free (t); } data->basenames = g_list_prepend (data->basenames, basename); } g_object_unref (info); } g_list_free (infos); if (infos) { /* Not last, get more files */ g_file_enumerator_next_files_async (data->enumerator, 100, 0, data->cancellable, got_more_files, data); } else { data->completer->basename_loader = NULL; if (data->completer->basenames_dir) g_object_unref (data->completer->basenames_dir); g_list_foreach (data->completer->basenames, (GFunc)g_free, NULL); g_list_free (data->completer->basenames); data->completer->basenames_dir = g_object_ref (data->dir); data->completer->basenames = data->basenames; data->completer->basenames_are_escaped = data->should_escape; data->basenames = NULL; g_file_enumerator_close_async (data->enumerator, 0, NULL, NULL, NULL); g_signal_emit (data->completer, signals[GOT_COMPLETION_DATA], 0); load_basenames_data_free (data); } }
static void more_files_callback (GObject *source_object, GAsyncResult *res, gpointer user_data) { InsensitiveFileSearchData *data = (InsensitiveFileSearchData *) (user_data); GList *files, *l; gchar *filename = NULL, *component, *case_folded_name, *name_collation_key; gboolean end_of_files, is_utf8; files = g_file_enumerator_next_files_finish (data->enumerator, res, NULL); end_of_files = files == NULL; component = data->split_path[data->index]; g_return_if_fail (component != NULL); is_utf8 = (g_utf8_validate (component, -1, NULL)); if (is_utf8) { case_folded_name = g_utf8_casefold (component, -1); name_collation_key = g_utf8_collate_key (case_folded_name, -1); g_free (case_folded_name); } else { name_collation_key = g_ascii_strdown (component, -1); } for (l = files; l != NULL; l = l->next) { GFileInfo *info; const gchar *this_name; gchar *key; info = l->data; this_name = g_file_info_get_name (info); if (is_utf8 && g_utf8_validate (this_name, -1, NULL)) { gchar *case_folded; case_folded = g_utf8_casefold (this_name, -1); key = g_utf8_collate_key (case_folded, -1); g_free (case_folded); } else { key = g_ascii_strdown (this_name, -1); } if (strcmp (key, name_collation_key) == 0) filename = g_strdup (this_name); g_free (key); if (filename) break; } g_list_free_full (files, g_object_unref); g_free (name_collation_key); if (filename) { GFile *next_file; g_file_enumerator_close_async (data->enumerator, G_PRIORITY_DEFAULT, data->cancellable, NULL, NULL); g_object_unref (data->enumerator); data->enumerator = NULL; /* Set the current file and continue searching */ next_file = g_file_get_child (data->current_file, filename); g_free (filename); g_object_unref (data->current_file); data->current_file = next_file; data->index++; /* Skip any empty components due to multiple slashes */ while (data->split_path[data->index] != NULL && *data->split_path[data->index] == 0) data->index++; if (data->split_path[data->index] == NULL) { /* Search is complete, file was found */ GSimpleAsyncResult *simple; simple = g_simple_async_result_new (G_OBJECT (data->root), data->callback, data->user_data, _g_find_file_insensitive_async); g_simple_async_result_set_op_res_gpointer (simple, g_object_ref (data->current_file), g_object_unref); g_simple_async_result_complete_in_idle (simple); g_object_unref (simple); clear_find_file_insensitive_state (data); return; } /* Continue searching down the tree */ g_file_enumerate_children_async (data->current_file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, G_PRIORITY_DEFAULT, data->cancellable, enumerated_children_callback, data); return; } if (end_of_files) { /* Could not find the given file, abort the search */ GSimpleAsyncResult *simple; GFile *file; g_object_unref (data->enumerator); data->enumerator = NULL; simple = g_simple_async_result_new (G_OBJECT (data->root), data->callback, data->user_data, _g_find_file_insensitive_async); file = g_file_get_child (data->root, data->original_path); g_simple_async_result_set_op_res_gpointer (simple, file, g_object_unref); g_simple_async_result_complete_in_idle (simple); g_object_unref (simple); clear_find_file_insensitive_state (data); return; } /* Continue enumerating */ g_file_enumerator_next_files_async (data->enumerator, INSENSITIVE_SEARCH_ITEMS_PER_CALLBACK, G_PRIORITY_DEFAULT, data->cancellable, more_files_callback, data); }
static void enum_files_cb (GObject *obj, GAsyncResult *result, gpointer data) { RBAndroidSource *source = RB_ANDROID_SOURCE (data); RBAndroidSourcePrivate *priv = GET_PRIVATE(source); GFileEnumerator *e = G_FILE_ENUMERATOR (obj); GError *error = NULL; GFileInfo *info; GList *files; GList *l; files = g_file_enumerator_next_files_finish (e, result, &error); if (error != NULL) { rb_debug ("error listing files: %s", error->message); music_dirs_done (source); return; } if (files == NULL) { priv->scanned++; g_object_unref (e); find_music_dirs (source); return; } for (l = files; l != NULL; l = l->next) { guint32 filetype; info = (GFileInfo *)l->data; filetype = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE); if (filetype == G_FILE_TYPE_DIRECTORY) { GFile *dir; if (priv->scanned == 0) { rb_debug ("got storage container %s", g_file_info_get_name (info)); dir = g_file_get_child (g_file_enumerator_get_container (e), g_file_info_get_name (info)); g_queue_push_tail (&priv->to_scan, dir); } else if (g_ascii_strcasecmp (g_file_info_get_name (info), "music") == 0) { GFile *storage; char *uri; storage = g_file_enumerator_get_container (e); dir = g_file_get_child (storage, g_file_info_get_name (info)); uri = g_file_get_uri (dir); rb_debug ("music dir found at %s", uri); /* keep the container around for space/capacity calculation */ priv->storage = g_list_append (priv->storage, dir); rhythmdb_import_job_add_uri (priv->import_job, uri); g_free (uri); } } g_object_unref (info); } g_list_free (files); g_file_enumerator_next_files_async (G_FILE_ENUMERATOR (obj), 64, G_PRIORITY_DEFAULT, priv->cancel, enum_files_cb, source); }