1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 * Author: Alexander Larsson <alexl@redhat.com>
23 * @short_description: File Information and Attributes
25 * @see_also: #GFile, [GFileAttribute][gio-GFileAttribute]
27 * Functionality for manipulating basic metadata for files. #GFileInfo
28 * implements methods for getting information that all files should
29 * contain, and allows for manipulation of extended attributes.
31 * See [GFileAttribute][gio-GFileAttribute] for more information on how
32 * GIO handles file attributes.
34 * To obtain a #GFileInfo for a #GFile, use g_file_query_info() (or its
35 * async variant). To obtain a #GFileInfo for a file input or output
36 * stream, use g_file_input_stream_query_info() or
37 * g_file_output_stream_query_info() (or their async variants).
39 * To change the actual attributes of a file, you should then set the
40 * attribute in the #GFileInfo and call g_file_set_attributes_from_info()
41 * or g_file_set_attributes_async() on a GFile.
43 * However, not all attributes can be changed in the file. For instance,
44 * the actual size of a file cannot be changed via g_file_info_set_size().
45 * You may call g_file_query_settable_attributes() and
46 * g_file_query_writable_namespaces() to discover the settable attributes
47 * of a particular file at runtime.
49 * #GFileAttributeMatcher allows for searching through a #GFileInfo for
57 #include "gfileinfo.h"
58 #include "gfileinfo-priv.h"
59 #include "gfileattribute-priv.h"
64 /* We use this nasty thing, because NULL is a valid attribute matcher (matches nothing) */
65 #define NO_ATTRIBUTE_MASK ((GFileAttributeMatcher *)1)
69 GFileAttributeValue value;
74 GObject parent_instance;
77 GFileAttributeMatcher *mask;
80 struct _GFileInfoClass
82 GObjectClass parent_class;
86 G_DEFINE_TYPE (GFileInfo, g_file_info, G_TYPE_OBJECT);
90 guint32 attribute_id_counter;
93 G_LOCK_DEFINE_STATIC (attribute_hash);
94 static int namespace_id_counter = 0;
95 static GHashTable *ns_hash = NULL;
96 static GHashTable *attribute_hash = NULL;
97 static char ***attributes = NULL;
99 /* Attribute ids are 32bit, we split it up like this:
100 * |------------|--------------------|
102 * namespace attribute id
104 * This way the attributes gets sorted in namespace order
108 #define NS_MASK ((guint32)((1<<12) - 1))
110 #define ID_MASK ((guint32)((1<<20) - 1))
112 #define GET_NS(_attr_id) \
113 (((guint32) (_attr_id) >> NS_POS) & NS_MASK)
114 #define GET_ID(_attr_id) \
115 (((guint32)(_attr_id) >> ID_POS) & ID_MASK)
117 #define MAKE_ATTR_ID(_ns, _id) \
118 ( ((((guint32) _ns) & NS_MASK) << NS_POS) | \
119 ((((guint32) _id) & ID_MASK) << ID_POS) )
122 _lookup_namespace (const char *namespace)
126 ns_info = g_hash_table_lookup (ns_hash, namespace);
129 ns_info = g_new0 (NSInfo, 1);
130 ns_info->id = ++namespace_id_counter;
131 g_hash_table_insert (ns_hash, g_strdup (namespace), ns_info);
132 attributes = g_realloc (attributes, (ns_info->id + 1) * sizeof (char **));
133 attributes[ns_info->id] = g_new (char *, 1);
134 attributes[ns_info->id][0] = g_strconcat (namespace, "::*", NULL);
140 _lookup_attribute (const char *attribute)
147 attr_id = GPOINTER_TO_UINT (g_hash_table_lookup (attribute_hash, attribute));
152 colon = strstr (attribute, "::");
154 ns = g_strndup (attribute, colon - attribute);
158 ns_info = _lookup_namespace (ns);
161 id = ++ns_info->attribute_id_counter;
162 attributes[ns_info->id] = g_realloc (attributes[ns_info->id], (id + 1) * sizeof (char *));
163 attributes[ns_info->id][id] = g_strdup (attribute);
165 attr_id = MAKE_ATTR_ID (ns_info->id, id);
167 g_hash_table_insert (attribute_hash, attributes[ns_info->id][id], GUINT_TO_POINTER (attr_id));
173 ensure_attribute_hash (void)
175 if (attribute_hash != NULL)
178 ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
179 attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
181 #define REGISTER_ATTRIBUTE(name) G_STMT_START{\
182 guint _u = _lookup_attribute (G_FILE_ATTRIBUTE_ ## name); \
183 /* use for generating the ID: g_print ("#define G_FILE_ATTRIBUTE_ID_%s (%u + %u)\n", #name + 17, _u & ~ID_MASK, _u & ID_MASK); */ \
184 g_assert (_u == G_FILE_ATTRIBUTE_ID_ ## name); \
187 REGISTER_ATTRIBUTE (STANDARD_TYPE);
188 REGISTER_ATTRIBUTE (STANDARD_IS_HIDDEN);
189 REGISTER_ATTRIBUTE (STANDARD_IS_BACKUP);
190 REGISTER_ATTRIBUTE (STANDARD_IS_SYMLINK);
191 REGISTER_ATTRIBUTE (STANDARD_IS_VIRTUAL);
192 REGISTER_ATTRIBUTE (STANDARD_NAME);
193 REGISTER_ATTRIBUTE (STANDARD_DISPLAY_NAME);
194 REGISTER_ATTRIBUTE (STANDARD_EDIT_NAME);
195 REGISTER_ATTRIBUTE (STANDARD_COPY_NAME);
196 REGISTER_ATTRIBUTE (STANDARD_DESCRIPTION);
197 REGISTER_ATTRIBUTE (STANDARD_ICON);
198 REGISTER_ATTRIBUTE (STANDARD_CONTENT_TYPE);
199 REGISTER_ATTRIBUTE (STANDARD_FAST_CONTENT_TYPE);
200 REGISTER_ATTRIBUTE (STANDARD_SIZE);
201 REGISTER_ATTRIBUTE (STANDARD_ALLOCATED_SIZE);
202 REGISTER_ATTRIBUTE (STANDARD_SYMLINK_TARGET);
203 REGISTER_ATTRIBUTE (STANDARD_TARGET_URI);
204 REGISTER_ATTRIBUTE (STANDARD_SORT_ORDER);
205 REGISTER_ATTRIBUTE (STANDARD_SYMBOLIC_ICON);
206 REGISTER_ATTRIBUTE (ETAG_VALUE);
207 REGISTER_ATTRIBUTE (ID_FILE);
208 REGISTER_ATTRIBUTE (ID_FILESYSTEM);
209 REGISTER_ATTRIBUTE (ACCESS_CAN_READ);
210 REGISTER_ATTRIBUTE (ACCESS_CAN_WRITE);
211 REGISTER_ATTRIBUTE (ACCESS_CAN_EXECUTE);
212 REGISTER_ATTRIBUTE (ACCESS_CAN_DELETE);
213 REGISTER_ATTRIBUTE (ACCESS_CAN_TRASH);
214 REGISTER_ATTRIBUTE (ACCESS_CAN_RENAME);
215 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_MOUNT);
216 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_UNMOUNT);
217 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_EJECT);
218 REGISTER_ATTRIBUTE (MOUNTABLE_UNIX_DEVICE);
219 REGISTER_ATTRIBUTE (MOUNTABLE_UNIX_DEVICE_FILE);
220 REGISTER_ATTRIBUTE (MOUNTABLE_HAL_UDI);
221 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_START);
222 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_START_DEGRADED);
223 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_STOP);
224 REGISTER_ATTRIBUTE (MOUNTABLE_START_STOP_TYPE);
225 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_POLL);
226 REGISTER_ATTRIBUTE (MOUNTABLE_IS_MEDIA_CHECK_AUTOMATIC);
227 REGISTER_ATTRIBUTE (TIME_MODIFIED);
228 REGISTER_ATTRIBUTE (TIME_MODIFIED_USEC);
229 REGISTER_ATTRIBUTE (TIME_ACCESS);
230 REGISTER_ATTRIBUTE (TIME_ACCESS_USEC);
231 REGISTER_ATTRIBUTE (TIME_CHANGED);
232 REGISTER_ATTRIBUTE (TIME_CHANGED_USEC);
233 REGISTER_ATTRIBUTE (TIME_CREATED);
234 REGISTER_ATTRIBUTE (TIME_CREATED_USEC);
235 REGISTER_ATTRIBUTE (UNIX_DEVICE);
236 REGISTER_ATTRIBUTE (UNIX_INODE);
237 REGISTER_ATTRIBUTE (UNIX_MODE);
238 REGISTER_ATTRIBUTE (UNIX_NLINK);
239 REGISTER_ATTRIBUTE (UNIX_UID);
240 REGISTER_ATTRIBUTE (UNIX_GID);
241 REGISTER_ATTRIBUTE (UNIX_RDEV);
242 REGISTER_ATTRIBUTE (UNIX_BLOCK_SIZE);
243 REGISTER_ATTRIBUTE (UNIX_BLOCKS);
244 REGISTER_ATTRIBUTE (UNIX_IS_MOUNTPOINT);
245 REGISTER_ATTRIBUTE (DOS_IS_ARCHIVE);
246 REGISTER_ATTRIBUTE (DOS_IS_SYSTEM);
247 REGISTER_ATTRIBUTE (OWNER_USER);
248 REGISTER_ATTRIBUTE (OWNER_USER_REAL);
249 REGISTER_ATTRIBUTE (OWNER_GROUP);
250 REGISTER_ATTRIBUTE (THUMBNAIL_PATH);
251 REGISTER_ATTRIBUTE (THUMBNAILING_FAILED);
252 REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID);
253 REGISTER_ATTRIBUTE (PREVIEW_ICON);
254 REGISTER_ATTRIBUTE (FILESYSTEM_SIZE);
255 REGISTER_ATTRIBUTE (FILESYSTEM_FREE);
256 REGISTER_ATTRIBUTE (FILESYSTEM_TYPE);
257 REGISTER_ATTRIBUTE (FILESYSTEM_READONLY);
258 REGISTER_ATTRIBUTE (FILESYSTEM_USE_PREVIEW);
259 REGISTER_ATTRIBUTE (GVFS_BACKEND);
260 REGISTER_ATTRIBUTE (SELINUX_CONTEXT);
261 REGISTER_ATTRIBUTE (TRASH_ITEM_COUNT);
262 REGISTER_ATTRIBUTE (TRASH_ORIG_PATH);
263 REGISTER_ATTRIBUTE (TRASH_DELETION_DATE);
265 #undef REGISTER_ATTRIBUTE
269 lookup_namespace (const char *namespace)
274 G_LOCK (attribute_hash);
276 ensure_attribute_hash ();
278 ns_info = _lookup_namespace (namespace);
283 G_UNLOCK (attribute_hash);
289 get_attribute_for_id (int attribute)
292 G_LOCK (attribute_hash);
293 s = attributes[GET_NS(attribute)][GET_ID(attribute)];
294 G_UNLOCK (attribute_hash);
299 lookup_attribute (const char *attribute)
303 G_LOCK (attribute_hash);
304 ensure_attribute_hash ();
306 attr_id = _lookup_attribute (attribute);
308 G_UNLOCK (attribute_hash);
314 g_file_info_finalize (GObject *object)
318 GFileAttribute *attrs;
320 info = G_FILE_INFO (object);
322 attrs = (GFileAttribute *)info->attributes->data;
323 for (i = 0; i < info->attributes->len; i++)
324 _g_file_attribute_value_clear (&attrs[i].value);
325 g_array_free (info->attributes, TRUE);
327 if (info->mask != NO_ATTRIBUTE_MASK)
328 g_file_attribute_matcher_unref (info->mask);
330 G_OBJECT_CLASS (g_file_info_parent_class)->finalize (object);
334 g_file_info_class_init (GFileInfoClass *klass)
336 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
338 gobject_class->finalize = g_file_info_finalize;
342 g_file_info_init (GFileInfo *info)
344 info->mask = NO_ATTRIBUTE_MASK;
345 info->attributes = g_array_new (FALSE, FALSE,
346 sizeof (GFileAttribute));
352 * Creates a new file info structure.
354 * Returns: a #GFileInfo.
357 g_file_info_new (void)
359 return g_object_new (G_TYPE_FILE_INFO, NULL);
363 * g_file_info_copy_into:
364 * @src_info: source to copy attributes from.
365 * @dest_info: destination to copy attributes to.
367 * Copies all of the [GFileAttribute][gio-GFileAttribute]
368 * from @src_info to @dest_info.
371 g_file_info_copy_into (GFileInfo *src_info,
372 GFileInfo *dest_info)
374 GFileAttribute *source, *dest;
377 g_return_if_fail (G_IS_FILE_INFO (src_info));
378 g_return_if_fail (G_IS_FILE_INFO (dest_info));
380 dest = (GFileAttribute *)dest_info->attributes->data;
381 for (i = 0; i < dest_info->attributes->len; i++)
382 _g_file_attribute_value_clear (&dest[i].value);
384 g_array_set_size (dest_info->attributes,
385 src_info->attributes->len);
387 source = (GFileAttribute *)src_info->attributes->data;
388 dest = (GFileAttribute *)dest_info->attributes->data;
390 for (i = 0; i < src_info->attributes->len; i++)
392 dest[i].attribute = source[i].attribute;
393 dest[i].value.type = G_FILE_ATTRIBUTE_TYPE_INVALID;
394 _g_file_attribute_value_set (&dest[i].value, &source[i].value);
397 if (dest_info->mask != NO_ATTRIBUTE_MASK)
398 g_file_attribute_matcher_unref (dest_info->mask);
400 if (src_info->mask == NO_ATTRIBUTE_MASK)
401 dest_info->mask = NO_ATTRIBUTE_MASK;
403 dest_info->mask = g_file_attribute_matcher_ref (src_info->mask);
408 * @other: a #GFileInfo.
410 * Duplicates a file info structure.
412 * Returns: (transfer full): a duplicate #GFileInfo of @other.
415 g_file_info_dup (GFileInfo *other)
419 g_return_val_if_fail (G_IS_FILE_INFO (other), NULL);
421 new = g_file_info_new ();
422 g_file_info_copy_into (other, new);
427 * g_file_info_set_attribute_mask:
428 * @info: a #GFileInfo.
429 * @mask: a #GFileAttributeMatcher.
431 * Sets @mask on @info to match specific attribute types.
434 g_file_info_set_attribute_mask (GFileInfo *info,
435 GFileAttributeMatcher *mask)
437 GFileAttribute *attr;
440 g_return_if_fail (G_IS_FILE_INFO (info));
442 if (mask != info->mask)
444 if (info->mask != NO_ATTRIBUTE_MASK)
445 g_file_attribute_matcher_unref (info->mask);
446 info->mask = g_file_attribute_matcher_ref (mask);
448 /* Remove non-matching attributes */
449 for (i = 0; i < info->attributes->len; i++)
451 attr = &g_array_index (info->attributes, GFileAttribute, i);
452 if (!_g_file_attribute_matcher_matches_id (mask,
455 _g_file_attribute_value_clear (&attr->value);
456 g_array_remove_index (info->attributes, i);
464 * g_file_info_unset_attribute_mask:
467 * Unsets a mask set by g_file_info_set_attribute_mask(), if one
471 g_file_info_unset_attribute_mask (GFileInfo *info)
473 g_return_if_fail (G_IS_FILE_INFO (info));
475 if (info->mask != NO_ATTRIBUTE_MASK)
476 g_file_attribute_matcher_unref (info->mask);
477 info->mask = NO_ATTRIBUTE_MASK;
481 * g_file_info_clear_status:
482 * @info: a #GFileInfo.
484 * Clears the status information from @info.
487 g_file_info_clear_status (GFileInfo *info)
489 GFileAttribute *attrs;
492 g_return_if_fail (G_IS_FILE_INFO (info));
494 attrs = (GFileAttribute *)info->attributes->data;
495 for (i = 0; i < info->attributes->len; i++)
496 attrs[i].value.status = G_FILE_ATTRIBUTE_STATUS_UNSET;
500 g_file_info_find_place (GFileInfo *info,
504 GFileAttribute *attrs;
505 /* Binary search for the place where attribute would be, if it's
509 max = info->attributes->len;
511 attrs = (GFileAttribute *)info->attributes->data;
515 med = min + (max - min) / 2;
516 if (attrs[med].attribute == attribute)
521 else if (attrs[med].attribute < attribute)
523 else /* attrs[med].attribute > attribute */
530 static GFileAttributeValue *
531 g_file_info_find_value (GFileInfo *info,
534 GFileAttribute *attrs;
537 i = g_file_info_find_place (info, attr_id);
538 attrs = (GFileAttribute *)info->attributes->data;
539 if (i < info->attributes->len &&
540 attrs[i].attribute == attr_id)
541 return &attrs[i].value;
546 static GFileAttributeValue *
547 g_file_info_find_value_by_name (GFileInfo *info,
548 const char *attribute)
552 attr_id = lookup_attribute (attribute);
553 return g_file_info_find_value (info, attr_id);
557 * g_file_info_has_attribute:
558 * @info: a #GFileInfo.
559 * @attribute: a file attribute key.
561 * Checks if a file info structure has an attribute named @attribute.
563 * Returns: %TRUE if @Ginfo has an attribute named @attribute,
567 g_file_info_has_attribute (GFileInfo *info,
568 const char *attribute)
570 GFileAttributeValue *value;
572 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
573 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
575 value = g_file_info_find_value_by_name (info, attribute);
576 return value != NULL;
580 * g_file_info_has_namespace:
581 * @info: a #GFileInfo.
582 * @name_space: a file attribute namespace.
584 * Checks if a file info structure has an attribute in the
585 * specified @name_space.
587 * Returns: %TRUE if @Ginfo has an attribute in @name_space,
593 g_file_info_has_namespace (GFileInfo *info,
594 const char *name_space)
596 GFileAttribute *attrs;
600 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
601 g_return_val_if_fail (name_space != NULL, FALSE);
603 ns_id = lookup_namespace (name_space);
605 attrs = (GFileAttribute *)info->attributes->data;
606 for (i = 0; i < info->attributes->len; i++)
608 if (GET_NS (attrs[i].attribute) == ns_id)
616 * g_file_info_list_attributes:
617 * @info: a #GFileInfo.
618 * @name_space: a file attribute key's namespace.
620 * Lists the file info structure's attributes.
622 * Returns: (nullable) (array zero-terminated=1) (transfer full): a
623 * null-terminated array of strings of all of the possible attribute
624 * types for the given @name_space, or %NULL on error.
627 g_file_info_list_attributes (GFileInfo *info,
628 const char *name_space)
631 GFileAttribute *attrs;
633 guint32 ns_id = (name_space) ? lookup_namespace (name_space) : 0;
636 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
638 names = g_ptr_array_new ();
639 attrs = (GFileAttribute *)info->attributes->data;
640 for (i = 0; i < info->attributes->len; i++)
642 attribute = attrs[i].attribute;
643 if (ns_id == 0 || GET_NS (attribute) == ns_id)
644 g_ptr_array_add (names, g_strdup (get_attribute_for_id (attribute)));
648 g_ptr_array_add (names, NULL);
650 return (char **)g_ptr_array_free (names, FALSE);
654 * g_file_info_get_attribute_type:
655 * @info: a #GFileInfo.
656 * @attribute: a file attribute key.
658 * Gets the attribute type for an attribute key.
660 * Returns: a #GFileAttributeType for the given @attribute, or
661 * %G_FILE_ATTRIBUTE_TYPE_INVALID if the key is not set.
664 g_file_info_get_attribute_type (GFileInfo *info,
665 const char *attribute)
667 GFileAttributeValue *value;
669 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_ATTRIBUTE_TYPE_INVALID);
670 g_return_val_if_fail (attribute != NULL && *attribute != '\0', G_FILE_ATTRIBUTE_TYPE_INVALID);
672 value = g_file_info_find_value_by_name (info, attribute);
676 return G_FILE_ATTRIBUTE_TYPE_INVALID;
680 * g_file_info_remove_attribute:
681 * @info: a #GFileInfo.
682 * @attribute: a file attribute key.
684 * Removes all cases of @attribute from @info if it exists.
687 g_file_info_remove_attribute (GFileInfo *info,
688 const char *attribute)
691 GFileAttribute *attrs;
694 g_return_if_fail (G_IS_FILE_INFO (info));
695 g_return_if_fail (attribute != NULL && *attribute != '\0');
697 attr_id = lookup_attribute (attribute);
699 i = g_file_info_find_place (info, attr_id);
700 attrs = (GFileAttribute *)info->attributes->data;
701 if (i < info->attributes->len &&
702 attrs[i].attribute == attr_id)
704 _g_file_attribute_value_clear (&attrs[i].value);
705 g_array_remove_index (info->attributes, i);
710 * g_file_info_get_attribute_data:
711 * @info: a #GFileInfo
712 * @attribute: a file attribute key
713 * @type: (out) (allow-none): return location for the attribute type, or %NULL
714 * @value_pp: (out) (allow-none): return location for the attribute value, or %NULL
715 * @status: (out) (allow-none): return location for the attribute status, or %NULL
717 * Gets the attribute type, value and status for an attribute key.
719 * Returns: (transfer none): %TRUE if @info has an attribute named @attribute,
723 g_file_info_get_attribute_data (GFileInfo *info,
724 const char *attribute,
725 GFileAttributeType *type,
727 GFileAttributeStatus *status)
729 GFileAttributeValue *value;
731 value = g_file_info_find_value_by_name (info, attribute);
736 *status = value->status;
742 *value_pp = _g_file_attribute_value_peek_as_pointer (value);
748 * g_file_info_get_attribute_status:
749 * @info: a #GFileInfo
750 * @attribute: a file attribute key
752 * Gets the attribute status for an attribute key.
754 * Returns: a #GFileAttributeStatus for the given @attribute, or
755 * %G_FILE_ATTRIBUTE_STATUS_UNSET if the key is invalid.
759 g_file_info_get_attribute_status (GFileInfo *info,
760 const char *attribute)
762 GFileAttributeValue *val;
764 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
765 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
767 val = g_file_info_find_value_by_name (info, attribute);
771 return G_FILE_ATTRIBUTE_STATUS_UNSET;
775 * g_file_info_set_attribute_status:
776 * @info: a #GFileInfo
777 * @attribute: a file attribute key
778 * @status: a #GFileAttributeStatus
780 * Sets the attribute status for an attribute key. This is only
781 * needed by external code that implement g_file_set_attributes_from_info()
782 * or similar functions.
784 * The attribute must exist in @info for this to work. Otherwise %FALSE
785 * is returned and @info is unchanged.
787 * Returns: %TRUE if the status was changed, %FALSE if the key was not set.
792 g_file_info_set_attribute_status (GFileInfo *info,
793 const char *attribute,
794 GFileAttributeStatus status)
796 GFileAttributeValue *val;
798 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
799 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
801 val = g_file_info_find_value_by_name (info, attribute);
804 val->status = status;
811 GFileAttributeValue *
812 _g_file_info_get_attribute_value (GFileInfo *info,
813 const char *attribute)
816 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
817 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
819 return g_file_info_find_value_by_name (info, attribute);
823 * g_file_info_get_attribute_as_string:
824 * @info: a #GFileInfo.
825 * @attribute: a file attribute key.
827 * Gets the value of a attribute, formated as a string.
828 * This escapes things as needed to make the string valid
831 * Returns: a UTF-8 string associated with the given @attribute.
832 * When you're done with the string it must be freed with g_free().
835 g_file_info_get_attribute_as_string (GFileInfo *info,
836 const char *attribute)
838 GFileAttributeValue *val;
839 val = _g_file_info_get_attribute_value (info, attribute);
841 return _g_file_attribute_value_as_string (val);
847 * g_file_info_get_attribute_object:
848 * @info: a #GFileInfo.
849 * @attribute: a file attribute key.
851 * Gets the value of a #GObject attribute. If the attribute does
852 * not contain a #GObject, %NULL will be returned.
854 * Returns: (transfer none): a #GObject associated with the given @attribute, or
858 g_file_info_get_attribute_object (GFileInfo *info,
859 const char *attribute)
861 GFileAttributeValue *value;
863 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
864 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
866 value = g_file_info_find_value_by_name (info, attribute);
867 return _g_file_attribute_value_get_object (value);
871 * g_file_info_get_attribute_string:
872 * @info: a #GFileInfo.
873 * @attribute: a file attribute key.
875 * Gets the value of a string attribute. If the attribute does
876 * not contain a string, %NULL will be returned.
878 * Returns: the contents of the @attribute value as a UTF-8 string, or
882 g_file_info_get_attribute_string (GFileInfo *info,
883 const char *attribute)
885 GFileAttributeValue *value;
887 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
888 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
890 value = g_file_info_find_value_by_name (info, attribute);
891 return _g_file_attribute_value_get_string (value);
895 * g_file_info_get_attribute_byte_string:
896 * @info: a #GFileInfo.
897 * @attribute: a file attribute key.
899 * Gets the value of a byte string attribute. If the attribute does
900 * not contain a byte string, %NULL will be returned.
902 * Returns: the contents of the @attribute value as a byte string, or
906 g_file_info_get_attribute_byte_string (GFileInfo *info,
907 const char *attribute)
909 GFileAttributeValue *value;
911 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
912 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
914 value = g_file_info_find_value_by_name (info, attribute);
915 return _g_file_attribute_value_get_byte_string (value);
919 * g_file_info_get_attribute_stringv:
920 * @info: a #GFileInfo.
921 * @attribute: a file attribute key.
923 * Gets the value of a stringv attribute. If the attribute does
924 * not contain a stringv, %NULL will be returned.
926 * Returns: (transfer none): the contents of the @attribute value as a stringv, or
927 * %NULL otherwise. Do not free. These returned strings are UTF-8.
932 g_file_info_get_attribute_stringv (GFileInfo *info,
933 const char *attribute)
935 GFileAttributeValue *value;
937 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
938 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
940 value = g_file_info_find_value_by_name (info, attribute);
941 return _g_file_attribute_value_get_stringv (value);
945 * g_file_info_get_attribute_boolean:
946 * @info: a #GFileInfo.
947 * @attribute: a file attribute key.
949 * Gets the value of a boolean attribute. If the attribute does not
950 * contain a boolean value, %FALSE will be returned.
952 * Returns: the boolean value contained within the attribute.
955 g_file_info_get_attribute_boolean (GFileInfo *info,
956 const char *attribute)
958 GFileAttributeValue *value;
960 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
961 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
963 value = g_file_info_find_value_by_name (info, attribute);
964 return _g_file_attribute_value_get_boolean (value);
968 * g_file_info_get_attribute_uint32:
969 * @info: a #GFileInfo.
970 * @attribute: a file attribute key.
972 * Gets an unsigned 32-bit integer contained within the attribute. If the
973 * attribute does not contain an unsigned 32-bit integer, or is invalid,
974 * 0 will be returned.
976 * Returns: an unsigned 32-bit integer from the attribute.
979 g_file_info_get_attribute_uint32 (GFileInfo *info,
980 const char *attribute)
982 GFileAttributeValue *value;
984 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
985 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
987 value = g_file_info_find_value_by_name (info, attribute);
988 return _g_file_attribute_value_get_uint32 (value);
992 * g_file_info_get_attribute_int32:
993 * @info: a #GFileInfo.
994 * @attribute: a file attribute key.
996 * Gets a signed 32-bit integer contained within the attribute. If the
997 * attribute does not contain a signed 32-bit integer, or is invalid,
998 * 0 will be returned.
1000 * Returns: a signed 32-bit integer from the attribute.
1003 g_file_info_get_attribute_int32 (GFileInfo *info,
1004 const char *attribute)
1006 GFileAttributeValue *value;
1008 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1009 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
1011 value = g_file_info_find_value_by_name (info, attribute);
1012 return _g_file_attribute_value_get_int32 (value);
1016 * g_file_info_get_attribute_uint64:
1017 * @info: a #GFileInfo.
1018 * @attribute: a file attribute key.
1020 * Gets a unsigned 64-bit integer contained within the attribute. If the
1021 * attribute does not contain an unsigned 64-bit integer, or is invalid,
1022 * 0 will be returned.
1024 * Returns: a unsigned 64-bit integer from the attribute.
1027 g_file_info_get_attribute_uint64 (GFileInfo *info,
1028 const char *attribute)
1030 GFileAttributeValue *value;
1032 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1033 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
1035 value = g_file_info_find_value_by_name (info, attribute);
1036 return _g_file_attribute_value_get_uint64 (value);
1040 * g_file_info_get_attribute_int64:
1041 * @info: a #GFileInfo.
1042 * @attribute: a file attribute key.
1044 * Gets a signed 64-bit integer contained within the attribute. If the
1045 * attribute does not contain an signed 64-bit integer, or is invalid,
1046 * 0 will be returned.
1048 * Returns: a signed 64-bit integer from the attribute.
1051 g_file_info_get_attribute_int64 (GFileInfo *info,
1052 const char *attribute)
1054 GFileAttributeValue *value;
1056 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1057 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
1059 value = g_file_info_find_value_by_name (info, attribute);
1060 return _g_file_attribute_value_get_int64 (value);
1063 static GFileAttributeValue *
1064 g_file_info_create_value (GFileInfo *info,
1067 GFileAttribute *attrs;
1070 if (info->mask != NO_ATTRIBUTE_MASK &&
1071 !_g_file_attribute_matcher_matches_id (info->mask, attr_id))
1074 i = g_file_info_find_place (info, attr_id);
1076 attrs = (GFileAttribute *)info->attributes->data;
1077 if (i < info->attributes->len &&
1078 attrs[i].attribute == attr_id)
1079 return &attrs[i].value;
1082 GFileAttribute attr = { 0 };
1083 attr.attribute = attr_id;
1084 g_array_insert_val (info->attributes, i, attr);
1086 attrs = (GFileAttribute *)info->attributes->data;
1087 return &attrs[i].value;
1092 _g_file_info_set_attribute_by_id (GFileInfo *info,
1094 GFileAttributeType type,
1097 GFileAttributeValue *value;
1099 value = g_file_info_create_value (info, attribute);
1102 _g_file_attribute_value_set_from_pointer (value, type, value_p, TRUE);
1106 * g_file_info_set_attribute:
1107 * @info: a #GFileInfo.
1108 * @attribute: a file attribute key.
1109 * @type: a #GFileAttributeType
1110 * @value_p: pointer to the value
1112 * Sets the @attribute to contain the given value, if possible. To unset the
1113 * attribute, use %G_ATTRIBUTE_TYPE_INVALID for @type.
1116 g_file_info_set_attribute (GFileInfo *info,
1117 const char *attribute,
1118 GFileAttributeType type,
1121 g_return_if_fail (G_IS_FILE_INFO (info));
1122 g_return_if_fail (attribute != NULL && *attribute != '\0');
1124 _g_file_info_set_attribute_by_id (info, lookup_attribute (attribute), type, value_p);
1128 _g_file_info_set_attribute_object_by_id (GFileInfo *info,
1130 GObject *attr_value)
1132 GFileAttributeValue *value;
1134 value = g_file_info_create_value (info, attribute);
1136 _g_file_attribute_value_set_object (value, attr_value);
1140 * g_file_info_set_attribute_object:
1141 * @info: a #GFileInfo.
1142 * @attribute: a file attribute key.
1143 * @attr_value: a #GObject.
1145 * Sets the @attribute to contain the given @attr_value,
1149 g_file_info_set_attribute_object (GFileInfo *info,
1150 const char *attribute,
1151 GObject *attr_value)
1153 g_return_if_fail (G_IS_FILE_INFO (info));
1154 g_return_if_fail (attribute != NULL && *attribute != '\0');
1155 g_return_if_fail (G_IS_OBJECT (attr_value));
1157 _g_file_info_set_attribute_object_by_id (info,
1158 lookup_attribute (attribute),
1163 _g_file_info_set_attribute_stringv_by_id (GFileInfo *info,
1167 GFileAttributeValue *value;
1169 value = g_file_info_create_value (info, attribute);
1171 _g_file_attribute_value_set_stringv (value, attr_value);
1175 * g_file_info_set_attribute_stringv:
1176 * @info: a #GFileInfo.
1177 * @attribute: a file attribute key
1178 * @attr_value: (array) (element-type utf8): a %NULL terminated array of UTF-8 strings.
1180 * Sets the @attribute to contain the given @attr_value,
1186 g_file_info_set_attribute_stringv (GFileInfo *info,
1187 const char *attribute,
1190 g_return_if_fail (G_IS_FILE_INFO (info));
1191 g_return_if_fail (attribute != NULL && *attribute != '\0');
1192 g_return_if_fail (attr_value != NULL);
1194 _g_file_info_set_attribute_stringv_by_id (info,
1195 lookup_attribute (attribute),
1200 _g_file_info_set_attribute_string_by_id (GFileInfo *info,
1202 const char *attr_value)
1204 GFileAttributeValue *value;
1206 value = g_file_info_create_value (info, attribute);
1208 _g_file_attribute_value_set_string (value, attr_value);
1212 * g_file_info_set_attribute_string:
1213 * @info: a #GFileInfo.
1214 * @attribute: a file attribute key.
1215 * @attr_value: a UTF-8 string.
1217 * Sets the @attribute to contain the given @attr_value,
1221 g_file_info_set_attribute_string (GFileInfo *info,
1222 const char *attribute,
1223 const char *attr_value)
1225 g_return_if_fail (G_IS_FILE_INFO (info));
1226 g_return_if_fail (attribute != NULL && *attribute != '\0');
1227 g_return_if_fail (attr_value != NULL);
1229 _g_file_info_set_attribute_string_by_id (info,
1230 lookup_attribute (attribute),
1235 _g_file_info_set_attribute_byte_string_by_id (GFileInfo *info,
1237 const char *attr_value)
1239 GFileAttributeValue *value;
1241 value = g_file_info_create_value (info, attribute);
1243 _g_file_attribute_value_set_byte_string (value, attr_value);
1247 * g_file_info_set_attribute_byte_string:
1248 * @info: a #GFileInfo.
1249 * @attribute: a file attribute key.
1250 * @attr_value: a byte string.
1252 * Sets the @attribute to contain the given @attr_value,
1256 g_file_info_set_attribute_byte_string (GFileInfo *info,
1257 const char *attribute,
1258 const char *attr_value)
1260 g_return_if_fail (G_IS_FILE_INFO (info));
1261 g_return_if_fail (attribute != NULL && *attribute != '\0');
1262 g_return_if_fail (attr_value != NULL);
1264 _g_file_info_set_attribute_byte_string_by_id (info,
1265 lookup_attribute (attribute),
1270 _g_file_info_set_attribute_boolean_by_id (GFileInfo *info,
1272 gboolean attr_value)
1274 GFileAttributeValue *value;
1276 value = g_file_info_create_value (info, attribute);
1278 _g_file_attribute_value_set_boolean (value, attr_value);
1282 * g_file_info_set_attribute_boolean:
1283 * @info: a #GFileInfo.
1284 * @attribute: a file attribute key.
1285 * @attr_value: a boolean value.
1287 * Sets the @attribute to contain the given @attr_value,
1291 g_file_info_set_attribute_boolean (GFileInfo *info,
1292 const char *attribute,
1293 gboolean attr_value)
1295 g_return_if_fail (G_IS_FILE_INFO (info));
1296 g_return_if_fail (attribute != NULL && *attribute != '\0');
1298 _g_file_info_set_attribute_boolean_by_id (info,
1299 lookup_attribute (attribute),
1304 _g_file_info_set_attribute_uint32_by_id (GFileInfo *info,
1308 GFileAttributeValue *value;
1310 value = g_file_info_create_value (info, attribute);
1312 _g_file_attribute_value_set_uint32 (value, attr_value);
1316 * g_file_info_set_attribute_uint32:
1317 * @info: a #GFileInfo.
1318 * @attribute: a file attribute key.
1319 * @attr_value: an unsigned 32-bit integer.
1321 * Sets the @attribute to contain the given @attr_value,
1325 g_file_info_set_attribute_uint32 (GFileInfo *info,
1326 const char *attribute,
1329 g_return_if_fail (G_IS_FILE_INFO (info));
1330 g_return_if_fail (attribute != NULL && *attribute != '\0');
1332 _g_file_info_set_attribute_uint32_by_id (info,
1333 lookup_attribute (attribute),
1338 _g_file_info_set_attribute_int32_by_id (GFileInfo *info,
1342 GFileAttributeValue *value;
1344 value = g_file_info_create_value (info, attribute);
1346 _g_file_attribute_value_set_int32 (value, attr_value);
1350 * g_file_info_set_attribute_int32:
1351 * @info: a #GFileInfo.
1352 * @attribute: a file attribute key.
1353 * @attr_value: a signed 32-bit integer
1355 * Sets the @attribute to contain the given @attr_value,
1359 g_file_info_set_attribute_int32 (GFileInfo *info,
1360 const char *attribute,
1363 g_return_if_fail (G_IS_FILE_INFO (info));
1364 g_return_if_fail (attribute != NULL && *attribute != '\0');
1366 _g_file_info_set_attribute_int32_by_id (info,
1367 lookup_attribute (attribute),
1372 _g_file_info_set_attribute_uint64_by_id (GFileInfo *info,
1376 GFileAttributeValue *value;
1378 value = g_file_info_create_value (info, attribute);
1380 _g_file_attribute_value_set_uint64 (value, attr_value);
1384 * g_file_info_set_attribute_uint64:
1385 * @info: a #GFileInfo.
1386 * @attribute: a file attribute key.
1387 * @attr_value: an unsigned 64-bit integer.
1389 * Sets the @attribute to contain the given @attr_value,
1393 g_file_info_set_attribute_uint64 (GFileInfo *info,
1394 const char *attribute,
1397 g_return_if_fail (G_IS_FILE_INFO (info));
1398 g_return_if_fail (attribute != NULL && *attribute != '\0');
1400 _g_file_info_set_attribute_uint64_by_id (info,
1401 lookup_attribute (attribute),
1406 _g_file_info_set_attribute_int64_by_id (GFileInfo *info,
1410 GFileAttributeValue *value;
1412 value = g_file_info_create_value (info, attribute);
1414 _g_file_attribute_value_set_int64 (value, attr_value);
1418 * g_file_info_set_attribute_int64:
1419 * @info: a #GFileInfo.
1420 * @attribute: attribute name to set.
1421 * @attr_value: int64 value to set attribute to.
1423 * Sets the @attribute to contain the given @attr_value,
1428 g_file_info_set_attribute_int64 (GFileInfo *info,
1429 const char *attribute,
1432 g_return_if_fail (G_IS_FILE_INFO (info));
1433 g_return_if_fail (attribute != NULL && *attribute != '\0');
1435 _g_file_info_set_attribute_int64_by_id (info,
1436 lookup_attribute (attribute),
1440 /* Helper getters */
1442 * g_file_info_get_deletion_date:
1443 * @info: a #GFileInfo.
1445 * Returns the #GDateTime representing the deletion date of the file, as
1446 * available in G_FILE_ATTRIBUTE_TRASH_DELETION_DATE. If the
1447 * G_FILE_ATTRIBUTE_TRASH_DELETION_DATE attribute is unset, %NULL is returned.
1449 * Returns: a #GDateTime, or %NULL.
1454 g_file_info_get_deletion_date (GFileInfo *info)
1456 static guint32 attr = 0;
1457 GFileAttributeValue *value;
1458 const char *date_str;
1461 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1464 attr = lookup_attribute (G_FILE_ATTRIBUTE_TRASH_DELETION_DATE);
1466 value = g_file_info_find_value (info, attr);
1467 date_str = _g_file_attribute_value_get_string (value);
1471 if (g_time_val_from_iso8601 (date_str, &tv) == FALSE)
1474 return g_date_time_new_from_timeval_local (&tv);
1478 * g_file_info_get_file_type:
1479 * @info: a #GFileInfo.
1481 * Gets a file's type (whether it is a regular file, symlink, etc).
1482 * This is different from the file's content type, see g_file_info_get_content_type().
1484 * Returns: a #GFileType for the given file.
1487 g_file_info_get_file_type (GFileInfo *info)
1489 static guint32 attr = 0;
1490 GFileAttributeValue *value;
1492 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_TYPE_UNKNOWN);
1495 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
1497 value = g_file_info_find_value (info, attr);
1498 return (GFileType)_g_file_attribute_value_get_uint32 (value);
1502 * g_file_info_get_is_hidden:
1503 * @info: a #GFileInfo.
1505 * Checks if a file is hidden.
1507 * Returns: %TRUE if the file is a hidden file, %FALSE otherwise.
1510 g_file_info_get_is_hidden (GFileInfo *info)
1512 static guint32 attr = 0;
1513 GFileAttributeValue *value;
1515 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1518 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
1520 value = g_file_info_find_value (info, attr);
1521 return (GFileType)_g_file_attribute_value_get_boolean (value);
1525 * g_file_info_get_is_backup:
1526 * @info: a #GFileInfo.
1528 * Checks if a file is a backup file.
1530 * Returns: %TRUE if file is a backup file, %FALSE otherwise.
1533 g_file_info_get_is_backup (GFileInfo *info)
1535 static guint32 attr = 0;
1536 GFileAttributeValue *value;
1538 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1541 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
1543 value = g_file_info_find_value (info, attr);
1544 return (GFileType)_g_file_attribute_value_get_boolean (value);
1548 * g_file_info_get_is_symlink:
1549 * @info: a #GFileInfo.
1551 * Checks if a file is a symlink.
1553 * Returns: %TRUE if the given @info is a symlink.
1556 g_file_info_get_is_symlink (GFileInfo *info)
1558 static guint32 attr = 0;
1559 GFileAttributeValue *value;
1561 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1564 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
1566 value = g_file_info_find_value (info, attr);
1567 return (GFileType)_g_file_attribute_value_get_boolean (value);
1571 * g_file_info_get_name:
1572 * @info: a #GFileInfo.
1574 * Gets the name for a file.
1576 * Returns: a string containing the file name.
1579 g_file_info_get_name (GFileInfo *info)
1581 static guint32 attr = 0;
1582 GFileAttributeValue *value;
1584 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1587 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
1589 value = g_file_info_find_value (info, attr);
1590 return _g_file_attribute_value_get_byte_string (value);
1594 * g_file_info_get_display_name:
1595 * @info: a #GFileInfo.
1597 * Gets a display name for a file.
1599 * Returns: a string containing the display name.
1602 g_file_info_get_display_name (GFileInfo *info)
1604 static guint32 attr = 0;
1605 GFileAttributeValue *value;
1607 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1610 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
1612 value = g_file_info_find_value (info, attr);
1613 return _g_file_attribute_value_get_string (value);
1617 * g_file_info_get_edit_name:
1618 * @info: a #GFileInfo.
1620 * Gets the edit name for a file.
1622 * Returns: a string containing the edit name.
1625 g_file_info_get_edit_name (GFileInfo *info)
1627 static guint32 attr = 0;
1628 GFileAttributeValue *value;
1630 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1633 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
1635 value = g_file_info_find_value (info, attr);
1636 return _g_file_attribute_value_get_string (value);
1640 * g_file_info_get_icon:
1641 * @info: a #GFileInfo.
1643 * Gets the icon for a file.
1645 * Returns: (transfer none): #GIcon for the given @info.
1648 g_file_info_get_icon (GFileInfo *info)
1650 static guint32 attr = 0;
1651 GFileAttributeValue *value;
1654 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1657 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
1659 value = g_file_info_find_value (info, attr);
1660 obj = _g_file_attribute_value_get_object (value);
1661 if (G_IS_ICON (obj))
1662 return G_ICON (obj);
1667 * g_file_info_get_symbolic_icon:
1668 * @info: a #GFileInfo.
1670 * Gets the symbolic icon for a file.
1672 * Returns: (transfer none): #GIcon for the given @info.
1677 g_file_info_get_symbolic_icon (GFileInfo *info)
1679 static guint32 attr = 0;
1680 GFileAttributeValue *value;
1683 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1686 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON);
1688 value = g_file_info_find_value (info, attr);
1689 obj = _g_file_attribute_value_get_object (value);
1690 if (G_IS_ICON (obj))
1691 return G_ICON (obj);
1696 * g_file_info_get_content_type:
1697 * @info: a #GFileInfo.
1699 * Gets the file's content type.
1701 * Returns: a string containing the file's content type.
1704 g_file_info_get_content_type (GFileInfo *info)
1706 static guint32 attr = 0;
1707 GFileAttributeValue *value;
1709 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1712 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1714 value = g_file_info_find_value (info, attr);
1715 return _g_file_attribute_value_get_string (value);
1719 * g_file_info_get_size:
1720 * @info: a #GFileInfo.
1722 * Gets the file's size.
1724 * Returns: a #goffset containing the file's size.
1727 g_file_info_get_size (GFileInfo *info)
1729 static guint32 attr = 0;
1730 GFileAttributeValue *value;
1732 g_return_val_if_fail (G_IS_FILE_INFO (info), (goffset) 0);
1735 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
1737 value = g_file_info_find_value (info, attr);
1738 return (goffset) _g_file_attribute_value_get_uint64 (value);
1742 * g_file_info_get_modification_time:
1743 * @info: a #GFileInfo.
1744 * @result: (out caller-allocates): a #GTimeVal.
1746 * Gets the modification time of the current @info and sets it
1750 g_file_info_get_modification_time (GFileInfo *info,
1753 static guint32 attr_mtime = 0, attr_mtime_usec;
1754 GFileAttributeValue *value;
1756 g_return_if_fail (G_IS_FILE_INFO (info));
1757 g_return_if_fail (result != NULL);
1759 if (attr_mtime == 0)
1761 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1762 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1765 value = g_file_info_find_value (info, attr_mtime);
1766 result->tv_sec = _g_file_attribute_value_get_uint64 (value);
1767 value = g_file_info_find_value (info, attr_mtime_usec);
1768 result->tv_usec = _g_file_attribute_value_get_uint32 (value);
1772 * g_file_info_get_symlink_target:
1773 * @info: a #GFileInfo.
1775 * Gets the symlink target for a given #GFileInfo.
1777 * Returns: a string containing the symlink target.
1780 g_file_info_get_symlink_target (GFileInfo *info)
1782 static guint32 attr = 0;
1783 GFileAttributeValue *value;
1785 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1788 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
1790 value = g_file_info_find_value (info, attr);
1791 return _g_file_attribute_value_get_byte_string (value);
1795 * g_file_info_get_etag:
1796 * @info: a #GFileInfo.
1798 * Gets the [entity tag][gfile-etag] for a given
1799 * #GFileInfo. See %G_FILE_ATTRIBUTE_ETAG_VALUE.
1801 * Returns: a string containing the value of the "etag:value" attribute.
1804 g_file_info_get_etag (GFileInfo *info)
1806 static guint32 attr = 0;
1807 GFileAttributeValue *value;
1809 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1812 attr = lookup_attribute (G_FILE_ATTRIBUTE_ETAG_VALUE);
1814 value = g_file_info_find_value (info, attr);
1815 return _g_file_attribute_value_get_string (value);
1819 * g_file_info_get_sort_order:
1820 * @info: a #GFileInfo.
1822 * Gets the value of the sort_order attribute from the #GFileInfo.
1823 * See %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
1825 * Returns: a #gint32 containing the value of the "standard::sort_order" attribute.
1828 g_file_info_get_sort_order (GFileInfo *info)
1830 static guint32 attr = 0;
1831 GFileAttributeValue *value;
1833 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1836 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
1838 value = g_file_info_find_value (info, attr);
1839 return _g_file_attribute_value_get_int32 (value);
1842 /* Helper setters: */
1844 * g_file_info_set_file_type:
1845 * @info: a #GFileInfo.
1846 * @type: a #GFileType.
1848 * Sets the file type in a #GFileInfo to @type.
1849 * See %G_FILE_ATTRIBUTE_STANDARD_TYPE.
1852 g_file_info_set_file_type (GFileInfo *info,
1855 static guint32 attr = 0;
1856 GFileAttributeValue *value;
1858 g_return_if_fail (G_IS_FILE_INFO (info));
1861 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
1863 value = g_file_info_create_value (info, attr);
1865 _g_file_attribute_value_set_uint32 (value, type);
1869 * g_file_info_set_is_hidden:
1870 * @info: a #GFileInfo.
1871 * @is_hidden: a #gboolean.
1873 * Sets the "is_hidden" attribute in a #GFileInfo according to @is_hidden.
1874 * See %G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN.
1877 g_file_info_set_is_hidden (GFileInfo *info,
1880 static guint32 attr = 0;
1881 GFileAttributeValue *value;
1883 g_return_if_fail (G_IS_FILE_INFO (info));
1886 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
1888 value = g_file_info_create_value (info, attr);
1890 _g_file_attribute_value_set_boolean (value, is_hidden);
1894 * g_file_info_set_is_symlink:
1895 * @info: a #GFileInfo.
1896 * @is_symlink: a #gboolean.
1898 * Sets the "is_symlink" attribute in a #GFileInfo according to @is_symlink.
1899 * See %G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK.
1902 g_file_info_set_is_symlink (GFileInfo *info,
1903 gboolean is_symlink)
1905 static guint32 attr = 0;
1906 GFileAttributeValue *value;
1908 g_return_if_fail (G_IS_FILE_INFO (info));
1911 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
1913 value = g_file_info_create_value (info, attr);
1915 _g_file_attribute_value_set_boolean (value, is_symlink);
1919 * g_file_info_set_name:
1920 * @info: a #GFileInfo.
1921 * @name: a string containing a name.
1923 * Sets the name attribute for the current #GFileInfo.
1924 * See %G_FILE_ATTRIBUTE_STANDARD_NAME.
1927 g_file_info_set_name (GFileInfo *info,
1930 static guint32 attr = 0;
1931 GFileAttributeValue *value;
1933 g_return_if_fail (G_IS_FILE_INFO (info));
1934 g_return_if_fail (name != NULL);
1937 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
1939 value = g_file_info_create_value (info, attr);
1941 _g_file_attribute_value_set_byte_string (value, name);
1945 * g_file_info_set_display_name:
1946 * @info: a #GFileInfo.
1947 * @display_name: a string containing a display name.
1949 * Sets the display name for the current #GFileInfo.
1950 * See %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.
1953 g_file_info_set_display_name (GFileInfo *info,
1954 const char *display_name)
1956 static guint32 attr = 0;
1957 GFileAttributeValue *value;
1959 g_return_if_fail (G_IS_FILE_INFO (info));
1960 g_return_if_fail (display_name != NULL);
1963 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
1965 value = g_file_info_create_value (info, attr);
1967 _g_file_attribute_value_set_string (value, display_name);
1971 * g_file_info_set_edit_name:
1972 * @info: a #GFileInfo.
1973 * @edit_name: a string containing an edit name.
1975 * Sets the edit name for the current file.
1976 * See %G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME.
1979 g_file_info_set_edit_name (GFileInfo *info,
1980 const char *edit_name)
1982 static guint32 attr = 0;
1983 GFileAttributeValue *value;
1985 g_return_if_fail (G_IS_FILE_INFO (info));
1986 g_return_if_fail (edit_name != NULL);
1989 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
1991 value = g_file_info_create_value (info, attr);
1993 _g_file_attribute_value_set_string (value, edit_name);
1997 * g_file_info_set_icon:
1998 * @info: a #GFileInfo.
2001 * Sets the icon for a given #GFileInfo.
2002 * See %G_FILE_ATTRIBUTE_STANDARD_ICON.
2005 g_file_info_set_icon (GFileInfo *info,
2008 static guint32 attr = 0;
2009 GFileAttributeValue *value;
2011 g_return_if_fail (G_IS_FILE_INFO (info));
2012 g_return_if_fail (G_IS_ICON (icon));
2015 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
2017 value = g_file_info_create_value (info, attr);
2019 _g_file_attribute_value_set_object (value, G_OBJECT (icon));
2023 * g_file_info_set_symbolic_icon:
2024 * @info: a #GFileInfo.
2027 * Sets the symbolic icon for a given #GFileInfo.
2028 * See %G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON.
2033 g_file_info_set_symbolic_icon (GFileInfo *info,
2036 static guint32 attr = 0;
2037 GFileAttributeValue *value;
2039 g_return_if_fail (G_IS_FILE_INFO (info));
2040 g_return_if_fail (G_IS_ICON (icon));
2043 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON);
2045 value = g_file_info_create_value (info, attr);
2047 _g_file_attribute_value_set_object (value, G_OBJECT (icon));
2051 * g_file_info_set_content_type:
2052 * @info: a #GFileInfo.
2053 * @content_type: a content type. See [GContentType][gio-GContentType]
2055 * Sets the content type attribute for a given #GFileInfo.
2056 * See %G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE.
2059 g_file_info_set_content_type (GFileInfo *info,
2060 const char *content_type)
2062 static guint32 attr = 0;
2063 GFileAttributeValue *value;
2065 g_return_if_fail (G_IS_FILE_INFO (info));
2066 g_return_if_fail (content_type != NULL);
2069 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
2071 value = g_file_info_create_value (info, attr);
2073 _g_file_attribute_value_set_string (value, content_type);
2077 * g_file_info_set_size:
2078 * @info: a #GFileInfo.
2079 * @size: a #goffset containing the file's size.
2081 * Sets the %G_FILE_ATTRIBUTE_STANDARD_SIZE attribute in the file info
2082 * to the given size.
2085 g_file_info_set_size (GFileInfo *info,
2088 static guint32 attr = 0;
2089 GFileAttributeValue *value;
2091 g_return_if_fail (G_IS_FILE_INFO (info));
2094 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
2096 value = g_file_info_create_value (info, attr);
2098 _g_file_attribute_value_set_uint64 (value, size);
2102 * g_file_info_set_modification_time:
2103 * @info: a #GFileInfo.
2104 * @mtime: a #GTimeVal.
2106 * Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute in the file
2107 * info to the given time value.
2110 g_file_info_set_modification_time (GFileInfo *info,
2113 static guint32 attr_mtime = 0, attr_mtime_usec;
2114 GFileAttributeValue *value;
2116 g_return_if_fail (G_IS_FILE_INFO (info));
2117 g_return_if_fail (mtime != NULL);
2119 if (attr_mtime == 0)
2121 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
2122 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
2125 value = g_file_info_create_value (info, attr_mtime);
2127 _g_file_attribute_value_set_uint64 (value, mtime->tv_sec);
2128 value = g_file_info_create_value (info, attr_mtime_usec);
2130 _g_file_attribute_value_set_uint32 (value, mtime->tv_usec);
2134 * g_file_info_set_symlink_target:
2135 * @info: a #GFileInfo.
2136 * @symlink_target: a static string containing a path to a symlink target.
2138 * Sets the %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET attribute in the file info
2139 * to the given symlink target.
2142 g_file_info_set_symlink_target (GFileInfo *info,
2143 const char *symlink_target)
2145 static guint32 attr = 0;
2146 GFileAttributeValue *value;
2148 g_return_if_fail (G_IS_FILE_INFO (info));
2149 g_return_if_fail (symlink_target != NULL);
2152 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
2154 value = g_file_info_create_value (info, attr);
2156 _g_file_attribute_value_set_byte_string (value, symlink_target);
2160 * g_file_info_set_sort_order:
2161 * @info: a #GFileInfo.
2162 * @sort_order: a sort order integer.
2164 * Sets the sort order attribute in the file info structure. See
2165 * %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
2168 g_file_info_set_sort_order (GFileInfo *info,
2171 static guint32 attr = 0;
2172 GFileAttributeValue *value;
2174 g_return_if_fail (G_IS_FILE_INFO (info));
2177 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
2179 value = g_file_info_create_value (info, attr);
2181 _g_file_attribute_value_set_int32 (value, sort_order);
2190 struct _GFileAttributeMatcher {
2194 GArray *sub_matchers;
2197 guint32 iterator_ns;
2201 G_DEFINE_BOXED_TYPE (GFileAttributeMatcher, g_file_attribute_matcher,
2202 g_file_attribute_matcher_ref,
2203 g_file_attribute_matcher_unref)
2206 compare_sub_matchers (gconstpointer a,
2209 const SubMatcher *suba = a;
2210 const SubMatcher *subb = b;
2213 diff = suba->id - subb->id;
2218 return suba->mask - subb->mask;
2222 sub_matcher_matches (SubMatcher *matcher,
2223 SubMatcher *submatcher)
2225 if ((matcher->mask & submatcher->mask) != matcher->mask)
2228 return matcher->id == (submatcher->id & matcher->mask);
2231 /* Call this function after modifying a matcher.
2232 * It will ensure all the invariants other functions rely on.
2234 static GFileAttributeMatcher *
2235 matcher_optimize (GFileAttributeMatcher *matcher)
2237 SubMatcher *submatcher, *compare;
2240 /* remove sub_matchers if we match everything anyway */
2243 if (matcher->sub_matchers)
2245 g_array_free (matcher->sub_matchers, TRUE);
2246 matcher->sub_matchers = NULL;
2251 if (matcher->sub_matchers->len == 0)
2253 g_file_attribute_matcher_unref (matcher);
2257 /* sort sub_matchers by id (and then mask), so we can bsearch
2258 * and compare matchers in O(N) instead of O(N²) */
2259 g_array_sort (matcher->sub_matchers, compare_sub_matchers);
2261 /* remove duplicates and specific matches when we match the whole namespace */
2263 compare = &g_array_index (matcher->sub_matchers, SubMatcher, j);
2265 for (i = 1; i < matcher->sub_matchers->len; i++)
2267 submatcher = &g_array_index (matcher->sub_matchers, SubMatcher, i);
2268 if (sub_matcher_matches (compare, submatcher))
2275 *compare = *submatcher;
2278 g_array_set_size (matcher->sub_matchers, j + 1);
2284 * g_file_attribute_matcher_new:
2285 * @attributes: an attribute string to match.
2287 * Creates a new file attribute matcher, which matches attributes
2288 * against a given string. #GFileAttributeMatchers are reference
2289 * counted structures, and are created with a reference count of 1. If
2290 * the number of references falls to 0, the #GFileAttributeMatcher is
2291 * automatically destroyed.
2293 * The @attribute string should be formatted with specific keys separated
2294 * from namespaces with a double colon. Several "namespace::key" strings may be
2295 * concatenated with a single comma (e.g. "standard::type,standard::is-hidden").
2296 * The wildcard "*" may be used to match all keys and namespaces, or
2297 * "namespace::*" will match all keys in a given namespace.
2299 * ## Examples of file attribute matcher strings and results
2301 * - `"*"`: matches all attributes.
2302 * - `"standard::is-hidden"`: matches only the key is-hidden in the
2303 * standard namespace.
2304 * - `"standard::type,unix::*"`: matches the type key in the standard
2305 * namespace and all keys in the unix namespace.
2307 * Returns: a #GFileAttributeMatcher
2309 GFileAttributeMatcher *
2310 g_file_attribute_matcher_new (const char *attributes)
2315 GFileAttributeMatcher *matcher;
2317 if (attributes == NULL || *attributes == '\0')
2320 matcher = g_malloc0 (sizeof (GFileAttributeMatcher));
2322 matcher->sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
2324 split = g_strsplit (attributes, ",", -1);
2326 for (i = 0; split[i] != NULL; i++)
2328 if (strcmp (split[i], "*") == 0)
2329 matcher->all = TRUE;
2334 colon = strstr (split[i], "::");
2335 if (colon != NULL &&
2340 s.id = lookup_attribute (split[i]);
2341 s.mask = 0xffffffff;
2348 s.id = lookup_namespace (split[i]) << NS_POS;
2349 s.mask = NS_MASK << NS_POS;
2352 g_array_append_val (matcher->sub_matchers, s);
2358 matcher = matcher_optimize (matcher);
2364 * g_file_attribute_matcher_subtract:
2365 * @matcher: Matcher to subtract from
2366 * @subtract: The matcher to subtract
2368 * Subtracts all attributes of @subtract from @matcher and returns
2369 * a matcher that supports those attributes.
2371 * Note that currently it is not possible to remove a single
2372 * attribute when the @matcher matches the whole namespace - or remove
2373 * a namespace or attribute when the matcher matches everything. This
2374 * is a limitation of the current implementation, but may be fixed
2377 * Returns: A file attribute matcher matching all attributes of
2378 * @matcher that are not matched by @subtract
2380 GFileAttributeMatcher *
2381 g_file_attribute_matcher_subtract (GFileAttributeMatcher *matcher,
2382 GFileAttributeMatcher *subtract)
2384 GFileAttributeMatcher *result;
2386 SubMatcher *msub, *ssub;
2388 if (matcher == NULL)
2390 if (subtract == NULL)
2391 return g_file_attribute_matcher_ref (matcher);
2395 return g_file_attribute_matcher_ref (matcher);
2397 result = g_malloc0 (sizeof (GFileAttributeMatcher));
2399 result->sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
2402 g_assert (subtract->sub_matchers->len > 0);
2403 ssub = &g_array_index (subtract->sub_matchers, SubMatcher, si);
2405 for (mi = 0; mi < matcher->sub_matchers->len; mi++)
2407 msub = &g_array_index (matcher->sub_matchers, SubMatcher, mi);
2410 if (sub_matcher_matches (ssub, msub))
2414 if (si >= subtract->sub_matchers->len)
2417 ssub = &g_array_index (subtract->sub_matchers, SubMatcher, si);
2418 if (ssub->id <= msub->id)
2421 g_array_append_val (result->sub_matchers, *msub);
2424 if (mi < matcher->sub_matchers->len)
2425 g_array_append_vals (result->sub_matchers,
2426 &g_array_index (matcher->sub_matchers, SubMatcher, mi),
2427 matcher->sub_matchers->len - mi);
2429 result = matcher_optimize (result);
2435 * g_file_attribute_matcher_ref:
2436 * @matcher: a #GFileAttributeMatcher.
2438 * References a file attribute matcher.
2440 * Returns: a #GFileAttributeMatcher.
2442 GFileAttributeMatcher *
2443 g_file_attribute_matcher_ref (GFileAttributeMatcher *matcher)
2447 g_return_val_if_fail (matcher->ref > 0, NULL);
2448 g_atomic_int_inc (&matcher->ref);
2454 * g_file_attribute_matcher_unref:
2455 * @matcher: a #GFileAttributeMatcher.
2457 * Unreferences @matcher. If the reference count falls below 1,
2458 * the @matcher is automatically freed.
2462 g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher)
2466 g_return_if_fail (matcher->ref > 0);
2468 if (g_atomic_int_dec_and_test (&matcher->ref))
2470 if (matcher->sub_matchers)
2471 g_array_free (matcher->sub_matchers, TRUE);
2479 * g_file_attribute_matcher_matches_only:
2480 * @matcher: a #GFileAttributeMatcher.
2481 * @attribute: a file attribute key.
2483 * Checks if a attribute matcher only matches a given attribute. Always
2484 * returns %FALSE if "*" was used when creating the matcher.
2486 * Returns: %TRUE if the matcher only matches @attribute. %FALSE otherwise.
2489 g_file_attribute_matcher_matches_only (GFileAttributeMatcher *matcher,
2490 const char *attribute)
2492 SubMatcher *sub_matcher;
2495 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
2497 if (matcher == NULL ||
2501 if (matcher->sub_matchers->len != 1)
2504 id = lookup_attribute (attribute);
2506 sub_matcher = &g_array_index (matcher->sub_matchers, SubMatcher, 0);
2508 return sub_matcher->id == id &&
2509 sub_matcher->mask == 0xffffffff;
2513 matcher_matches_id (GFileAttributeMatcher *matcher,
2516 SubMatcher *sub_matchers;
2519 if (matcher->sub_matchers)
2521 sub_matchers = (SubMatcher *)matcher->sub_matchers->data;
2522 for (i = 0; i < matcher->sub_matchers->len; i++)
2524 if (sub_matchers[i].id == (id & sub_matchers[i].mask))
2533 _g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
2536 /* We return a NULL matcher for an empty match string, so handle this */
2537 if (matcher == NULL)
2543 return matcher_matches_id (matcher, id);
2547 * g_file_attribute_matcher_matches:
2548 * @matcher: a #GFileAttributeMatcher.
2549 * @attribute: a file attribute key.
2551 * Checks if an attribute will be matched by an attribute matcher. If
2552 * the matcher was created with the "*" matching string, this function
2553 * will always return %TRUE.
2555 * Returns: %TRUE if @attribute matches @matcher. %FALSE otherwise.
2558 g_file_attribute_matcher_matches (GFileAttributeMatcher *matcher,
2559 const char *attribute)
2561 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
2563 /* We return a NULL matcher for an empty match string, so handle this */
2564 if (matcher == NULL)
2570 return matcher_matches_id (matcher, lookup_attribute (attribute));
2573 /* return TRUE -> all */
2575 * g_file_attribute_matcher_enumerate_namespace:
2576 * @matcher: a #GFileAttributeMatcher.
2577 * @ns: a string containing a file attribute namespace.
2579 * Checks if the matcher will match all of the keys in a given namespace.
2580 * This will always return %TRUE if a wildcard character is in use (e.g. if
2581 * matcher was created with "standard::*" and @ns is "standard", or if matcher was created
2582 * using "*" and namespace is anything.)
2584 * TODO: this is awkwardly worded.
2586 * Returns: %TRUE if the matcher matches all of the entries
2587 * in the given @ns, %FALSE otherwise.
2590 g_file_attribute_matcher_enumerate_namespace (GFileAttributeMatcher *matcher,
2593 SubMatcher *sub_matchers;
2597 g_return_val_if_fail (ns != NULL && *ns != '\0', FALSE);
2599 /* We return a NULL matcher for an empty match string, so handle this */
2600 if (matcher == NULL)
2606 ns_id = lookup_namespace (ns) << NS_POS;
2608 if (matcher->sub_matchers)
2610 sub_matchers = (SubMatcher *)matcher->sub_matchers->data;
2611 for (i = 0; i < matcher->sub_matchers->len; i++)
2613 if (sub_matchers[i].id == ns_id)
2618 matcher->iterator_ns = ns_id;
2619 matcher->iterator_pos = 0;
2625 * g_file_attribute_matcher_enumerate_next:
2626 * @matcher: a #GFileAttributeMatcher.
2628 * Gets the next matched attribute from a #GFileAttributeMatcher.
2630 * Returns: a string containing the next attribute or %NULL if
2631 * no more attribute exist.
2634 g_file_attribute_matcher_enumerate_next (GFileAttributeMatcher *matcher)
2637 SubMatcher *sub_matcher;
2639 /* We return a NULL matcher for an empty match string, so handle this */
2640 if (matcher == NULL)
2645 i = matcher->iterator_pos++;
2647 if (matcher->sub_matchers == NULL)
2650 if (i < matcher->sub_matchers->len)
2651 sub_matcher = &g_array_index (matcher->sub_matchers, SubMatcher, i);
2655 if (sub_matcher->mask == 0xffffffff &&
2656 (sub_matcher->id & (NS_MASK << NS_POS)) == matcher->iterator_ns)
2657 return get_attribute_for_id (sub_matcher->id);
2662 * g_file_attribute_matcher_to_string:
2663 * @matcher: (allow-none): a #GFileAttributeMatcher.
2665 * Prints what the matcher is matching against. The format will be
2666 * equal to the format passed to g_file_attribute_matcher_new().
2667 * The output however, might not be identical, as the matcher may
2668 * decide to use a different order or omit needless parts.
2670 * Returns: a string describing the attributes the matcher matches
2671 * against or %NULL if @matcher was %NULL.
2676 g_file_attribute_matcher_to_string (GFileAttributeMatcher *matcher)
2681 if (matcher == NULL)
2685 return g_strdup ("*");
2687 string = g_string_new ("");
2688 for (i = 0; i < matcher->sub_matchers->len; i++)
2690 SubMatcher *submatcher = &g_array_index (matcher->sub_matchers, SubMatcher, i);
2693 g_string_append_c (string, ',');
2695 g_string_append (string, get_attribute_for_id (submatcher->id));
2698 return g_string_free (string, FALSE);