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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
25 * @short_description: File Information and Attributes
27 * @see_also: #GFile, <link linkend="gio-GFileAttribute">GFileAttribute</link>
29 * Functionality for manipulating basic metadata for files. #GFileInfo
30 * implements methods for getting information that all files should
31 * contain, and allows for manipulation of extended attributes.
33 * See <link linkend="gio-GFileAttribute">GFileAttribute</link> for more
34 * information on how GIO handles file attributes.
36 * To obtain a #GFileInfo for a #GFile, use g_file_query_info() (or its
37 * async variant). To obtain a #GFileInfo for a file input or output
38 * stream, use g_file_input_stream_query_info() or
39 * g_file_output_stream_query_info() (or their async variants).
41 * #GFileAttributeMatcher allows for searching through a #GFileInfo for
49 #include "gfileinfo.h"
50 #include "gfileattribute-priv.h"
55 /* We use this nasty thing, because NULL is a valid attribute matcher (matches nothing) */
56 #define NO_ATTRIBUTE_MASK ((GFileAttributeMatcher *)1)
60 GFileAttributeValue value;
65 GObject parent_instance;
68 GFileAttributeMatcher *mask;
71 struct _GFileInfoClass
73 GObjectClass parent_class;
77 static gboolean g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
80 G_DEFINE_TYPE (GFileInfo, g_file_info, G_TYPE_OBJECT);
84 guint32 attribute_id_counter;
87 G_LOCK_DEFINE_STATIC (attribute_hash);
88 static int namespace_id_counter = 0;
89 static GHashTable *ns_hash = NULL;
90 static GHashTable *attribute_hash = NULL;
91 static char ***attributes = NULL;
93 /* Attribute ids are 32bit, we split it up like this:
94 * |------------|--------------------|
96 * namespace attribute id
98 * This way the attributes gets sorted in namespace order
102 #define NS_MASK ((guint32)((1<<12) - 1))
104 #define ID_MASK ((guint32)((1<<20) - 1))
106 #define GET_NS(_attr_id) \
107 (((guint32) (_attr_id) >> NS_POS) & NS_MASK)
108 #define GET_ID(_attr_id) \
109 (((guint32)(_attr_id) >> ID_POS) & ID_MASK)
111 #define MAKE_ATTR_ID(_ns, _id) \
112 ( ((((guint32) _ns) & NS_MASK) << NS_POS) | \
113 ((((guint32) _id) & ID_MASK) << ID_POS) )
116 _lookup_namespace (const char *namespace)
120 ns_info = g_hash_table_lookup (ns_hash, namespace);
123 ns_info = g_new0 (NSInfo, 1);
124 ns_info->id = ++namespace_id_counter;
125 g_hash_table_insert (ns_hash, g_strdup (namespace), ns_info);
126 attributes = g_realloc (attributes, (ns_info->id + 1) * sizeof (char **));
127 attributes[ns_info->id] = NULL;
133 lookup_namespace (const char *namespace)
138 G_LOCK (attribute_hash);
140 if (attribute_hash == NULL)
142 ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
143 attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
146 ns_info = _lookup_namespace (namespace);
151 G_UNLOCK (attribute_hash);
157 get_attribute_for_id (int attribute)
160 G_LOCK (attribute_hash);
161 s = attributes[GET_NS(attribute)][GET_ID(attribute)];
162 G_UNLOCK (attribute_hash);
167 lookup_attribute (const char *attribute)
174 G_LOCK (attribute_hash);
175 if (attribute_hash == NULL)
177 ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
178 attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
181 attr_id = GPOINTER_TO_UINT (g_hash_table_lookup (attribute_hash, attribute));
185 G_UNLOCK (attribute_hash);
189 colon = strstr (attribute, "::");
191 ns = g_strndup (attribute, colon - attribute);
195 ns_info = _lookup_namespace (ns);
198 id = ++ns_info->attribute_id_counter;
199 attributes[ns_info->id] = g_realloc (attributes[ns_info->id], (id + 1) * sizeof (char *));
200 attributes[ns_info->id][id] = g_strdup (attribute);
202 attr_id = MAKE_ATTR_ID (ns_info->id, id);
204 g_hash_table_insert (attribute_hash, attributes[ns_info->id][id], GUINT_TO_POINTER (attr_id));
206 G_UNLOCK (attribute_hash);
212 g_file_info_finalize (GObject *object)
216 GFileAttribute *attrs;
218 info = G_FILE_INFO (object);
220 attrs = (GFileAttribute *)info->attributes->data;
221 for (i = 0; i < info->attributes->len; i++)
222 _g_file_attribute_value_clear (&attrs[i].value);
223 g_array_free (info->attributes, TRUE);
225 if (info->mask != NO_ATTRIBUTE_MASK)
226 g_file_attribute_matcher_unref (info->mask);
228 if (G_OBJECT_CLASS (g_file_info_parent_class)->finalize)
229 (*G_OBJECT_CLASS (g_file_info_parent_class)->finalize) (object);
233 g_file_info_class_init (GFileInfoClass *klass)
235 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
237 gobject_class->finalize = g_file_info_finalize;
241 g_file_info_init (GFileInfo *info)
243 info->mask = NO_ATTRIBUTE_MASK;
244 info->attributes = g_array_new (FALSE, FALSE,
245 sizeof (GFileAttribute));
251 * Creates a new file info structure.
253 * Returns: a #GFileInfo.
256 g_file_info_new (void)
258 return g_object_new (G_TYPE_FILE_INFO, NULL);
262 * g_file_info_copy_into:
263 * @src_info: source to copy attributes from.
264 * @dest_info: destination to copy attributes to.
266 * Copies all of the #GFileAttribute<!-- -->s from @src_info to @dest_info.
269 g_file_info_copy_into (GFileInfo *src_info,
270 GFileInfo *dest_info)
272 GFileAttribute *source, *dest;
275 g_return_if_fail (G_IS_FILE_INFO (src_info));
276 g_return_if_fail (G_IS_FILE_INFO (dest_info));
278 dest = (GFileAttribute *)dest_info->attributes->data;
279 for (i = 0; i < dest_info->attributes->len; i++)
280 _g_file_attribute_value_clear (&dest[i].value);
282 g_array_set_size (dest_info->attributes,
283 src_info->attributes->len);
285 source = (GFileAttribute *)src_info->attributes->data;
286 dest = (GFileAttribute *)dest_info->attributes->data;
288 for (i = 0; i < src_info->attributes->len; i++)
290 dest[i].attribute = source[i].attribute;
291 dest[i].value.type = G_FILE_ATTRIBUTE_TYPE_INVALID;
292 _g_file_attribute_value_set (&dest[i].value, &source[i].value);
295 if (src_info->mask == NO_ATTRIBUTE_MASK)
296 dest_info->mask = NO_ATTRIBUTE_MASK;
298 dest_info->mask = g_file_attribute_matcher_ref (src_info->mask);
303 * @other: a #GFileInfo.
305 * Duplicates a file info structure.
307 * Returns: a duplicate #GFileInfo of @other.
310 g_file_info_dup (GFileInfo *other)
314 g_return_val_if_fail (G_IS_FILE_INFO (other), NULL);
316 new = g_file_info_new ();
317 g_file_info_copy_into (other, new);
322 * g_file_info_set_attribute_mask:
323 * @info: a #GFileInfo.
324 * @mask: a #GFileAttributeMatcher.
326 * Sets @mask on @info to match specific attribute types.
329 g_file_info_set_attribute_mask (GFileInfo *info,
330 GFileAttributeMatcher *mask)
332 GFileAttribute *attr;
335 g_return_if_fail (G_IS_FILE_INFO (info));
336 g_return_if_fail (mask != NULL);
338 if (mask != info->mask)
340 if (info->mask != NO_ATTRIBUTE_MASK)
341 g_file_attribute_matcher_unref (info->mask);
342 info->mask = g_file_attribute_matcher_ref (mask);
344 /* Remove non-matching attributes */
345 for (i = 0; i < info->attributes->len; i++)
347 attr = &g_array_index (info->attributes, GFileAttribute, i);
348 if (!g_file_attribute_matcher_matches_id (mask,
351 _g_file_attribute_value_clear (&attr->value);
352 g_array_remove_index (info->attributes, i);
360 * g_file_info_unset_attribute_mask:
363 * Unsets a mask set by g_file_info_set_attribute_mask(), if one
367 g_file_info_unset_attribute_mask (GFileInfo *info)
369 g_return_if_fail (G_IS_FILE_INFO (info));
371 if (info->mask != NO_ATTRIBUTE_MASK)
372 g_file_attribute_matcher_unref (info->mask);
373 info->mask = NO_ATTRIBUTE_MASK;
377 * g_file_info_clear_status:
378 * @info: a #GFileInfo.
380 * Clears the status information from @info.
383 g_file_info_clear_status (GFileInfo *info)
385 GFileAttribute *attrs;
388 g_return_if_fail (G_IS_FILE_INFO (info));
390 attrs = (GFileAttribute *)info->attributes->data;
391 for (i = 0; i < info->attributes->len; i++)
392 attrs[i].value.status = G_FILE_ATTRIBUTE_STATUS_UNSET;
396 g_file_info_find_place (GFileInfo *info,
400 GFileAttribute *attrs;
401 /* Binary search for the place where attribute would be, if its
405 max = info->attributes->len;
407 attrs = (GFileAttribute *)info->attributes->data;
411 med = min + (max - min) / 2;
412 if (attrs[med].attribute == attribute)
417 else if (attrs[med].attribute < attribute)
419 else /* attrs[med].attribute > attribute */
426 static GFileAttributeValue *
427 g_file_info_find_value (GFileInfo *info,
430 GFileAttribute *attrs;
433 i = g_file_info_find_place (info, attr_id);
434 attrs = (GFileAttribute *)info->attributes->data;
435 if (i < info->attributes->len &&
436 attrs[i].attribute == attr_id)
437 return &attrs[i].value;
442 static GFileAttributeValue *
443 g_file_info_find_value_by_name (GFileInfo *info,
444 const char *attribute)
448 attr_id = lookup_attribute (attribute);
449 return g_file_info_find_value (info, attr_id);
453 * g_file_info_has_attribute:
454 * @info: a #GFileInfo.
455 * @attribute: a file attribute key.
457 * Checks if a file info structure has an attribute named @attribute.
459 * Returns: %TRUE if @Ginfo has an attribute named @attribute,
463 g_file_info_has_attribute (GFileInfo *info,
464 const char *attribute)
466 GFileAttributeValue *value;
468 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
469 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
471 value = g_file_info_find_value_by_name (info, attribute);
472 return value != NULL;
476 * g_file_info_list_attributes:
477 * @info: a #GFileInfo.
478 * @name_space: a file attribute key's namespace.
480 * Lists the file info structure's attributes.
482 * Returns: a null-terminated array of strings of all of the
483 * possible attribute types for the given @name_space, or
487 g_file_info_list_attributes (GFileInfo *info,
488 const char *name_space)
491 GFileAttribute *attrs;
493 guint32 ns_id = (name_space) ? lookup_namespace (name_space) : 0;
496 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
498 names = g_ptr_array_new ();
499 attrs = (GFileAttribute *)info->attributes->data;
500 for (i = 0; i < info->attributes->len; i++)
502 attribute = attrs[i].attribute;
503 if (ns_id == 0 || GET_NS (attribute) == ns_id)
504 g_ptr_array_add (names, g_strdup (get_attribute_for_id (attribute)));
508 g_ptr_array_add (names, NULL);
510 return (char **)g_ptr_array_free (names, FALSE);
514 * g_file_info_get_attribute_type:
515 * @info: a #GFileInfo.
516 * @attribute: a file attribute key.
518 * Gets the attribute type for an attribute key.
520 * Returns: a #GFileAttributeType for the given @attribute, or
521 * %G_FILE_ATTRIBUTE_TYPE_INVALID if the key is invalid.
524 g_file_info_get_attribute_type (GFileInfo *info,
525 const char *attribute)
527 GFileAttributeValue *value;
529 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_ATTRIBUTE_TYPE_INVALID);
530 g_return_val_if_fail (attribute != NULL && *attribute != '\0', G_FILE_ATTRIBUTE_TYPE_INVALID);
532 value = g_file_info_find_value_by_name (info, attribute);
536 return G_FILE_ATTRIBUTE_TYPE_INVALID;
540 * g_file_info_remove_attribute:
541 * @info: a #GFileInfo.
542 * @attribute: a file attribute key.
544 * Removes all cases of @attribute from @info if it exists.
547 g_file_info_remove_attribute (GFileInfo *info,
548 const char *attribute)
551 GFileAttribute *attrs;
554 g_return_if_fail (G_IS_FILE_INFO (info));
555 g_return_if_fail (attribute != NULL && *attribute != '\0');
557 attr_id = lookup_attribute (attribute);
559 i = g_file_info_find_place (info, attr_id);
560 attrs = (GFileAttribute *)info->attributes->data;
561 if (i < info->attributes->len &&
562 attrs[i].attribute == attr_id)
564 _g_file_attribute_value_clear (&attrs[i].value);
565 g_array_remove_index (info->attributes, i);
570 * g_file_info_get_attribute_data:
571 * @info: a #GFileInfo
572 * @attribute: a file attribute key
573 * @type: return location for the attribute type, or %NULL
574 * @value_pp: return location for the attribute value, or %NULL
575 * @status: return location for the attribute status, or %NULL
577 * Gets the attribute type, value and status for an attribute key.
579 * Returns: %TRUE if @info has an attribute named @attribute,
583 g_file_info_get_attribute_data (GFileInfo *info,
584 const char *attribute,
585 GFileAttributeType *type,
587 GFileAttributeStatus *status)
589 GFileAttributeValue *value;
591 value = g_file_info_find_value_by_name (info, attribute);
596 *status = value->status;
602 *value_pp = _g_file_attribute_value_peek_as_pointer (value);
608 * g_file_info_get_attribute_status:
609 * @info: a #GFileInfo
610 * @attribute: a file attribute key
612 * Gets the attribute status for an attribute key.
614 * Returns: a #GFileAttributeStatus for the given @attribute, or
615 * %G_FILE_ATTRIBUTE_STATUS_UNSET if the key is invalid.
619 g_file_info_get_attribute_status (GFileInfo *info,
620 const char *attribute)
622 GFileAttributeValue *val;
624 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
625 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
627 val = g_file_info_find_value_by_name (info, attribute);
631 return G_FILE_ATTRIBUTE_STATUS_UNSET;
635 GFileAttributeValue *
636 _g_file_info_get_attribute_value (GFileInfo *info,
637 const char *attribute)
640 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
641 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
643 return g_file_info_find_value_by_name (info, attribute);
647 * g_file_info_get_attribute_as_string:
648 * @info: a #GFileInfo.
649 * @attribute: a file attribute key.
651 * Gets the value of a attribute, formated as a string.
652 * This escapes things as needed to make the string valid
655 * Returns: a UTF-8 string associated with the given @attribute.
656 * When you're done with the string it must be freed with g_free().
659 g_file_info_get_attribute_as_string (GFileInfo *info,
660 const char *attribute)
662 GFileAttributeValue *val;
663 val = _g_file_info_get_attribute_value (info, attribute);
665 return _g_file_attribute_value_as_string (val);
671 * g_file_info_get_attribute_object:
672 * @info: a #GFileInfo.
673 * @attribute: a file attribute key.
675 * Gets the value of a #GObject attribute. If the attribute does
676 * not contain a #GObject, %NULL will be returned.
678 * Returns: a #GObject associated with the given @attribute, or
682 g_file_info_get_attribute_object (GFileInfo *info,
683 const char *attribute)
685 GFileAttributeValue *value;
687 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
688 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
690 value = g_file_info_find_value_by_name (info, attribute);
691 return _g_file_attribute_value_get_object (value);
695 * g_file_info_get_attribute_string:
696 * @info: a #GFileInfo.
697 * @attribute: a file attribute key.
699 * Gets the value of a string attribute. If the attribute does
700 * not contain a string, %NULL will be returned.
702 * Returns: the contents of the @attribute value as a string, or
706 g_file_info_get_attribute_string (GFileInfo *info,
707 const char *attribute)
709 GFileAttributeValue *value;
711 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
712 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
714 value = g_file_info_find_value_by_name (info, attribute);
715 return _g_file_attribute_value_get_string (value);
719 * g_file_info_get_attribute_byte_string:
720 * @info: a #GFileInfo.
721 * @attribute: a file attribute key.
723 * Gets the value of a byte string attribute. If the attribute does
724 * not contain a byte string, %NULL will be returned.
726 * Returns: the contents of the @attribute value as a byte string, or
730 g_file_info_get_attribute_byte_string (GFileInfo *info,
731 const char *attribute)
733 GFileAttributeValue *value;
735 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
736 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
738 value = g_file_info_find_value_by_name (info, attribute);
739 return _g_file_attribute_value_get_byte_string (value);
743 * g_file_info_get_attribute_boolean:
744 * @info: a #GFileInfo.
745 * @attribute: a file attribute key.
747 * Gets the value of a boolean attribute. If the attribute does not
748 * contain a boolean value, %FALSE will be returned.
750 * Returns: the boolean value contained within the attribute.
753 g_file_info_get_attribute_boolean (GFileInfo *info,
754 const char *attribute)
756 GFileAttributeValue *value;
758 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
759 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
761 value = g_file_info_find_value_by_name (info, attribute);
762 return _g_file_attribute_value_get_boolean (value);
766 * g_file_info_get_attribute_uint32:
767 * @info: a #GFileInfo.
768 * @attribute: a file attribute key.
770 * Gets an unsigned 32-bit integer contained within the attribute. If the
771 * attribute does not contain an unsigned 32-bit integer, or is invalid,
772 * 0 will be returned.
774 * Returns: an unsigned 32-bit integer from the attribute.
777 g_file_info_get_attribute_uint32 (GFileInfo *info,
778 const char *attribute)
780 GFileAttributeValue *value;
782 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
783 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
785 value = g_file_info_find_value_by_name (info, attribute);
786 return _g_file_attribute_value_get_uint32 (value);
790 * g_file_info_get_attribute_int32:
791 * @info: a #GFileInfo.
792 * @attribute: a file attribute key.
794 * Gets a signed 32-bit integer contained within the attribute. If the
795 * attribute does not contain a signed 32-bit integer, or is invalid,
796 * 0 will be returned.
798 * Returns: a signed 32-bit integer from the attribute.
801 g_file_info_get_attribute_int32 (GFileInfo *info,
802 const char *attribute)
804 GFileAttributeValue *value;
806 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
807 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
809 value = g_file_info_find_value_by_name (info, attribute);
810 return _g_file_attribute_value_get_int32 (value);
814 * g_file_info_get_attribute_uint64:
815 * @info: a #GFileInfo.
816 * @attribute: a file attribute key.
818 * Gets a unsigned 64-bit integer contained within the attribute. If the
819 * attribute does not contain an unsigned 64-bit integer, or is invalid,
820 * 0 will be returned.
822 * Returns: a unsigned 64-bit integer from the attribute.
825 g_file_info_get_attribute_uint64 (GFileInfo *info,
826 const char *attribute)
828 GFileAttributeValue *value;
830 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
831 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
833 value = g_file_info_find_value_by_name (info, attribute);
834 return _g_file_attribute_value_get_uint64 (value);
838 * g_file_info_get_attribute_int64:
839 * @info: a #GFileInfo.
840 * @attribute: a file attribute key.
842 * Gets a signed 64-bit integer contained within the attribute. If the
843 * attribute does not contain an signed 64-bit integer, or is invalid,
844 * 0 will be returned.
846 * Returns: a signed 64-bit integer from the attribute.
849 g_file_info_get_attribute_int64 (GFileInfo *info,
850 const char *attribute)
852 GFileAttributeValue *value;
854 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
855 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
857 value = g_file_info_find_value_by_name (info, attribute);
858 return _g_file_attribute_value_get_int64 (value);
861 static GFileAttributeValue *
862 g_file_info_create_value (GFileInfo *info,
865 GFileAttribute *attrs;
868 if (info->mask != NO_ATTRIBUTE_MASK &&
869 !g_file_attribute_matcher_matches_id (info->mask, attr_id))
872 i = g_file_info_find_place (info, attr_id);
874 attrs = (GFileAttribute *)info->attributes->data;
875 if (i < info->attributes->len &&
876 attrs[i].attribute == attr_id)
877 return &attrs[i].value;
880 GFileAttribute attr = { 0 };
881 attr.attribute = attr_id;
882 g_array_insert_val (info->attributes, i, attr);
884 attrs = (GFileAttribute *)info->attributes->data;
885 return &attrs[i].value;
889 static GFileAttributeValue *
890 g_file_info_create_value_by_name (GFileInfo *info,
891 const char *attribute)
895 attr_id = lookup_attribute (attribute);
897 return g_file_info_create_value (info, attr_id);
901 * g_file_info_set_attribute:
902 * @info: a #GFileInfo.
903 * @attribute: a file attribute key.
904 * @type: a #GFileAttributeType
905 * @value_p: pointer to the value
907 * Sets the @attribute to contain the given value, if possible.
910 g_file_info_set_attribute (GFileInfo *info,
911 const char *attribute,
912 GFileAttributeType type,
915 GFileAttributeValue *value;
917 g_return_if_fail (G_IS_FILE_INFO (info));
918 g_return_if_fail (attribute != NULL && *attribute != '\0');
920 value = g_file_info_create_value_by_name (info, attribute);
923 _g_file_attribute_value_set_from_pointer (value, type, value_p, TRUE);
927 * g_file_info_set_attribute_object:
928 * @info: a #GFileInfo.
929 * @attribute: a file attribute key.
930 * @attr_value: a #GObject.
932 * Sets the @attribute to contain the given @attr_value,
936 g_file_info_set_attribute_object (GFileInfo *info,
937 const char *attribute,
940 GFileAttributeValue *value;
942 g_return_if_fail (G_IS_FILE_INFO (info));
943 g_return_if_fail (attribute != NULL && *attribute != '\0');
944 g_return_if_fail (G_IS_OBJECT (attr_value));
946 value = g_file_info_create_value_by_name (info, attribute);
948 _g_file_attribute_value_set_object (value, attr_value);
952 * g_file_info_set_attribute_string:
953 * @info: a #GFileInfo.
954 * @attribute: a file attribute key.
955 * @attr_value: a string.
957 * Sets the @attribute to contain the given @attr_value,
961 g_file_info_set_attribute_string (GFileInfo *info,
962 const char *attribute,
963 const char *attr_value)
965 GFileAttributeValue *value;
967 g_return_if_fail (G_IS_FILE_INFO (info));
968 g_return_if_fail (attribute != NULL && *attribute != '\0');
969 g_return_if_fail (attr_value != NULL);
971 value = g_file_info_create_value_by_name (info, attribute);
973 _g_file_attribute_value_set_string (value, attr_value);
977 * g_file_info_set_attribute_byte_string:
978 * @info: a #GFileInfo.
979 * @attribute: a file attribute key.
980 * @attr_value: a byte string.
982 * Sets the @attribute to contain the given @attr_value,
986 g_file_info_set_attribute_byte_string (GFileInfo *info,
987 const char *attribute,
988 const char *attr_value)
990 GFileAttributeValue *value;
992 g_return_if_fail (G_IS_FILE_INFO (info));
993 g_return_if_fail (attribute != NULL && *attribute != '\0');
994 g_return_if_fail (attr_value != NULL);
996 value = g_file_info_create_value_by_name (info, attribute);
998 _g_file_attribute_value_set_byte_string (value, attr_value);
1002 * g_file_info_set_attribute_boolean:
1003 * @info: a #GFileInfo.
1004 * @attribute: a file attribute key.
1005 * @attr_value: a boolean value.
1007 * Sets the @attribute to contain the given @attr_value,
1011 g_file_info_set_attribute_boolean (GFileInfo *info,
1012 const char *attribute,
1013 gboolean attr_value)
1015 GFileAttributeValue *value;
1017 g_return_if_fail (G_IS_FILE_INFO (info));
1018 g_return_if_fail (attribute != NULL && *attribute != '\0');
1020 value = g_file_info_create_value_by_name (info, attribute);
1022 _g_file_attribute_value_set_boolean (value, attr_value);
1026 * g_file_info_set_attribute_uint32:
1027 * @info: a #GFileInfo.
1028 * @attribute: a file attribute key.
1029 * @attr_value: an unsigned 32-bit integer.
1031 * Sets the @attribute to contain the given @attr_value,
1035 g_file_info_set_attribute_uint32 (GFileInfo *info,
1036 const char *attribute,
1039 GFileAttributeValue *value;
1041 g_return_if_fail (G_IS_FILE_INFO (info));
1042 g_return_if_fail (attribute != NULL && *attribute != '\0');
1044 value = g_file_info_create_value_by_name (info, attribute);
1046 _g_file_attribute_value_set_uint32 (value, attr_value);
1051 * g_file_info_set_attribute_int32:
1052 * @info: a #GFileInfo.
1053 * @attribute: a file attribute key.
1054 * @attr_value: a signed 32-bit integer
1056 * Sets the @attribute to contain the given @attr_value,
1060 g_file_info_set_attribute_int32 (GFileInfo *info,
1061 const char *attribute,
1064 GFileAttributeValue *value;
1066 g_return_if_fail (G_IS_FILE_INFO (info));
1067 g_return_if_fail (attribute != NULL && *attribute != '\0');
1069 value = g_file_info_create_value_by_name (info, attribute);
1071 _g_file_attribute_value_set_int32 (value, attr_value);
1075 * g_file_info_set_attribute_uint64:
1076 * @info: a #GFileInfo.
1077 * @attribute: a file attribute key.
1078 * @attr_value: an unsigned 64-bit integer.
1080 * Sets the @attribute to contain the given @attr_value,
1084 g_file_info_set_attribute_uint64 (GFileInfo *info,
1085 const char *attribute,
1088 GFileAttributeValue *value;
1090 g_return_if_fail (G_IS_FILE_INFO (info));
1091 g_return_if_fail (attribute != NULL && *attribute != '\0');
1093 value = g_file_info_create_value_by_name (info, attribute);
1095 _g_file_attribute_value_set_uint64 (value, attr_value);
1099 * g_file_info_set_attribute_int64:
1100 * @info: a #GFileInfo.
1101 * @attribute: attribute name to set.
1102 * @attr_value: int64 value to set attribute to.
1104 * Sets the @attribute to contain the given @attr_value,
1109 g_file_info_set_attribute_int64 (GFileInfo *info,
1110 const char *attribute,
1113 GFileAttributeValue *value;
1115 g_return_if_fail (G_IS_FILE_INFO (info));
1116 g_return_if_fail (attribute != NULL && *attribute != '\0');
1118 value = g_file_info_create_value_by_name (info, attribute);
1120 _g_file_attribute_value_set_int64 (value, attr_value);
1123 /* Helper getters */
1125 * g_file_info_get_file_type:
1126 * @info: a #GFileInfo.
1128 * Gets a file's type (whether it is a regular file, symlink, etc).
1129 * This is different from the file's content type, see g_file_info_get_content_type().
1131 * Returns: a #GFileType for the given file.
1134 g_file_info_get_file_type (GFileInfo *info)
1136 static guint32 attr = 0;
1137 GFileAttributeValue *value;
1139 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_TYPE_UNKNOWN);
1142 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
1144 value = g_file_info_find_value (info, attr);
1145 return (GFileType)_g_file_attribute_value_get_uint32 (value);
1149 * g_file_info_get_is_hidden:
1150 * @info: a #GFileInfo.
1152 * Checks if a file is hidden.
1154 * Returns: %TRUE if the file is a hidden file, %FALSE otherwise.
1157 g_file_info_get_is_hidden (GFileInfo *info)
1159 static guint32 attr = 0;
1160 GFileAttributeValue *value;
1162 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1165 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
1167 value = g_file_info_find_value (info, attr);
1168 return (GFileType)_g_file_attribute_value_get_boolean (value);
1172 * g_file_info_get_is_backup:
1173 * @info: a #GFileInfo.
1175 * Checks if a file is a backup file.
1177 * Returns: %TRUE if file is a backup file, %FALSE otherwise.
1180 g_file_info_get_is_backup (GFileInfo *info)
1182 static guint32 attr = 0;
1183 GFileAttributeValue *value;
1185 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1188 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
1190 value = g_file_info_find_value (info, attr);
1191 return (GFileType)_g_file_attribute_value_get_boolean (value);
1195 * g_file_info_get_is_symlink:
1196 * @info: a #GFileInfo.
1198 * Checks if a file is a symlink.
1200 * Returns: %TRUE if the given @info is a symlink.
1203 g_file_info_get_is_symlink (GFileInfo *info)
1205 static guint32 attr = 0;
1206 GFileAttributeValue *value;
1208 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1211 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
1213 value = g_file_info_find_value (info, attr);
1214 return (GFileType)_g_file_attribute_value_get_boolean (value);
1218 * g_file_info_get_name:
1219 * @info: a #GFileInfo.
1221 * Gets the name for a file.
1223 * Returns: a string containing the file name.
1226 g_file_info_get_name (GFileInfo *info)
1228 static guint32 attr = 0;
1229 GFileAttributeValue *value;
1231 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1234 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
1236 value = g_file_info_find_value (info, attr);
1237 return _g_file_attribute_value_get_byte_string (value);
1241 * g_file_info_get_display_name:
1242 * @info: a #GFileInfo.
1244 * Gets a display name for a file.
1246 * Returns: a string containing the display name.
1249 g_file_info_get_display_name (GFileInfo *info)
1251 static guint32 attr = 0;
1252 GFileAttributeValue *value;
1254 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1257 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
1259 value = g_file_info_find_value (info, attr);
1260 return _g_file_attribute_value_get_string (value);
1264 * g_file_info_get_edit_name:
1265 * @info: a #GFileInfo.
1267 * Gets the edit name for a file.
1269 * Returns: a string containing the edit name.
1272 g_file_info_get_edit_name (GFileInfo *info)
1274 static guint32 attr = 0;
1275 GFileAttributeValue *value;
1277 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1280 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
1282 value = g_file_info_find_value (info, attr);
1283 return _g_file_attribute_value_get_string (value);
1287 * g_file_info_get_icon:
1288 * @info: a #GFileInfo.
1290 * Gets the icon for a file.
1292 * Returns: #GIcon for the given @info.
1295 g_file_info_get_icon (GFileInfo *info)
1297 static guint32 attr = 0;
1298 GFileAttributeValue *value;
1301 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1304 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
1306 value = g_file_info_find_value (info, attr);
1307 obj = _g_file_attribute_value_get_object (value);
1308 if (obj != NULL && G_IS_ICON (obj))
1309 return G_ICON (obj);
1314 * g_file_info_get_content_type:
1315 * @info: a #GFileInfo.
1317 * Gets the file's content type.
1319 * Returns: a string containing the file's content type.s
1322 g_file_info_get_content_type (GFileInfo *info)
1324 static guint32 attr = 0;
1325 GFileAttributeValue *value;
1327 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1330 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1332 value = g_file_info_find_value (info, attr);
1333 return _g_file_attribute_value_get_string (value);
1337 * g_file_info_get_size:
1338 * @info: a #GFileInfo.
1340 * Gets the file's size.
1342 * Returns: a #goffset containing the file's size.
1345 g_file_info_get_size (GFileInfo *info)
1347 static guint32 attr = 0;
1348 GFileAttributeValue *value;
1350 g_return_val_if_fail (G_IS_FILE_INFO (info), (goffset) 0);
1353 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
1355 value = g_file_info_find_value (info, attr);
1356 return (goffset) _g_file_attribute_value_get_uint64 (value);
1360 * g_file_info_get_modification_time:
1361 * @info: a #GFileInfo.
1362 * @result: a #GTimeVal.
1364 * Gets the modification time of the current @info and sets it
1368 g_file_info_get_modification_time (GFileInfo *info,
1371 static guint32 attr_mtime = 0, attr_mtime_usec;
1372 GFileAttributeValue *value;
1374 g_return_if_fail (G_IS_FILE_INFO (info));
1375 g_return_if_fail (result != NULL);
1377 if (attr_mtime == 0)
1379 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1380 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1383 value = g_file_info_find_value (info, attr_mtime);
1384 result->tv_sec = _g_file_attribute_value_get_uint64 (value);
1385 value = g_file_info_find_value (info, attr_mtime_usec);
1386 result->tv_usec = _g_file_attribute_value_get_uint32 (value);
1390 * g_file_info_get_symlink_target:
1391 * @info: a #GFileInfo.
1393 * Gets the symlink target for a given #GFileInfo.
1395 * Returns: a string containing the symlink target.
1398 g_file_info_get_symlink_target (GFileInfo *info)
1400 static guint32 attr = 0;
1401 GFileAttributeValue *value;
1403 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1406 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
1408 value = g_file_info_find_value (info, attr);
1409 return _g_file_attribute_value_get_byte_string (value);
1413 * g_file_info_get_etag:
1414 * @info: a #GFileInfo.
1416 * Gets the <link linkend="gfile-etag">entity tag</link> for a given
1417 * #GFileInfo. See %G_FILE_ATTRIBUTE_ETAG_VALUE.
1419 * Returns: a string containing the value of the "etag:value" attribute.
1422 g_file_info_get_etag (GFileInfo *info)
1424 static guint32 attr = 0;
1425 GFileAttributeValue *value;
1427 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1430 attr = lookup_attribute (G_FILE_ATTRIBUTE_ETAG_VALUE);
1432 value = g_file_info_find_value (info, attr);
1433 return _g_file_attribute_value_get_string (value);
1437 * g_file_info_get_sort_order:
1438 * @info: a #GFileInfo.
1440 * Gets the value of the sort_order attribute from the #GFileInfo.
1441 * See %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
1443 * Returns: a #gint32 containing the value of the "standard::sort_order" attribute.
1446 g_file_info_get_sort_order (GFileInfo *info)
1448 static guint32 attr = 0;
1449 GFileAttributeValue *value;
1451 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1454 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
1456 value = g_file_info_find_value (info, attr);
1457 return _g_file_attribute_value_get_int32 (value);
1460 /* Helper setters: */
1462 * g_file_info_set_file_type:
1463 * @info: a #GFileInfo.
1464 * @type: a #GFileType.
1466 * Sets the file type in a #GFileInfo to @type.
1467 * See %G_FILE_ATTRIBUTE_STANDARD_TYPE.
1470 g_file_info_set_file_type (GFileInfo *info,
1473 static guint32 attr = 0;
1474 GFileAttributeValue *value;
1476 g_return_if_fail (G_IS_FILE_INFO (info));
1479 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
1481 value = g_file_info_create_value (info, attr);
1483 _g_file_attribute_value_set_uint32 (value, type);
1487 * g_file_info_set_is_hidden:
1488 * @info: a #GFileInfo.
1489 * @is_hidden: a #gboolean.
1491 * Sets the "is_hidden" attribute in a #GFileInfo according to @is_symlink.
1492 * See %G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN.
1495 g_file_info_set_is_hidden (GFileInfo *info,
1498 static guint32 attr = 0;
1499 GFileAttributeValue *value;
1501 g_return_if_fail (G_IS_FILE_INFO (info));
1504 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
1506 value = g_file_info_create_value (info, attr);
1508 _g_file_attribute_value_set_boolean (value, is_hidden);
1512 * g_file_info_set_is_symlink:
1513 * @info: a #GFileInfo.
1514 * @is_symlink: a #gboolean.
1516 * Sets the "is_symlink" attribute in a #GFileInfo according to @is_symlink.
1517 * See %G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK.
1520 g_file_info_set_is_symlink (GFileInfo *info,
1521 gboolean is_symlink)
1523 static guint32 attr = 0;
1524 GFileAttributeValue *value;
1526 g_return_if_fail (G_IS_FILE_INFO (info));
1529 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
1531 value = g_file_info_create_value (info, attr);
1533 _g_file_attribute_value_set_boolean (value, is_symlink);
1537 * g_file_info_set_name:
1538 * @info: a #GFileInfo.
1539 * @name: a string containing a name.
1541 * Sets the name attribute for the current #GFileInfo.
1542 * See %G_FILE_ATTRIBUTE_STANDARD_NAME.
1545 g_file_info_set_name (GFileInfo *info,
1548 static guint32 attr = 0;
1549 GFileAttributeValue *value;
1551 g_return_if_fail (G_IS_FILE_INFO (info));
1552 g_return_if_fail (name != NULL);
1555 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
1557 value = g_file_info_create_value (info, attr);
1559 _g_file_attribute_value_set_byte_string (value, name);
1563 * g_file_info_set_display_name:
1564 * @info: a #GFileInfo.
1565 * @display_name: a string containing a display name.
1567 * Sets the display name for the current #GFileInfo.
1568 * See %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.
1571 g_file_info_set_display_name (GFileInfo *info,
1572 const char *display_name)
1574 static guint32 attr = 0;
1575 GFileAttributeValue *value;
1577 g_return_if_fail (G_IS_FILE_INFO (info));
1578 g_return_if_fail (display_name != NULL);
1581 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
1583 value = g_file_info_create_value (info, attr);
1585 _g_file_attribute_value_set_string (value, display_name);
1589 * g_file_info_set_edit_name:
1590 * @info: a #GFileInfo.
1591 * @edit_name: a string containing an edit name.
1593 * Sets the edit name for the current file.
1594 * See %G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME.
1597 g_file_info_set_edit_name (GFileInfo *info,
1598 const char *edit_name)
1600 static guint32 attr = 0;
1601 GFileAttributeValue *value;
1603 g_return_if_fail (G_IS_FILE_INFO (info));
1604 g_return_if_fail (edit_name != NULL);
1607 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
1609 value = g_file_info_create_value (info, attr);
1611 _g_file_attribute_value_set_string (value, edit_name);
1615 * g_file_info_set_icon:
1616 * @info: a #GFileInfo.
1619 * Sets the icon for a given #GFileInfo.
1620 * See %G_FILE_ATTRIBUTE_STANDARD_ICON.
1623 g_file_info_set_icon (GFileInfo *info,
1626 static guint32 attr = 0;
1627 GFileAttributeValue *value;
1629 g_return_if_fail (G_IS_FILE_INFO (info));
1630 g_return_if_fail (G_IS_ICON (icon));
1633 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
1635 value = g_file_info_create_value (info, attr);
1637 _g_file_attribute_value_set_object (value, G_OBJECT (icon));
1641 * g_file_info_set_content_type:
1642 * @info: a #GFileInfo.
1643 * @content_type: a content type. See #GContentType.
1645 * Sets the content type attribute for a given #GFileInfo.
1646 * See %G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE.
1649 g_file_info_set_content_type (GFileInfo *info,
1650 const char *content_type)
1652 static guint32 attr = 0;
1653 GFileAttributeValue *value;
1655 g_return_if_fail (G_IS_FILE_INFO (info));
1656 g_return_if_fail (content_type != NULL);
1659 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1661 value = g_file_info_create_value (info, attr);
1663 _g_file_attribute_value_set_string (value, content_type);
1667 * g_file_info_set_size:
1668 * @info: a #GFileInfo.
1669 * @size: a #goffset containing the file's size.
1671 * Sets the %G_FILE_ATTRIBUTE_STANDARD_SIZE attribute in the file info
1672 * to the given size.
1675 g_file_info_set_size (GFileInfo *info,
1678 static guint32 attr = 0;
1679 GFileAttributeValue *value;
1681 g_return_if_fail (G_IS_FILE_INFO (info));
1684 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
1686 value = g_file_info_create_value (info, attr);
1688 _g_file_attribute_value_set_uint64 (value, size);
1692 * g_file_info_set_modification_time
1693 * @info: a #GFileInfo.
1694 * @mtime: a #GTimeVal.
1696 * Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute in the file
1697 * info to the given time value.
1700 g_file_info_set_modification_time (GFileInfo *info,
1703 static guint32 attr_mtime = 0, attr_mtime_usec;
1704 GFileAttributeValue *value;
1706 g_return_if_fail (G_IS_FILE_INFO (info));
1707 g_return_if_fail (mtime != NULL);
1709 if (attr_mtime == 0)
1711 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1712 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1715 value = g_file_info_create_value (info, attr_mtime);
1717 _g_file_attribute_value_set_uint64 (value, mtime->tv_sec);
1718 value = g_file_info_create_value (info, attr_mtime_usec);
1720 _g_file_attribute_value_set_uint32 (value, mtime->tv_usec);
1724 * g_file_info_set_symlink_target:
1725 * @info: a #GFileInfo.
1726 * @symlink_target: a static string containing a path to a symlink target.
1728 * Sets the %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET attribute in the file info
1729 * to the given symlink target.
1732 g_file_info_set_symlink_target (GFileInfo *info,
1733 const char *symlink_target)
1735 static guint32 attr = 0;
1736 GFileAttributeValue *value;
1738 g_return_if_fail (G_IS_FILE_INFO (info));
1739 g_return_if_fail (symlink_target != NULL);
1742 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
1744 value = g_file_info_create_value (info, attr);
1746 _g_file_attribute_value_set_byte_string (value, symlink_target);
1750 * g_file_info_set_sort_order:
1751 * @info: a #GFileInfo.
1752 * @sort_order: a sort order integer.
1754 * Sets the sort order attribute in the file info structure. See
1755 * %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
1758 g_file_info_set_sort_order (GFileInfo *info,
1761 static guint32 attr = 0;
1762 GFileAttributeValue *value;
1764 g_return_if_fail (G_IS_FILE_INFO (info));
1767 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
1769 value = g_file_info_create_value (info, attr);
1771 _g_file_attribute_value_set_int32 (value, sort_order);
1775 #define ON_STACK_MATCHERS 5
1782 struct _GFileAttributeMatcher {
1784 SubMatcher sub_matchers[ON_STACK_MATCHERS];
1785 GArray *more_sub_matchers;
1788 guint32 iterator_ns;
1794 matcher_add (GFileAttributeMatcher *matcher,
1798 SubMatcher *sub_matchers;
1802 for (i = 0; i < ON_STACK_MATCHERS; i++)
1804 /* First empty spot, not found, use this */
1805 if (matcher->sub_matchers[i].id == 0)
1807 matcher->sub_matchers[i].id = id;
1808 matcher->sub_matchers[i].mask = mask;
1813 if (matcher->sub_matchers[i].id == id &&
1814 matcher->sub_matchers[i].mask == mask)
1818 if (matcher->more_sub_matchers == NULL)
1819 matcher->more_sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
1821 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
1822 for (i = 0; i < matcher->more_sub_matchers->len; i++)
1825 if (sub_matchers[i].id == id &&
1826 sub_matchers[i].mask == mask)
1833 g_array_append_val (matcher->more_sub_matchers, s);
1837 * g_file_attribute_matcher_new:
1838 * @attributes: an attribute string to match.
1840 * Creates a new file attribute matcher, which matches attributes
1841 * against a given string. #GFileAttributeMatcher<!-- -->s are reference
1842 * counted structures, and are created with a reference count of 1. If
1843 * the number of references falls to 0, the #GFileAttributeMatcher is
1844 * automatically destroyed.
1846 * The @attribute string should be formatted with specific keys separated
1847 * from namespaces with a double colon. Several "namespace::key" strings may be
1848 * concatenated with a single comma (e.g. "standard::type,standard::is-hidden").
1849 * The wildcard "*" may be used to match all keys and namespaces, or
1850 * "namespace::*" will match all keys in a given namespace.
1852 * Examples of strings to use:
1854 * <title>File Attribute Matcher strings and results</title>
1855 * <tgroup cols='2' align='left'><thead>
1856 * <row><entry> Matcher String </entry><entry> Matches </entry></row></thead>
1858 * <row><entry>"*"</entry><entry>matches all attributes.</entry></row>
1859 * <row><entry>"standard::is-hidden"</entry><entry>matches only the key is-hidden in the standard namespace.</entry></row>
1860 * <row><entry>"standard::type,unix::*"</entry><entry>matches the type key in the standard namespace and
1861 * all keys in the unix namespace.</entry></row>
1865 * Returns: a #GFileAttributeMatcher.
1867 GFileAttributeMatcher *
1868 g_file_attribute_matcher_new (const char *attributes)
1873 GFileAttributeMatcher *matcher;
1875 if (attributes == NULL || *attributes == '\0')
1878 matcher = g_malloc0 (sizeof (GFileAttributeMatcher));
1881 split = g_strsplit (attributes, ",", -1);
1883 for (i = 0; split[i] != NULL; i++)
1885 if (strcmp (split[i], "*") == 0)
1886 matcher->all = TRUE;
1891 colon = strstr (split[i], "::");
1892 if (colon != NULL &&
1897 id = lookup_attribute (split[i]);
1905 id = lookup_namespace (split[i]) << NS_POS;
1906 mask = NS_MASK << NS_POS;
1909 matcher_add (matcher, id, mask);
1919 * g_file_attribute_matcher_ref:
1920 * @matcher: a #GFileAttributeMatcher.
1922 * References a file attribute matcher.
1924 * Returns: a #GFileAttributeMatcher.
1926 GFileAttributeMatcher *
1927 g_file_attribute_matcher_ref (GFileAttributeMatcher *matcher)
1929 g_return_val_if_fail (matcher != NULL, NULL);
1930 g_return_val_if_fail (matcher->ref > 0, NULL);
1932 g_atomic_int_inc (&matcher->ref);
1938 * g_file_attribute_matcher_unref:
1939 * @matcher: a #GFileAttributeMatcher.
1941 * Unreferences @matcher. If the reference count falls below 1,
1942 * the @matcher is automatically freed.
1946 g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher)
1948 g_return_if_fail (matcher != NULL);
1949 g_return_if_fail (matcher->ref > 0);
1951 if (g_atomic_int_dec_and_test (&matcher->ref))
1953 if (matcher->more_sub_matchers)
1954 g_array_free (matcher->more_sub_matchers, TRUE);
1961 * g_file_attribute_matcher_matches_only:
1962 * @matcher: a #GFileAttributeMatcher.
1963 * @attribute: a file attribute key.
1965 * Checks if a attribute matcher only matches a given attribute. Always
1966 * returns %FALSE if "*" was used when creating the matcher.
1968 * Returns: %TRUE if the matcher only matches @attribute. %FALSE otherwise.
1971 g_file_attribute_matcher_matches_only (GFileAttributeMatcher *matcher,
1972 const char *attribute)
1976 g_return_val_if_fail (matcher != NULL, FALSE);
1977 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
1982 id = lookup_attribute (attribute);
1984 if (matcher->sub_matchers[0].id != 0 &&
1985 matcher->sub_matchers[1].id == 0 &&
1986 matcher->sub_matchers[0].mask == 0xffffffff &&
1987 matcher->sub_matchers[0].id == id)
1994 matcher_matches_id (GFileAttributeMatcher *matcher,
1997 SubMatcher *sub_matchers;
2000 for (i = 0; i < ON_STACK_MATCHERS; i++)
2002 if (matcher->sub_matchers[i].id == 0)
2005 if (matcher->sub_matchers[i].id == (id & matcher->sub_matchers[i].mask))
2009 if (matcher->more_sub_matchers)
2011 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
2012 for (i = 0; i < matcher->more_sub_matchers->len; i++)
2014 if (sub_matchers[i].id == (id & sub_matchers[i].mask))
2023 g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
2026 g_return_val_if_fail (matcher != NULL, FALSE);
2031 return matcher_matches_id (matcher, id);
2035 * g_file_attribute_matcher_matches:
2036 * @matcher: a #GFileAttributeMatcher.
2037 * @attribute: a file attribute key.
2039 * Checks if an attribute will be matched by an attribute matcher. If
2040 * the matcher was created with the "*" matching string, this function
2041 * will always return %TRUE.
2043 * Returns: %TRUE if @attribute matches @matcher. %FALSE otherwise.
2046 g_file_attribute_matcher_matches (GFileAttributeMatcher *matcher,
2047 const char *attribute)
2049 g_return_val_if_fail (matcher != NULL, FALSE);
2050 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
2055 return matcher_matches_id (matcher, lookup_attribute (attribute));
2058 /* return TRUE -> all */
2060 * g_file_attribute_matcher_enumerate_namespace:
2061 * @matcher: a #GFileAttributeMatcher.
2062 * @ns: a string containing a file attribute namespace.
2064 * Checks if the matcher will match all of the keys in a given namespace.
2065 * This will always return %TRUE if a wildcard character is in use (e.g. if
2066 * matcher was created with "standard::*" and @ns is "standard", or if matcher was created
2067 * using "*" and namespace is anything.)
2069 * TODO: this is awkwardly worded.
2071 * Returns: %TRUE if the matcher matches all of the entries
2072 * in the given @ns, %FALSE otherwise.
2075 g_file_attribute_matcher_enumerate_namespace (GFileAttributeMatcher *matcher,
2078 SubMatcher *sub_matchers;
2082 g_return_val_if_fail (matcher != NULL, FALSE);
2083 g_return_val_if_fail (ns != NULL && *ns != '\0', FALSE);
2088 ns_id = lookup_namespace (ns) << NS_POS;
2090 for (i = 0; i < ON_STACK_MATCHERS; i++)
2092 if (matcher->sub_matchers[i].id == ns_id)
2096 if (matcher->more_sub_matchers)
2098 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
2099 for (i = 0; i < matcher->more_sub_matchers->len; i++)
2101 if (sub_matchers[i].id == ns_id)
2106 matcher->iterator_ns = ns_id;
2107 matcher->iterator_pos = 0;
2113 * g_file_attribute_matcher_enumerate_next:
2114 * @matcher: a #GFileAttributeMatcher.
2116 * Gets the next matched attribute from a #GFileAttributeMatcher.
2118 * Returns: a string containing the next attribute or %NULL if
2119 * no more attribute exist.
2122 g_file_attribute_matcher_enumerate_next (GFileAttributeMatcher *matcher)
2125 SubMatcher *sub_matcher;
2127 g_return_val_if_fail (matcher != NULL, NULL);
2131 i = matcher->iterator_pos++;
2133 if (i < ON_STACK_MATCHERS)
2135 if (matcher->sub_matchers[i].id == 0)
2138 sub_matcher = &matcher->sub_matchers[i];
2142 if (matcher->more_sub_matchers == NULL)
2145 i -= ON_STACK_MATCHERS;
2146 if (i < matcher->more_sub_matchers->len)
2147 sub_matcher = &g_array_index (matcher->more_sub_matchers, SubMatcher, i);
2152 if (sub_matcher->mask == 0xffffffff &&
2153 (sub_matcher->id & (NS_MASK << NS_POS)) == matcher->iterator_ns)
2154 return get_attribute_for_id (sub_matcher->id);
2158 #define __G_FILE_INFO_C__
2159 #include "gioaliasdef.c"