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 * To change the actual attributes of a file, you should then set the
42 * attribute in the #GFileInfo and call g_file_set_attributes_from_info()
43 * or g_file_set_attributes_async() on a GFile.
45 * However, not all attributes can be changed in the file. For instance,
46 * the actual size of a file cannot be changed via g_file_info_set_size().
47 * You may call g_file_query_settable_attributes() and
48 * g_file_query_writable_namespaces() to discover the settable attributes
49 * of a particular file at runtime.
51 * #GFileAttributeMatcher allows for searching through a #GFileInfo for
59 #include "gfileinfo.h"
60 #include "gfileattribute-priv.h"
65 /* We use this nasty thing, because NULL is a valid attribute matcher (matches nothing) */
66 #define NO_ATTRIBUTE_MASK ((GFileAttributeMatcher *)1)
70 GFileAttributeValue value;
75 GObject parent_instance;
78 GFileAttributeMatcher *mask;
81 struct _GFileInfoClass
83 GObjectClass parent_class;
87 static gboolean g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
90 G_DEFINE_TYPE (GFileInfo, g_file_info, G_TYPE_OBJECT);
94 guint32 attribute_id_counter;
97 G_LOCK_DEFINE_STATIC (attribute_hash);
98 static int namespace_id_counter = 0;
99 static GHashTable *ns_hash = NULL;
100 static GHashTable *attribute_hash = NULL;
101 static char ***attributes = NULL;
103 /* Attribute ids are 32bit, we split it up like this:
104 * |------------|--------------------|
106 * namespace attribute id
108 * This way the attributes gets sorted in namespace order
112 #define NS_MASK ((guint32)((1<<12) - 1))
114 #define ID_MASK ((guint32)((1<<20) - 1))
116 #define GET_NS(_attr_id) \
117 (((guint32) (_attr_id) >> NS_POS) & NS_MASK)
118 #define GET_ID(_attr_id) \
119 (((guint32)(_attr_id) >> ID_POS) & ID_MASK)
121 #define MAKE_ATTR_ID(_ns, _id) \
122 ( ((((guint32) _ns) & NS_MASK) << NS_POS) | \
123 ((((guint32) _id) & ID_MASK) << ID_POS) )
126 _lookup_namespace (const char *namespace)
130 ns_info = g_hash_table_lookup (ns_hash, namespace);
133 ns_info = g_new0 (NSInfo, 1);
134 ns_info->id = ++namespace_id_counter;
135 g_hash_table_insert (ns_hash, g_strdup (namespace), ns_info);
136 attributes = g_realloc (attributes, (ns_info->id + 1) * sizeof (char **));
137 attributes[ns_info->id] = NULL;
143 lookup_namespace (const char *namespace)
148 G_LOCK (attribute_hash);
150 if (attribute_hash == NULL)
152 ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
153 attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
156 ns_info = _lookup_namespace (namespace);
161 G_UNLOCK (attribute_hash);
167 get_attribute_for_id (int attribute)
170 G_LOCK (attribute_hash);
171 s = attributes[GET_NS(attribute)][GET_ID(attribute)];
172 G_UNLOCK (attribute_hash);
177 lookup_attribute (const char *attribute)
184 G_LOCK (attribute_hash);
185 if (attribute_hash == NULL)
187 ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
188 attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
191 attr_id = GPOINTER_TO_UINT (g_hash_table_lookup (attribute_hash, attribute));
195 G_UNLOCK (attribute_hash);
199 colon = strstr (attribute, "::");
201 ns = g_strndup (attribute, colon - attribute);
205 ns_info = _lookup_namespace (ns);
208 id = ++ns_info->attribute_id_counter;
209 attributes[ns_info->id] = g_realloc (attributes[ns_info->id], (id + 1) * sizeof (char *));
210 attributes[ns_info->id][id] = g_strdup (attribute);
212 attr_id = MAKE_ATTR_ID (ns_info->id, id);
214 g_hash_table_insert (attribute_hash, attributes[ns_info->id][id], GUINT_TO_POINTER (attr_id));
216 G_UNLOCK (attribute_hash);
222 g_file_info_finalize (GObject *object)
226 GFileAttribute *attrs;
228 info = G_FILE_INFO (object);
230 attrs = (GFileAttribute *)info->attributes->data;
231 for (i = 0; i < info->attributes->len; i++)
232 _g_file_attribute_value_clear (&attrs[i].value);
233 g_array_free (info->attributes, TRUE);
235 if (info->mask != NO_ATTRIBUTE_MASK)
236 g_file_attribute_matcher_unref (info->mask);
238 G_OBJECT_CLASS (g_file_info_parent_class)->finalize (object);
242 g_file_info_class_init (GFileInfoClass *klass)
244 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
246 gobject_class->finalize = g_file_info_finalize;
250 g_file_info_init (GFileInfo *info)
252 info->mask = NO_ATTRIBUTE_MASK;
253 info->attributes = g_array_new (FALSE, FALSE,
254 sizeof (GFileAttribute));
260 * Creates a new file info structure.
262 * Returns: a #GFileInfo.
265 g_file_info_new (void)
267 return g_object_new (G_TYPE_FILE_INFO, NULL);
271 * g_file_info_copy_into:
272 * @src_info: source to copy attributes from.
273 * @dest_info: destination to copy attributes to.
275 * Copies all of the #GFileAttribute<!-- -->s from @src_info to @dest_info.
278 g_file_info_copy_into (GFileInfo *src_info,
279 GFileInfo *dest_info)
281 GFileAttribute *source, *dest;
284 g_return_if_fail (G_IS_FILE_INFO (src_info));
285 g_return_if_fail (G_IS_FILE_INFO (dest_info));
287 dest = (GFileAttribute *)dest_info->attributes->data;
288 for (i = 0; i < dest_info->attributes->len; i++)
289 _g_file_attribute_value_clear (&dest[i].value);
291 g_array_set_size (dest_info->attributes,
292 src_info->attributes->len);
294 source = (GFileAttribute *)src_info->attributes->data;
295 dest = (GFileAttribute *)dest_info->attributes->data;
297 for (i = 0; i < src_info->attributes->len; i++)
299 dest[i].attribute = source[i].attribute;
300 dest[i].value.type = G_FILE_ATTRIBUTE_TYPE_INVALID;
301 _g_file_attribute_value_set (&dest[i].value, &source[i].value);
304 if (src_info->mask == NO_ATTRIBUTE_MASK)
305 dest_info->mask = NO_ATTRIBUTE_MASK;
307 dest_info->mask = g_file_attribute_matcher_ref (src_info->mask);
312 * @other: a #GFileInfo.
314 * Duplicates a file info structure.
316 * Returns: a duplicate #GFileInfo of @other.
319 g_file_info_dup (GFileInfo *other)
323 g_return_val_if_fail (G_IS_FILE_INFO (other), NULL);
325 new = g_file_info_new ();
326 g_file_info_copy_into (other, new);
331 * g_file_info_set_attribute_mask:
332 * @info: a #GFileInfo.
333 * @mask: a #GFileAttributeMatcher.
335 * Sets @mask on @info to match specific attribute types.
338 g_file_info_set_attribute_mask (GFileInfo *info,
339 GFileAttributeMatcher *mask)
341 GFileAttribute *attr;
344 g_return_if_fail (G_IS_FILE_INFO (info));
346 if (mask != info->mask)
348 if (info->mask != NO_ATTRIBUTE_MASK)
349 g_file_attribute_matcher_unref (info->mask);
350 info->mask = g_file_attribute_matcher_ref (mask);
352 /* Remove non-matching attributes */
353 for (i = 0; i < info->attributes->len; i++)
355 attr = &g_array_index (info->attributes, GFileAttribute, i);
356 if (!g_file_attribute_matcher_matches_id (mask,
359 _g_file_attribute_value_clear (&attr->value);
360 g_array_remove_index (info->attributes, i);
368 * g_file_info_unset_attribute_mask:
371 * Unsets a mask set by g_file_info_set_attribute_mask(), if one
375 g_file_info_unset_attribute_mask (GFileInfo *info)
377 g_return_if_fail (G_IS_FILE_INFO (info));
379 if (info->mask != NO_ATTRIBUTE_MASK)
380 g_file_attribute_matcher_unref (info->mask);
381 info->mask = NO_ATTRIBUTE_MASK;
385 * g_file_info_clear_status:
386 * @info: a #GFileInfo.
388 * Clears the status information from @info.
391 g_file_info_clear_status (GFileInfo *info)
393 GFileAttribute *attrs;
396 g_return_if_fail (G_IS_FILE_INFO (info));
398 attrs = (GFileAttribute *)info->attributes->data;
399 for (i = 0; i < info->attributes->len; i++)
400 attrs[i].value.status = G_FILE_ATTRIBUTE_STATUS_UNSET;
404 g_file_info_find_place (GFileInfo *info,
408 GFileAttribute *attrs;
409 /* Binary search for the place where attribute would be, if its
413 max = info->attributes->len;
415 attrs = (GFileAttribute *)info->attributes->data;
419 med = min + (max - min) / 2;
420 if (attrs[med].attribute == attribute)
425 else if (attrs[med].attribute < attribute)
427 else /* attrs[med].attribute > attribute */
434 static GFileAttributeValue *
435 g_file_info_find_value (GFileInfo *info,
438 GFileAttribute *attrs;
441 i = g_file_info_find_place (info, attr_id);
442 attrs = (GFileAttribute *)info->attributes->data;
443 if (i < info->attributes->len &&
444 attrs[i].attribute == attr_id)
445 return &attrs[i].value;
450 static GFileAttributeValue *
451 g_file_info_find_value_by_name (GFileInfo *info,
452 const char *attribute)
456 attr_id = lookup_attribute (attribute);
457 return g_file_info_find_value (info, attr_id);
461 * g_file_info_has_attribute:
462 * @info: a #GFileInfo.
463 * @attribute: a file attribute key.
465 * Checks if a file info structure has an attribute named @attribute.
467 * Returns: %TRUE if @Ginfo has an attribute named @attribute,
471 g_file_info_has_attribute (GFileInfo *info,
472 const char *attribute)
474 GFileAttributeValue *value;
476 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
477 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
479 value = g_file_info_find_value_by_name (info, attribute);
480 return value != NULL;
484 * g_file_info_list_attributes:
485 * @info: a #GFileInfo.
486 * @name_space: a file attribute key's namespace.
488 * Lists the file info structure's attributes.
490 * Returns: a null-terminated array of strings of all of the
491 * possible attribute types for the given @name_space, or
495 g_file_info_list_attributes (GFileInfo *info,
496 const char *name_space)
499 GFileAttribute *attrs;
501 guint32 ns_id = (name_space) ? lookup_namespace (name_space) : 0;
504 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
506 names = g_ptr_array_new ();
507 attrs = (GFileAttribute *)info->attributes->data;
508 for (i = 0; i < info->attributes->len; i++)
510 attribute = attrs[i].attribute;
511 if (ns_id == 0 || GET_NS (attribute) == ns_id)
512 g_ptr_array_add (names, g_strdup (get_attribute_for_id (attribute)));
516 g_ptr_array_add (names, NULL);
518 return (char **)g_ptr_array_free (names, FALSE);
522 * g_file_info_get_attribute_type:
523 * @info: a #GFileInfo.
524 * @attribute: a file attribute key.
526 * Gets the attribute type for an attribute key.
528 * Returns: a #GFileAttributeType for the given @attribute, or
529 * %G_FILE_ATTRIBUTE_TYPE_INVALID if the key is invalid.
532 g_file_info_get_attribute_type (GFileInfo *info,
533 const char *attribute)
535 GFileAttributeValue *value;
537 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_ATTRIBUTE_TYPE_INVALID);
538 g_return_val_if_fail (attribute != NULL && *attribute != '\0', G_FILE_ATTRIBUTE_TYPE_INVALID);
540 value = g_file_info_find_value_by_name (info, attribute);
544 return G_FILE_ATTRIBUTE_TYPE_INVALID;
548 * g_file_info_remove_attribute:
549 * @info: a #GFileInfo.
550 * @attribute: a file attribute key.
552 * Removes all cases of @attribute from @info if it exists.
555 g_file_info_remove_attribute (GFileInfo *info,
556 const char *attribute)
559 GFileAttribute *attrs;
562 g_return_if_fail (G_IS_FILE_INFO (info));
563 g_return_if_fail (attribute != NULL && *attribute != '\0');
565 attr_id = lookup_attribute (attribute);
567 i = g_file_info_find_place (info, attr_id);
568 attrs = (GFileAttribute *)info->attributes->data;
569 if (i < info->attributes->len &&
570 attrs[i].attribute == attr_id)
572 _g_file_attribute_value_clear (&attrs[i].value);
573 g_array_remove_index (info->attributes, i);
578 * g_file_info_get_attribute_data:
579 * @info: a #GFileInfo
580 * @attribute: a file attribute key
581 * @type: return location for the attribute type, or %NULL
582 * @value_pp: return location for the attribute value, or %NULL
583 * @status: return location for the attribute status, or %NULL
585 * Gets the attribute type, value and status for an attribute key.
587 * Returns: %TRUE if @info has an attribute named @attribute,
591 g_file_info_get_attribute_data (GFileInfo *info,
592 const char *attribute,
593 GFileAttributeType *type,
595 GFileAttributeStatus *status)
597 GFileAttributeValue *value;
599 value = g_file_info_find_value_by_name (info, attribute);
604 *status = value->status;
610 *value_pp = _g_file_attribute_value_peek_as_pointer (value);
616 * g_file_info_get_attribute_status:
617 * @info: a #GFileInfo
618 * @attribute: a file attribute key
620 * Gets the attribute status for an attribute key.
622 * Returns: a #GFileAttributeStatus for the given @attribute, or
623 * %G_FILE_ATTRIBUTE_STATUS_UNSET if the key is invalid.
627 g_file_info_get_attribute_status (GFileInfo *info,
628 const char *attribute)
630 GFileAttributeValue *val;
632 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
633 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
635 val = g_file_info_find_value_by_name (info, attribute);
639 return G_FILE_ATTRIBUTE_STATUS_UNSET;
643 GFileAttributeValue *
644 _g_file_info_get_attribute_value (GFileInfo *info,
645 const char *attribute)
648 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
649 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
651 return g_file_info_find_value_by_name (info, attribute);
655 * g_file_info_get_attribute_as_string:
656 * @info: a #GFileInfo.
657 * @attribute: a file attribute key.
659 * Gets the value of a attribute, formated as a string.
660 * This escapes things as needed to make the string valid
663 * Returns: a UTF-8 string associated with the given @attribute.
664 * When you're done with the string it must be freed with g_free().
667 g_file_info_get_attribute_as_string (GFileInfo *info,
668 const char *attribute)
670 GFileAttributeValue *val;
671 val = _g_file_info_get_attribute_value (info, attribute);
673 return _g_file_attribute_value_as_string (val);
679 * g_file_info_get_attribute_object:
680 * @info: a #GFileInfo.
681 * @attribute: a file attribute key.
683 * Gets the value of a #GObject attribute. If the attribute does
684 * not contain a #GObject, %NULL will be returned.
686 * Returns: a #GObject associated with the given @attribute, or
690 g_file_info_get_attribute_object (GFileInfo *info,
691 const char *attribute)
693 GFileAttributeValue *value;
695 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
696 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
698 value = g_file_info_find_value_by_name (info, attribute);
699 return _g_file_attribute_value_get_object (value);
703 * g_file_info_get_attribute_string:
704 * @info: a #GFileInfo.
705 * @attribute: a file attribute key.
707 * Gets the value of a string attribute. If the attribute does
708 * not contain a string, %NULL will be returned.
710 * Returns: the contents of the @attribute value as a string, or
714 g_file_info_get_attribute_string (GFileInfo *info,
715 const char *attribute)
717 GFileAttributeValue *value;
719 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
720 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
722 value = g_file_info_find_value_by_name (info, attribute);
723 return _g_file_attribute_value_get_string (value);
727 * g_file_info_get_attribute_byte_string:
728 * @info: a #GFileInfo.
729 * @attribute: a file attribute key.
731 * Gets the value of a byte string attribute. If the attribute does
732 * not contain a byte string, %NULL will be returned.
734 * Returns: the contents of the @attribute value as a byte string, or
738 g_file_info_get_attribute_byte_string (GFileInfo *info,
739 const char *attribute)
741 GFileAttributeValue *value;
743 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
744 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
746 value = g_file_info_find_value_by_name (info, attribute);
747 return _g_file_attribute_value_get_byte_string (value);
751 * g_file_info_get_attribute_boolean:
752 * @info: a #GFileInfo.
753 * @attribute: a file attribute key.
755 * Gets the value of a boolean attribute. If the attribute does not
756 * contain a boolean value, %FALSE will be returned.
758 * Returns: the boolean value contained within the attribute.
761 g_file_info_get_attribute_boolean (GFileInfo *info,
762 const char *attribute)
764 GFileAttributeValue *value;
766 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
767 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
769 value = g_file_info_find_value_by_name (info, attribute);
770 return _g_file_attribute_value_get_boolean (value);
774 * g_file_info_get_attribute_uint32:
775 * @info: a #GFileInfo.
776 * @attribute: a file attribute key.
778 * Gets an unsigned 32-bit integer contained within the attribute. If the
779 * attribute does not contain an unsigned 32-bit integer, or is invalid,
780 * 0 will be returned.
782 * Returns: an unsigned 32-bit integer from the attribute.
785 g_file_info_get_attribute_uint32 (GFileInfo *info,
786 const char *attribute)
788 GFileAttributeValue *value;
790 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
791 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
793 value = g_file_info_find_value_by_name (info, attribute);
794 return _g_file_attribute_value_get_uint32 (value);
798 * g_file_info_get_attribute_int32:
799 * @info: a #GFileInfo.
800 * @attribute: a file attribute key.
802 * Gets a signed 32-bit integer contained within the attribute. If the
803 * attribute does not contain a signed 32-bit integer, or is invalid,
804 * 0 will be returned.
806 * Returns: a signed 32-bit integer from the attribute.
809 g_file_info_get_attribute_int32 (GFileInfo *info,
810 const char *attribute)
812 GFileAttributeValue *value;
814 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
815 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
817 value = g_file_info_find_value_by_name (info, attribute);
818 return _g_file_attribute_value_get_int32 (value);
822 * g_file_info_get_attribute_uint64:
823 * @info: a #GFileInfo.
824 * @attribute: a file attribute key.
826 * Gets a unsigned 64-bit integer contained within the attribute. If the
827 * attribute does not contain an unsigned 64-bit integer, or is invalid,
828 * 0 will be returned.
830 * Returns: a unsigned 64-bit integer from the attribute.
833 g_file_info_get_attribute_uint64 (GFileInfo *info,
834 const char *attribute)
836 GFileAttributeValue *value;
838 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
839 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
841 value = g_file_info_find_value_by_name (info, attribute);
842 return _g_file_attribute_value_get_uint64 (value);
846 * g_file_info_get_attribute_int64:
847 * @info: a #GFileInfo.
848 * @attribute: a file attribute key.
850 * Gets a signed 64-bit integer contained within the attribute. If the
851 * attribute does not contain an signed 64-bit integer, or is invalid,
852 * 0 will be returned.
854 * Returns: a signed 64-bit integer from the attribute.
857 g_file_info_get_attribute_int64 (GFileInfo *info,
858 const char *attribute)
860 GFileAttributeValue *value;
862 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
863 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
865 value = g_file_info_find_value_by_name (info, attribute);
866 return _g_file_attribute_value_get_int64 (value);
869 static GFileAttributeValue *
870 g_file_info_create_value (GFileInfo *info,
873 GFileAttribute *attrs;
876 if (info->mask != NO_ATTRIBUTE_MASK &&
877 !g_file_attribute_matcher_matches_id (info->mask, attr_id))
880 i = g_file_info_find_place (info, attr_id);
882 attrs = (GFileAttribute *)info->attributes->data;
883 if (i < info->attributes->len &&
884 attrs[i].attribute == attr_id)
885 return &attrs[i].value;
888 GFileAttribute attr = { 0 };
889 attr.attribute = attr_id;
890 g_array_insert_val (info->attributes, i, attr);
892 attrs = (GFileAttribute *)info->attributes->data;
893 return &attrs[i].value;
897 static GFileAttributeValue *
898 g_file_info_create_value_by_name (GFileInfo *info,
899 const char *attribute)
903 attr_id = lookup_attribute (attribute);
905 return g_file_info_create_value (info, attr_id);
909 * g_file_info_set_attribute:
910 * @info: a #GFileInfo.
911 * @attribute: a file attribute key.
912 * @type: a #GFileAttributeType
913 * @value_p: pointer to the value
915 * Sets the @attribute to contain the given value, if possible.
918 g_file_info_set_attribute (GFileInfo *info,
919 const char *attribute,
920 GFileAttributeType type,
923 GFileAttributeValue *value;
925 g_return_if_fail (G_IS_FILE_INFO (info));
926 g_return_if_fail (attribute != NULL && *attribute != '\0');
928 value = g_file_info_create_value_by_name (info, attribute);
931 _g_file_attribute_value_set_from_pointer (value, type, value_p, TRUE);
935 * g_file_info_set_attribute_object:
936 * @info: a #GFileInfo.
937 * @attribute: a file attribute key.
938 * @attr_value: a #GObject.
940 * Sets the @attribute to contain the given @attr_value,
944 g_file_info_set_attribute_object (GFileInfo *info,
945 const char *attribute,
948 GFileAttributeValue *value;
950 g_return_if_fail (G_IS_FILE_INFO (info));
951 g_return_if_fail (attribute != NULL && *attribute != '\0');
952 g_return_if_fail (G_IS_OBJECT (attr_value));
954 value = g_file_info_create_value_by_name (info, attribute);
956 _g_file_attribute_value_set_object (value, attr_value);
960 * g_file_info_set_attribute_string:
961 * @info: a #GFileInfo.
962 * @attribute: a file attribute key.
963 * @attr_value: a string.
965 * Sets the @attribute to contain the given @attr_value,
969 g_file_info_set_attribute_string (GFileInfo *info,
970 const char *attribute,
971 const char *attr_value)
973 GFileAttributeValue *value;
975 g_return_if_fail (G_IS_FILE_INFO (info));
976 g_return_if_fail (attribute != NULL && *attribute != '\0');
977 g_return_if_fail (attr_value != NULL);
979 value = g_file_info_create_value_by_name (info, attribute);
981 _g_file_attribute_value_set_string (value, attr_value);
985 * g_file_info_set_attribute_byte_string:
986 * @info: a #GFileInfo.
987 * @attribute: a file attribute key.
988 * @attr_value: a byte string.
990 * Sets the @attribute to contain the given @attr_value,
994 g_file_info_set_attribute_byte_string (GFileInfo *info,
995 const char *attribute,
996 const char *attr_value)
998 GFileAttributeValue *value;
1000 g_return_if_fail (G_IS_FILE_INFO (info));
1001 g_return_if_fail (attribute != NULL && *attribute != '\0');
1002 g_return_if_fail (attr_value != NULL);
1004 value = g_file_info_create_value_by_name (info, attribute);
1006 _g_file_attribute_value_set_byte_string (value, attr_value);
1010 * g_file_info_set_attribute_boolean:
1011 * @info: a #GFileInfo.
1012 * @attribute: a file attribute key.
1013 * @attr_value: a boolean value.
1015 * Sets the @attribute to contain the given @attr_value,
1019 g_file_info_set_attribute_boolean (GFileInfo *info,
1020 const char *attribute,
1021 gboolean attr_value)
1023 GFileAttributeValue *value;
1025 g_return_if_fail (G_IS_FILE_INFO (info));
1026 g_return_if_fail (attribute != NULL && *attribute != '\0');
1028 value = g_file_info_create_value_by_name (info, attribute);
1030 _g_file_attribute_value_set_boolean (value, attr_value);
1034 * g_file_info_set_attribute_uint32:
1035 * @info: a #GFileInfo.
1036 * @attribute: a file attribute key.
1037 * @attr_value: an unsigned 32-bit integer.
1039 * Sets the @attribute to contain the given @attr_value,
1043 g_file_info_set_attribute_uint32 (GFileInfo *info,
1044 const char *attribute,
1047 GFileAttributeValue *value;
1049 g_return_if_fail (G_IS_FILE_INFO (info));
1050 g_return_if_fail (attribute != NULL && *attribute != '\0');
1052 value = g_file_info_create_value_by_name (info, attribute);
1054 _g_file_attribute_value_set_uint32 (value, attr_value);
1059 * g_file_info_set_attribute_int32:
1060 * @info: a #GFileInfo.
1061 * @attribute: a file attribute key.
1062 * @attr_value: a signed 32-bit integer
1064 * Sets the @attribute to contain the given @attr_value,
1068 g_file_info_set_attribute_int32 (GFileInfo *info,
1069 const char *attribute,
1072 GFileAttributeValue *value;
1074 g_return_if_fail (G_IS_FILE_INFO (info));
1075 g_return_if_fail (attribute != NULL && *attribute != '\0');
1077 value = g_file_info_create_value_by_name (info, attribute);
1079 _g_file_attribute_value_set_int32 (value, attr_value);
1083 * g_file_info_set_attribute_uint64:
1084 * @info: a #GFileInfo.
1085 * @attribute: a file attribute key.
1086 * @attr_value: an unsigned 64-bit integer.
1088 * Sets the @attribute to contain the given @attr_value,
1092 g_file_info_set_attribute_uint64 (GFileInfo *info,
1093 const char *attribute,
1096 GFileAttributeValue *value;
1098 g_return_if_fail (G_IS_FILE_INFO (info));
1099 g_return_if_fail (attribute != NULL && *attribute != '\0');
1101 value = g_file_info_create_value_by_name (info, attribute);
1103 _g_file_attribute_value_set_uint64 (value, attr_value);
1107 * g_file_info_set_attribute_int64:
1108 * @info: a #GFileInfo.
1109 * @attribute: attribute name to set.
1110 * @attr_value: int64 value to set attribute to.
1112 * Sets the @attribute to contain the given @attr_value,
1117 g_file_info_set_attribute_int64 (GFileInfo *info,
1118 const char *attribute,
1121 GFileAttributeValue *value;
1123 g_return_if_fail (G_IS_FILE_INFO (info));
1124 g_return_if_fail (attribute != NULL && *attribute != '\0');
1126 value = g_file_info_create_value_by_name (info, attribute);
1128 _g_file_attribute_value_set_int64 (value, attr_value);
1131 /* Helper getters */
1133 * g_file_info_get_file_type:
1134 * @info: a #GFileInfo.
1136 * Gets a file's type (whether it is a regular file, symlink, etc).
1137 * This is different from the file's content type, see g_file_info_get_content_type().
1139 * Returns: a #GFileType for the given file.
1142 g_file_info_get_file_type (GFileInfo *info)
1144 static guint32 attr = 0;
1145 GFileAttributeValue *value;
1147 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_TYPE_UNKNOWN);
1150 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
1152 value = g_file_info_find_value (info, attr);
1153 return (GFileType)_g_file_attribute_value_get_uint32 (value);
1157 * g_file_info_get_is_hidden:
1158 * @info: a #GFileInfo.
1160 * Checks if a file is hidden.
1162 * Returns: %TRUE if the file is a hidden file, %FALSE otherwise.
1165 g_file_info_get_is_hidden (GFileInfo *info)
1167 static guint32 attr = 0;
1168 GFileAttributeValue *value;
1170 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1173 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
1175 value = g_file_info_find_value (info, attr);
1176 return (GFileType)_g_file_attribute_value_get_boolean (value);
1180 * g_file_info_get_is_backup:
1181 * @info: a #GFileInfo.
1183 * Checks if a file is a backup file.
1185 * Returns: %TRUE if file is a backup file, %FALSE otherwise.
1188 g_file_info_get_is_backup (GFileInfo *info)
1190 static guint32 attr = 0;
1191 GFileAttributeValue *value;
1193 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1196 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
1198 value = g_file_info_find_value (info, attr);
1199 return (GFileType)_g_file_attribute_value_get_boolean (value);
1203 * g_file_info_get_is_symlink:
1204 * @info: a #GFileInfo.
1206 * Checks if a file is a symlink.
1208 * Returns: %TRUE if the given @info is a symlink.
1211 g_file_info_get_is_symlink (GFileInfo *info)
1213 static guint32 attr = 0;
1214 GFileAttributeValue *value;
1216 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1219 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
1221 value = g_file_info_find_value (info, attr);
1222 return (GFileType)_g_file_attribute_value_get_boolean (value);
1226 * g_file_info_get_name:
1227 * @info: a #GFileInfo.
1229 * Gets the name for a file.
1231 * Returns: a string containing the file name.
1234 g_file_info_get_name (GFileInfo *info)
1236 static guint32 attr = 0;
1237 GFileAttributeValue *value;
1239 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1242 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
1244 value = g_file_info_find_value (info, attr);
1245 return _g_file_attribute_value_get_byte_string (value);
1249 * g_file_info_get_display_name:
1250 * @info: a #GFileInfo.
1252 * Gets a display name for a file.
1254 * Returns: a string containing the display name.
1257 g_file_info_get_display_name (GFileInfo *info)
1259 static guint32 attr = 0;
1260 GFileAttributeValue *value;
1262 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1265 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
1267 value = g_file_info_find_value (info, attr);
1268 return _g_file_attribute_value_get_string (value);
1272 * g_file_info_get_edit_name:
1273 * @info: a #GFileInfo.
1275 * Gets the edit name for a file.
1277 * Returns: a string containing the edit name.
1280 g_file_info_get_edit_name (GFileInfo *info)
1282 static guint32 attr = 0;
1283 GFileAttributeValue *value;
1285 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1288 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
1290 value = g_file_info_find_value (info, attr);
1291 return _g_file_attribute_value_get_string (value);
1295 * g_file_info_get_icon:
1296 * @info: a #GFileInfo.
1298 * Gets the icon for a file.
1300 * Returns: #GIcon for the given @info.
1303 g_file_info_get_icon (GFileInfo *info)
1305 static guint32 attr = 0;
1306 GFileAttributeValue *value;
1309 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1312 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
1314 value = g_file_info_find_value (info, attr);
1315 obj = _g_file_attribute_value_get_object (value);
1316 if (G_IS_ICON (obj))
1317 return G_ICON (obj);
1322 * g_file_info_get_content_type:
1323 * @info: a #GFileInfo.
1325 * Gets the file's content type.
1327 * Returns: a string containing the file's content type.s
1330 g_file_info_get_content_type (GFileInfo *info)
1332 static guint32 attr = 0;
1333 GFileAttributeValue *value;
1335 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1338 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1340 value = g_file_info_find_value (info, attr);
1341 return _g_file_attribute_value_get_string (value);
1345 * g_file_info_get_size:
1346 * @info: a #GFileInfo.
1348 * Gets the file's size.
1350 * Returns: a #goffset containing the file's size.
1353 g_file_info_get_size (GFileInfo *info)
1355 static guint32 attr = 0;
1356 GFileAttributeValue *value;
1358 g_return_val_if_fail (G_IS_FILE_INFO (info), (goffset) 0);
1361 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
1363 value = g_file_info_find_value (info, attr);
1364 return (goffset) _g_file_attribute_value_get_uint64 (value);
1368 * g_file_info_get_modification_time:
1369 * @info: a #GFileInfo.
1370 * @result: a #GTimeVal.
1372 * Gets the modification time of the current @info and sets it
1376 g_file_info_get_modification_time (GFileInfo *info,
1379 static guint32 attr_mtime = 0, attr_mtime_usec;
1380 GFileAttributeValue *value;
1382 g_return_if_fail (G_IS_FILE_INFO (info));
1383 g_return_if_fail (result != NULL);
1385 if (attr_mtime == 0)
1387 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1388 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1391 value = g_file_info_find_value (info, attr_mtime);
1392 result->tv_sec = _g_file_attribute_value_get_uint64 (value);
1393 value = g_file_info_find_value (info, attr_mtime_usec);
1394 result->tv_usec = _g_file_attribute_value_get_uint32 (value);
1398 * g_file_info_get_symlink_target:
1399 * @info: a #GFileInfo.
1401 * Gets the symlink target for a given #GFileInfo.
1403 * Returns: a string containing the symlink target.
1406 g_file_info_get_symlink_target (GFileInfo *info)
1408 static guint32 attr = 0;
1409 GFileAttributeValue *value;
1411 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1414 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
1416 value = g_file_info_find_value (info, attr);
1417 return _g_file_attribute_value_get_byte_string (value);
1421 * g_file_info_get_etag:
1422 * @info: a #GFileInfo.
1424 * Gets the <link linkend="gfile-etag">entity tag</link> for a given
1425 * #GFileInfo. See %G_FILE_ATTRIBUTE_ETAG_VALUE.
1427 * Returns: a string containing the value of the "etag:value" attribute.
1430 g_file_info_get_etag (GFileInfo *info)
1432 static guint32 attr = 0;
1433 GFileAttributeValue *value;
1435 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1438 attr = lookup_attribute (G_FILE_ATTRIBUTE_ETAG_VALUE);
1440 value = g_file_info_find_value (info, attr);
1441 return _g_file_attribute_value_get_string (value);
1445 * g_file_info_get_sort_order:
1446 * @info: a #GFileInfo.
1448 * Gets the value of the sort_order attribute from the #GFileInfo.
1449 * See %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
1451 * Returns: a #gint32 containing the value of the "standard::sort_order" attribute.
1454 g_file_info_get_sort_order (GFileInfo *info)
1456 static guint32 attr = 0;
1457 GFileAttributeValue *value;
1459 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1462 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
1464 value = g_file_info_find_value (info, attr);
1465 return _g_file_attribute_value_get_int32 (value);
1468 /* Helper setters: */
1470 * g_file_info_set_file_type:
1471 * @info: a #GFileInfo.
1472 * @type: a #GFileType.
1474 * Sets the file type in a #GFileInfo to @type.
1475 * See %G_FILE_ATTRIBUTE_STANDARD_TYPE.
1478 g_file_info_set_file_type (GFileInfo *info,
1481 static guint32 attr = 0;
1482 GFileAttributeValue *value;
1484 g_return_if_fail (G_IS_FILE_INFO (info));
1487 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
1489 value = g_file_info_create_value (info, attr);
1491 _g_file_attribute_value_set_uint32 (value, type);
1495 * g_file_info_set_is_hidden:
1496 * @info: a #GFileInfo.
1497 * @is_hidden: a #gboolean.
1499 * Sets the "is_hidden" attribute in a #GFileInfo according to @is_symlink.
1500 * See %G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN.
1503 g_file_info_set_is_hidden (GFileInfo *info,
1506 static guint32 attr = 0;
1507 GFileAttributeValue *value;
1509 g_return_if_fail (G_IS_FILE_INFO (info));
1512 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
1514 value = g_file_info_create_value (info, attr);
1516 _g_file_attribute_value_set_boolean (value, is_hidden);
1520 * g_file_info_set_is_symlink:
1521 * @info: a #GFileInfo.
1522 * @is_symlink: a #gboolean.
1524 * Sets the "is_symlink" attribute in a #GFileInfo according to @is_symlink.
1525 * See %G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK.
1528 g_file_info_set_is_symlink (GFileInfo *info,
1529 gboolean is_symlink)
1531 static guint32 attr = 0;
1532 GFileAttributeValue *value;
1534 g_return_if_fail (G_IS_FILE_INFO (info));
1537 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
1539 value = g_file_info_create_value (info, attr);
1541 _g_file_attribute_value_set_boolean (value, is_symlink);
1545 * g_file_info_set_name:
1546 * @info: a #GFileInfo.
1547 * @name: a string containing a name.
1549 * Sets the name attribute for the current #GFileInfo.
1550 * See %G_FILE_ATTRIBUTE_STANDARD_NAME.
1553 g_file_info_set_name (GFileInfo *info,
1556 static guint32 attr = 0;
1557 GFileAttributeValue *value;
1559 g_return_if_fail (G_IS_FILE_INFO (info));
1560 g_return_if_fail (name != NULL);
1563 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
1565 value = g_file_info_create_value (info, attr);
1567 _g_file_attribute_value_set_byte_string (value, name);
1571 * g_file_info_set_display_name:
1572 * @info: a #GFileInfo.
1573 * @display_name: a string containing a display name.
1575 * Sets the display name for the current #GFileInfo.
1576 * See %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.
1579 g_file_info_set_display_name (GFileInfo *info,
1580 const char *display_name)
1582 static guint32 attr = 0;
1583 GFileAttributeValue *value;
1585 g_return_if_fail (G_IS_FILE_INFO (info));
1586 g_return_if_fail (display_name != NULL);
1589 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
1591 value = g_file_info_create_value (info, attr);
1593 _g_file_attribute_value_set_string (value, display_name);
1597 * g_file_info_set_edit_name:
1598 * @info: a #GFileInfo.
1599 * @edit_name: a string containing an edit name.
1601 * Sets the edit name for the current file.
1602 * See %G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME.
1605 g_file_info_set_edit_name (GFileInfo *info,
1606 const char *edit_name)
1608 static guint32 attr = 0;
1609 GFileAttributeValue *value;
1611 g_return_if_fail (G_IS_FILE_INFO (info));
1612 g_return_if_fail (edit_name != NULL);
1615 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
1617 value = g_file_info_create_value (info, attr);
1619 _g_file_attribute_value_set_string (value, edit_name);
1623 * g_file_info_set_icon:
1624 * @info: a #GFileInfo.
1627 * Sets the icon for a given #GFileInfo.
1628 * See %G_FILE_ATTRIBUTE_STANDARD_ICON.
1631 g_file_info_set_icon (GFileInfo *info,
1634 static guint32 attr = 0;
1635 GFileAttributeValue *value;
1637 g_return_if_fail (G_IS_FILE_INFO (info));
1638 g_return_if_fail (G_IS_ICON (icon));
1641 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
1643 value = g_file_info_create_value (info, attr);
1645 _g_file_attribute_value_set_object (value, G_OBJECT (icon));
1649 * g_file_info_set_content_type:
1650 * @info: a #GFileInfo.
1651 * @content_type: a content type. See #GContentType.
1653 * Sets the content type attribute for a given #GFileInfo.
1654 * See %G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE.
1657 g_file_info_set_content_type (GFileInfo *info,
1658 const char *content_type)
1660 static guint32 attr = 0;
1661 GFileAttributeValue *value;
1663 g_return_if_fail (G_IS_FILE_INFO (info));
1664 g_return_if_fail (content_type != NULL);
1667 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1669 value = g_file_info_create_value (info, attr);
1671 _g_file_attribute_value_set_string (value, content_type);
1675 * g_file_info_set_size:
1676 * @info: a #GFileInfo.
1677 * @size: a #goffset containing the file's size.
1679 * Sets the %G_FILE_ATTRIBUTE_STANDARD_SIZE attribute in the file info
1680 * to the given size.
1683 g_file_info_set_size (GFileInfo *info,
1686 static guint32 attr = 0;
1687 GFileAttributeValue *value;
1689 g_return_if_fail (G_IS_FILE_INFO (info));
1692 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
1694 value = g_file_info_create_value (info, attr);
1696 _g_file_attribute_value_set_uint64 (value, size);
1700 * g_file_info_set_modification_time
1701 * @info: a #GFileInfo.
1702 * @mtime: a #GTimeVal.
1704 * Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute in the file
1705 * info to the given time value.
1708 g_file_info_set_modification_time (GFileInfo *info,
1711 static guint32 attr_mtime = 0, attr_mtime_usec;
1712 GFileAttributeValue *value;
1714 g_return_if_fail (G_IS_FILE_INFO (info));
1715 g_return_if_fail (mtime != NULL);
1717 if (attr_mtime == 0)
1719 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1720 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1723 value = g_file_info_create_value (info, attr_mtime);
1725 _g_file_attribute_value_set_uint64 (value, mtime->tv_sec);
1726 value = g_file_info_create_value (info, attr_mtime_usec);
1728 _g_file_attribute_value_set_uint32 (value, mtime->tv_usec);
1732 * g_file_info_set_symlink_target:
1733 * @info: a #GFileInfo.
1734 * @symlink_target: a static string containing a path to a symlink target.
1736 * Sets the %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET attribute in the file info
1737 * to the given symlink target.
1740 g_file_info_set_symlink_target (GFileInfo *info,
1741 const char *symlink_target)
1743 static guint32 attr = 0;
1744 GFileAttributeValue *value;
1746 g_return_if_fail (G_IS_FILE_INFO (info));
1747 g_return_if_fail (symlink_target != NULL);
1750 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
1752 value = g_file_info_create_value (info, attr);
1754 _g_file_attribute_value_set_byte_string (value, symlink_target);
1758 * g_file_info_set_sort_order:
1759 * @info: a #GFileInfo.
1760 * @sort_order: a sort order integer.
1762 * Sets the sort order attribute in the file info structure. See
1763 * %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
1766 g_file_info_set_sort_order (GFileInfo *info,
1769 static guint32 attr = 0;
1770 GFileAttributeValue *value;
1772 g_return_if_fail (G_IS_FILE_INFO (info));
1775 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
1777 value = g_file_info_create_value (info, attr);
1779 _g_file_attribute_value_set_int32 (value, sort_order);
1783 #define ON_STACK_MATCHERS 5
1790 struct _GFileAttributeMatcher {
1792 SubMatcher sub_matchers[ON_STACK_MATCHERS];
1793 GArray *more_sub_matchers;
1796 guint32 iterator_ns;
1802 matcher_add (GFileAttributeMatcher *matcher,
1806 SubMatcher *sub_matchers;
1810 for (i = 0; i < ON_STACK_MATCHERS; i++)
1812 /* First empty spot, not found, use this */
1813 if (matcher->sub_matchers[i].id == 0)
1815 matcher->sub_matchers[i].id = id;
1816 matcher->sub_matchers[i].mask = mask;
1821 if (matcher->sub_matchers[i].id == id &&
1822 matcher->sub_matchers[i].mask == mask)
1826 if (matcher->more_sub_matchers == NULL)
1827 matcher->more_sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
1829 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
1830 for (i = 0; i < matcher->more_sub_matchers->len; i++)
1833 if (sub_matchers[i].id == id &&
1834 sub_matchers[i].mask == mask)
1841 g_array_append_val (matcher->more_sub_matchers, s);
1845 * g_file_attribute_matcher_new:
1846 * @attributes: an attribute string to match.
1848 * Creates a new file attribute matcher, which matches attributes
1849 * against a given string. #GFileAttributeMatcher<!-- -->s are reference
1850 * counted structures, and are created with a reference count of 1. If
1851 * the number of references falls to 0, the #GFileAttributeMatcher is
1852 * automatically destroyed.
1854 * The @attribute string should be formatted with specific keys separated
1855 * from namespaces with a double colon. Several "namespace::key" strings may be
1856 * concatenated with a single comma (e.g. "standard::type,standard::is-hidden").
1857 * The wildcard "*" may be used to match all keys and namespaces, or
1858 * "namespace::*" will match all keys in a given namespace.
1860 * Examples of strings to use:
1862 * <title>File Attribute Matcher strings and results</title>
1863 * <tgroup cols='2' align='left'><thead>
1864 * <row><entry> Matcher String </entry><entry> Matches </entry></row></thead>
1866 * <row><entry>"*"</entry><entry>matches all attributes.</entry></row>
1867 * <row><entry>"standard::is-hidden"</entry><entry>matches only the key is-hidden in the standard namespace.</entry></row>
1868 * <row><entry>"standard::type,unix::*"</entry><entry>matches the type key in the standard namespace and
1869 * all keys in the unix namespace.</entry></row>
1873 * Returns: a #GFileAttributeMatcher.
1875 GFileAttributeMatcher *
1876 g_file_attribute_matcher_new (const char *attributes)
1881 GFileAttributeMatcher *matcher;
1883 if (attributes == NULL || *attributes == '\0')
1886 matcher = g_malloc0 (sizeof (GFileAttributeMatcher));
1889 split = g_strsplit (attributes, ",", -1);
1891 for (i = 0; split[i] != NULL; i++)
1893 if (strcmp (split[i], "*") == 0)
1894 matcher->all = TRUE;
1899 colon = strstr (split[i], "::");
1900 if (colon != NULL &&
1905 id = lookup_attribute (split[i]);
1913 id = lookup_namespace (split[i]) << NS_POS;
1914 mask = NS_MASK << NS_POS;
1917 matcher_add (matcher, id, mask);
1927 * g_file_attribute_matcher_ref:
1928 * @matcher: a #GFileAttributeMatcher.
1930 * References a file attribute matcher.
1932 * Returns: a #GFileAttributeMatcher.
1934 GFileAttributeMatcher *
1935 g_file_attribute_matcher_ref (GFileAttributeMatcher *matcher)
1939 g_return_val_if_fail (matcher->ref > 0, NULL);
1940 g_atomic_int_inc (&matcher->ref);
1946 * g_file_attribute_matcher_unref:
1947 * @matcher: a #GFileAttributeMatcher.
1949 * Unreferences @matcher. If the reference count falls below 1,
1950 * the @matcher is automatically freed.
1954 g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher)
1958 g_return_if_fail (matcher->ref > 0);
1960 if (g_atomic_int_dec_and_test (&matcher->ref))
1962 if (matcher->more_sub_matchers)
1963 g_array_free (matcher->more_sub_matchers, TRUE);
1971 * g_file_attribute_matcher_matches_only:
1972 * @matcher: a #GFileAttributeMatcher.
1973 * @attribute: a file attribute key.
1975 * Checks if a attribute matcher only matches a given attribute. Always
1976 * returns %FALSE if "*" was used when creating the matcher.
1978 * Returns: %TRUE if the matcher only matches @attribute. %FALSE otherwise.
1981 g_file_attribute_matcher_matches_only (GFileAttributeMatcher *matcher,
1982 const char *attribute)
1986 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
1988 if (matcher == NULL ||
1992 id = lookup_attribute (attribute);
1994 if (matcher->sub_matchers[0].id != 0 &&
1995 matcher->sub_matchers[1].id == 0 &&
1996 matcher->sub_matchers[0].mask == 0xffffffff &&
1997 matcher->sub_matchers[0].id == id)
2004 matcher_matches_id (GFileAttributeMatcher *matcher,
2007 SubMatcher *sub_matchers;
2010 for (i = 0; i < ON_STACK_MATCHERS; i++)
2012 if (matcher->sub_matchers[i].id == 0)
2015 if (matcher->sub_matchers[i].id == (id & matcher->sub_matchers[i].mask))
2019 if (matcher->more_sub_matchers)
2021 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
2022 for (i = 0; i < matcher->more_sub_matchers->len; i++)
2024 if (sub_matchers[i].id == (id & sub_matchers[i].mask))
2033 g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
2036 /* We return a NULL matcher for an empty match string, so handle this */
2037 if (matcher == NULL)
2043 return matcher_matches_id (matcher, id);
2047 * g_file_attribute_matcher_matches:
2048 * @matcher: a #GFileAttributeMatcher.
2049 * @attribute: a file attribute key.
2051 * Checks if an attribute will be matched by an attribute matcher. If
2052 * the matcher was created with the "*" matching string, this function
2053 * will always return %TRUE.
2055 * Returns: %TRUE if @attribute matches @matcher. %FALSE otherwise.
2058 g_file_attribute_matcher_matches (GFileAttributeMatcher *matcher,
2059 const char *attribute)
2061 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
2063 /* We return a NULL matcher for an empty match string, so handle this */
2064 if (matcher == NULL)
2070 return matcher_matches_id (matcher, lookup_attribute (attribute));
2073 /* return TRUE -> all */
2075 * g_file_attribute_matcher_enumerate_namespace:
2076 * @matcher: a #GFileAttributeMatcher.
2077 * @ns: a string containing a file attribute namespace.
2079 * Checks if the matcher will match all of the keys in a given namespace.
2080 * This will always return %TRUE if a wildcard character is in use (e.g. if
2081 * matcher was created with "standard::*" and @ns is "standard", or if matcher was created
2082 * using "*" and namespace is anything.)
2084 * TODO: this is awkwardly worded.
2086 * Returns: %TRUE if the matcher matches all of the entries
2087 * in the given @ns, %FALSE otherwise.
2090 g_file_attribute_matcher_enumerate_namespace (GFileAttributeMatcher *matcher,
2093 SubMatcher *sub_matchers;
2097 g_return_val_if_fail (ns != NULL && *ns != '\0', FALSE);
2099 /* We return a NULL matcher for an empty match string, so handle this */
2100 if (matcher == NULL)
2106 ns_id = lookup_namespace (ns) << NS_POS;
2108 for (i = 0; i < ON_STACK_MATCHERS; i++)
2110 if (matcher->sub_matchers[i].id == ns_id)
2114 if (matcher->more_sub_matchers)
2116 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
2117 for (i = 0; i < matcher->more_sub_matchers->len; i++)
2119 if (sub_matchers[i].id == ns_id)
2124 matcher->iterator_ns = ns_id;
2125 matcher->iterator_pos = 0;
2131 * g_file_attribute_matcher_enumerate_next:
2132 * @matcher: a #GFileAttributeMatcher.
2134 * Gets the next matched attribute from a #GFileAttributeMatcher.
2136 * Returns: a string containing the next attribute or %NULL if
2137 * no more attribute exist.
2140 g_file_attribute_matcher_enumerate_next (GFileAttributeMatcher *matcher)
2143 SubMatcher *sub_matcher;
2145 /* We return a NULL matcher for an empty match string, so handle this */
2146 if (matcher == NULL)
2151 i = matcher->iterator_pos++;
2153 if (i < ON_STACK_MATCHERS)
2155 if (matcher->sub_matchers[i].id == 0)
2158 sub_matcher = &matcher->sub_matchers[i];
2162 if (matcher->more_sub_matchers == NULL)
2165 i -= ON_STACK_MATCHERS;
2166 if (i < matcher->more_sub_matchers->len)
2167 sub_matcher = &g_array_index (matcher->more_sub_matchers, SubMatcher, i);
2172 if (sub_matcher->mask == 0xffffffff &&
2173 (sub_matcher->id & (NS_MASK << NS_POS)) == matcher->iterator_ns)
2174 return get_attribute_for_id (sub_matcher->id);
2178 #define __G_FILE_INFO_C__
2179 #include "gioaliasdef.c"