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 void gth_metadata_provider_file_read (GthMetadataProvider *self, GthFileData *file_data, const char *attributes) { GFileAttributeMatcher *matcher; char *value; GTimeVal *timeval_p; const char *value_s; matcher = g_file_attribute_matcher_new (attributes); value = g_format_size_for_display (g_file_info_get_size (file_data->info)); g_file_info_set_attribute_string (file_data->info, "gth::file::display-size", value); g_free (value); timeval_p = gth_file_data_get_modification_time (file_data); value = _g_time_val_strftime (timeval_p, "%x %X"); g_file_info_set_attribute_string (file_data->info, "gth::file::display-mtime", value); g_free (value); value = g_file_get_parse_name (file_data->file); g_file_info_set_attribute_string (file_data->info, "gth::file::full-name", value); g_free (value); value_s = get_static_string (g_file_info_get_content_type (file_data->info)); if (value_s != NULL) g_file_info_set_attribute_string (file_data->info, "gth::file::content-type", value_s); g_file_attribute_matcher_unref (matcher); }
static GFileAttributeMatcher * g_file_attribute_matcher_subtract_attributes (GFileAttributeMatcher *matcher, const char * attributes) { GFileAttributeMatcher *result, *tmp; tmp = g_file_attribute_matcher_new (attributes); result = g_file_attribute_matcher_subtract (matcher, tmp); g_file_attribute_matcher_unref (tmp); return result; }
static GFileInfo * g_resource_file_query_filesystem_info (GFile *file, const char *attributes, GCancellable *cancellable, GError **error) { GFileInfo *info; GFileAttributeMatcher *matcher; info = g_file_info_new (); matcher = g_file_attribute_matcher_new (attributes); if (g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE)) g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, "resource"); if (g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY)) g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, TRUE); g_file_attribute_matcher_unref (matcher); return info; }
static GFileInfo * g_resource_file_query_info (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error) { GResourceFile *resource = G_RESOURCE_FILE (file); GError *my_error = NULL; GFileInfo *info; GFileAttributeMatcher *matcher; gboolean res; gsize size; guint32 resource_flags; char **children; gboolean is_dir; char *base; is_dir = FALSE; children = g_resources_enumerate_children (resource->path, 0, NULL); if (children != NULL) { g_strfreev (children); is_dir = TRUE; } /* root is always there */ if (strcmp ("/", resource->path) == 0) is_dir = TRUE; if (!is_dir) { res = g_resources_get_info (resource->path, 0, &size, &resource_flags, &my_error); if (!res) { if (g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, _("The resource at '%s' does not exist"), resource->path); } else g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, my_error->message); g_clear_error (&my_error); return FALSE; } } matcher = g_file_attribute_matcher_new (attributes); info = g_file_info_new (); base = g_resource_file_get_basename (file); g_file_info_set_name (info, base); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_READ, TRUE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_WRITE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_EXECUTE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH, FALSE); if (is_dir) { g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); } else { GBytes *bytes; char *content_type; g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); g_file_info_set_size (info, size); if ((_g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE) || ((~resource_flags & G_RESOURCE_FLAGS_COMPRESSED) && _g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE))) && (bytes = g_resources_lookup_data (resource->path, 0, NULL))) { const guchar *data; gsize data_size; data = g_bytes_get_data (bytes, &data_size); content_type = g_content_type_guess (base, data, data_size, NULL); g_bytes_unref (bytes); } else content_type = NULL; if (content_type) { _g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE, content_type); _g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE, content_type); g_free (content_type); } } g_free (base); g_file_attribute_matcher_unref (matcher); return info; }