static void g_local_file_enumerator_finalize (GObject *object) { GLocalFileEnumerator *local; local = G_LOCAL_FILE_ENUMERATOR (object); if (local->got_parent_info) _g_local_file_info_free_parent_info (&local->parent_info); g_free (local->filename); g_file_attribute_matcher_unref (local->matcher); g_file_attribute_matcher_unref (local->reduced_matcher); if (local->dir) { #ifdef USE_GDIR g_dir_close (local->dir); #else closedir (local->dir); #endif local->dir = NULL; } free_entries (local); G_OBJECT_CLASS (g_local_file_enumerator_parent_class)->finalize (object); }
static GFileInfo * g_local_file_enumerator_next_file (GFileEnumerator *enumerator, GCancellable *cancellable, GError **error) { GLocalFileEnumerator *local = G_LOCAL_FILE_ENUMERATOR (enumerator); const char *filename; char *path; GFileInfo *info; GError *my_error; if (!local->got_parent_info) { _g_local_file_info_get_parent_info (local->filename, local->matcher, &local->parent_info); local->got_parent_info = TRUE; } next_file: #ifdef USE_GDIR filename = g_dir_read_name (local->dir); #else filename = next_file_helper (local); #endif if (filename == NULL) return NULL; my_error = NULL; path = g_build_filename (local->filename, filename, NULL); info = _g_local_file_info_get (filename, path, local->matcher, local->flags, &local->parent_info, &my_error); g_free (path); if (info == NULL) { /* Failed to get info */ /* If the file does not exist there might have been a race where * the file was removed between the readdir and the stat, so we * ignore the file. */ if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_FOUND) { g_error_free (my_error); goto next_file; } else g_propagate_error (error, my_error); } return info; }
static gboolean g_local_file_enumerator_close (GFileEnumerator *enumerator, GCancellable *cancellable, GError **error) { GLocalFileEnumerator *local = G_LOCAL_FILE_ENUMERATOR (enumerator); if (local->dir) { #ifdef USE_GDIR g_dir_close (local->dir); #else closedir (local->dir); #endif local->dir = NULL; } return TRUE; }
static GFileInfo * g_local_file_enumerator_next_file (GFileEnumerator *enumerator, GCancellable *cancellable, GError **error) { GLocalFileEnumerator *local = G_LOCAL_FILE_ENUMERATOR (enumerator); const char *filename; char *path; GFileInfo *info; GError *my_error; GFileType file_type; if (!local->got_parent_info) { _g_local_file_info_get_parent_info (local->filename, local->matcher, &local->parent_info); local->got_parent_info = TRUE; } next_file: #ifdef USE_GDIR filename = g_dir_read_name (local->dir); file_type = G_FILE_TYPE_UNKNOWN; #else filename = next_file_helper (local, &file_type); #endif if (filename == NULL) return NULL; my_error = NULL; path = g_build_filename (local->filename, filename, NULL); if (file_type == G_FILE_TYPE_UNKNOWN || (file_type == G_FILE_TYPE_SYMBOLIC_LINK && !(local->flags & G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS))) { info = _g_local_file_info_get (filename, path, local->matcher, local->flags, &local->parent_info, &my_error); } else { info = _g_local_file_info_get (filename, path, local->reduced_matcher, local->flags, &local->parent_info, &my_error); if (info) { _g_local_file_info_get_nostat (info, filename, path, local->matcher); g_file_info_set_file_type (info, file_type); if (file_type == G_FILE_TYPE_SYMBOLIC_LINK) g_file_info_set_is_symlink (info, TRUE); } } g_free (path); if (info == NULL) { /* Failed to get info */ /* If the file does not exist there might have been a race where * the file was removed between the readdir and the stat, so we * ignore the file. */ if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_error_free (my_error); goto next_file; } else g_propagate_error (error, my_error); } return info; }