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 "gfileinfo-priv.h"
61 #include "gfileattribute-priv.h"
66 /* We use this nasty thing, because NULL is a valid attribute matcher (matches nothing) */
67 #define NO_ATTRIBUTE_MASK ((GFileAttributeMatcher *)1)
71 GFileAttributeValue value;
76 GObject parent_instance;
79 GFileAttributeMatcher *mask;
82 struct _GFileInfoClass
84 GObjectClass parent_class;
88 G_DEFINE_TYPE (GFileInfo, g_file_info, G_TYPE_OBJECT);
92 guint32 attribute_id_counter;
95 G_LOCK_DEFINE_STATIC (attribute_hash);
96 static int namespace_id_counter = 0;
97 static GHashTable *ns_hash = NULL;
98 static GHashTable *attribute_hash = NULL;
99 static char ***attributes = NULL;
101 /* Attribute ids are 32bit, we split it up like this:
102 * |------------|--------------------|
104 * namespace attribute id
106 * This way the attributes gets sorted in namespace order
110 #define NS_MASK ((guint32)((1<<12) - 1))
112 #define ID_MASK ((guint32)((1<<20) - 1))
114 #define GET_NS(_attr_id) \
115 (((guint32) (_attr_id) >> NS_POS) & NS_MASK)
116 #define GET_ID(_attr_id) \
117 (((guint32)(_attr_id) >> ID_POS) & ID_MASK)
119 #define MAKE_ATTR_ID(_ns, _id) \
120 ( ((((guint32) _ns) & NS_MASK) << NS_POS) | \
121 ((((guint32) _id) & ID_MASK) << ID_POS) )
124 _lookup_namespace (const char *namespace)
128 ns_info = g_hash_table_lookup (ns_hash, namespace);
131 ns_info = g_new0 (NSInfo, 1);
132 ns_info->id = ++namespace_id_counter;
133 g_hash_table_insert (ns_hash, g_strdup (namespace), ns_info);
134 attributes = g_realloc (attributes, (ns_info->id + 1) * sizeof (char **));
135 attributes[ns_info->id] = g_new (char *, 1);
136 attributes[ns_info->id][0] = g_strconcat (namespace, "::*", NULL);
142 _lookup_attribute (const char *attribute)
149 attr_id = GPOINTER_TO_UINT (g_hash_table_lookup (attribute_hash, attribute));
154 colon = strstr (attribute, "::");
156 ns = g_strndup (attribute, colon - attribute);
160 ns_info = _lookup_namespace (ns);
163 id = ++ns_info->attribute_id_counter;
164 attributes[ns_info->id] = g_realloc (attributes[ns_info->id], (id + 1) * sizeof (char *));
165 attributes[ns_info->id][id] = g_strdup (attribute);
167 attr_id = MAKE_ATTR_ID (ns_info->id, id);
169 g_hash_table_insert (attribute_hash, attributes[ns_info->id][id], GUINT_TO_POINTER (attr_id));
175 ensure_attribute_hash (void)
177 if (attribute_hash != NULL)
180 ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
181 attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
183 #define REGISTER_ATTRIBUTE(name) G_STMT_START{\
184 guint _u = _lookup_attribute (G_FILE_ATTRIBUTE_ ## name); \
185 /* use for generating the ID: g_print ("#define G_FILE_ATTRIBUTE_ID_%s (%u + %u)\n", #name + 17, _u & ~ID_MASK, _u & ID_MASK); */ \
186 g_assert (_u == G_FILE_ATTRIBUTE_ID_ ## name); \
189 REGISTER_ATTRIBUTE (STANDARD_TYPE);
190 REGISTER_ATTRIBUTE (STANDARD_IS_HIDDEN);
191 REGISTER_ATTRIBUTE (STANDARD_IS_BACKUP);
192 REGISTER_ATTRIBUTE (STANDARD_IS_SYMLINK);
193 REGISTER_ATTRIBUTE (STANDARD_IS_VIRTUAL);
194 REGISTER_ATTRIBUTE (STANDARD_NAME);
195 REGISTER_ATTRIBUTE (STANDARD_DISPLAY_NAME);
196 REGISTER_ATTRIBUTE (STANDARD_EDIT_NAME);
197 REGISTER_ATTRIBUTE (STANDARD_COPY_NAME);
198 REGISTER_ATTRIBUTE (STANDARD_DESCRIPTION);
199 REGISTER_ATTRIBUTE (STANDARD_ICON);
200 REGISTER_ATTRIBUTE (STANDARD_CONTENT_TYPE);
201 REGISTER_ATTRIBUTE (STANDARD_FAST_CONTENT_TYPE);
202 REGISTER_ATTRIBUTE (STANDARD_SIZE);
203 REGISTER_ATTRIBUTE (STANDARD_ALLOCATED_SIZE);
204 REGISTER_ATTRIBUTE (STANDARD_SYMLINK_TARGET);
205 REGISTER_ATTRIBUTE (STANDARD_TARGET_URI);
206 REGISTER_ATTRIBUTE (STANDARD_SORT_ORDER);
207 REGISTER_ATTRIBUTE (STANDARD_SYMBOLIC_ICON);
208 REGISTER_ATTRIBUTE (ETAG_VALUE);
209 REGISTER_ATTRIBUTE (ID_FILE);
210 REGISTER_ATTRIBUTE (ID_FILESYSTEM);
211 REGISTER_ATTRIBUTE (ACCESS_CAN_READ);
212 REGISTER_ATTRIBUTE (ACCESS_CAN_WRITE);
213 REGISTER_ATTRIBUTE (ACCESS_CAN_EXECUTE);
214 REGISTER_ATTRIBUTE (ACCESS_CAN_DELETE);
215 REGISTER_ATTRIBUTE (ACCESS_CAN_TRASH);
216 REGISTER_ATTRIBUTE (ACCESS_CAN_RENAME);
217 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_MOUNT);
218 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_UNMOUNT);
219 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_EJECT);
220 REGISTER_ATTRIBUTE (MOUNTABLE_UNIX_DEVICE);
221 REGISTER_ATTRIBUTE (MOUNTABLE_UNIX_DEVICE_FILE);
222 REGISTER_ATTRIBUTE (MOUNTABLE_HAL_UDI);
223 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_START);
224 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_START_DEGRADED);
225 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_STOP);
226 REGISTER_ATTRIBUTE (MOUNTABLE_START_STOP_TYPE);
227 REGISTER_ATTRIBUTE (MOUNTABLE_CAN_POLL);
228 REGISTER_ATTRIBUTE (MOUNTABLE_IS_MEDIA_CHECK_AUTOMATIC);
229 REGISTER_ATTRIBUTE (TIME_MODIFIED);
230 REGISTER_ATTRIBUTE (TIME_MODIFIED_USEC);
231 REGISTER_ATTRIBUTE (TIME_ACCESS);
232 REGISTER_ATTRIBUTE (TIME_ACCESS_USEC);
233 REGISTER_ATTRIBUTE (TIME_CHANGED);
234 REGISTER_ATTRIBUTE (TIME_CHANGED_USEC);
235 REGISTER_ATTRIBUTE (TIME_CREATED);
236 REGISTER_ATTRIBUTE (TIME_CREATED_USEC);
237 REGISTER_ATTRIBUTE (UNIX_DEVICE);
238 REGISTER_ATTRIBUTE (UNIX_INODE);
239 REGISTER_ATTRIBUTE (UNIX_MODE);
240 REGISTER_ATTRIBUTE (UNIX_NLINK);
241 REGISTER_ATTRIBUTE (UNIX_UID);
242 REGISTER_ATTRIBUTE (UNIX_GID);
243 REGISTER_ATTRIBUTE (UNIX_RDEV);
244 REGISTER_ATTRIBUTE (UNIX_BLOCK_SIZE);
245 REGISTER_ATTRIBUTE (UNIX_BLOCKS);
246 REGISTER_ATTRIBUTE (UNIX_IS_MOUNTPOINT);
247 REGISTER_ATTRIBUTE (DOS_IS_ARCHIVE);
248 REGISTER_ATTRIBUTE (DOS_IS_SYSTEM);
249 REGISTER_ATTRIBUTE (OWNER_USER);
250 REGISTER_ATTRIBUTE (OWNER_USER_REAL);
251 REGISTER_ATTRIBUTE (OWNER_GROUP);
252 REGISTER_ATTRIBUTE (THUMBNAIL_PATH);
253 REGISTER_ATTRIBUTE (THUMBNAILING_FAILED);
254 REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID);
255 REGISTER_ATTRIBUTE (PREVIEW_ICON);
256 REGISTER_ATTRIBUTE (FILESYSTEM_SIZE);
257 REGISTER_ATTRIBUTE (FILESYSTEM_FREE);
258 REGISTER_ATTRIBUTE (FILESYSTEM_TYPE);
259 REGISTER_ATTRIBUTE (FILESYSTEM_READONLY);
260 REGISTER_ATTRIBUTE (FILESYSTEM_USE_PREVIEW);
261 REGISTER_ATTRIBUTE (GVFS_BACKEND);
262 REGISTER_ATTRIBUTE (SELINUX_CONTEXT);
263 REGISTER_ATTRIBUTE (TRASH_ITEM_COUNT);
264 REGISTER_ATTRIBUTE (TRASH_ORIG_PATH);
265 REGISTER_ATTRIBUTE (TRASH_DELETION_DATE);
267 #undef REGISTER_ATTRIBUTE
271 lookup_namespace (const char *namespace)
276 G_LOCK (attribute_hash);
278 ensure_attribute_hash ();
280 ns_info = _lookup_namespace (namespace);
285 G_UNLOCK (attribute_hash);
291 get_attribute_for_id (int attribute)
294 G_LOCK (attribute_hash);
295 s = attributes[GET_NS(attribute)][GET_ID(attribute)];
296 G_UNLOCK (attribute_hash);
301 lookup_attribute (const char *attribute)
305 G_LOCK (attribute_hash);
306 ensure_attribute_hash ();
308 attr_id = _lookup_attribute (attribute);
310 G_UNLOCK (attribute_hash);
316 g_file_info_finalize (GObject *object)
320 GFileAttribute *attrs;
322 info = G_FILE_INFO (object);
324 attrs = (GFileAttribute *)info->attributes->data;
325 for (i = 0; i < info->attributes->len; i++)
326 _g_file_attribute_value_clear (&attrs[i].value);
327 g_array_free (info->attributes, TRUE);
329 if (info->mask != NO_ATTRIBUTE_MASK)
330 g_file_attribute_matcher_unref (info->mask);
332 G_OBJECT_CLASS (g_file_info_parent_class)->finalize (object);
336 g_file_info_class_init (GFileInfoClass *klass)
338 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
340 gobject_class->finalize = g_file_info_finalize;
344 g_file_info_init (GFileInfo *info)
346 info->mask = NO_ATTRIBUTE_MASK;
347 info->attributes = g_array_new (FALSE, FALSE,
348 sizeof (GFileAttribute));
354 * Creates a new file info structure.
356 * Returns: a #GFileInfo.
359 g_file_info_new (void)
361 return g_object_new (G_TYPE_FILE_INFO, NULL);
365 * g_file_info_copy_into:
366 * @src_info: source to copy attributes from.
367 * @dest_info: destination to copy attributes to.
369 * Copies all of the <link linkend="gio-GFileAttribute">GFileAttribute</link>s
370 * from @src_info to @dest_info.
373 g_file_info_copy_into (GFileInfo *src_info,
374 GFileInfo *dest_info)
376 GFileAttribute *source, *dest;
379 g_return_if_fail (G_IS_FILE_INFO (src_info));
380 g_return_if_fail (G_IS_FILE_INFO (dest_info));
382 dest = (GFileAttribute *)dest_info->attributes->data;
383 for (i = 0; i < dest_info->attributes->len; i++)
384 _g_file_attribute_value_clear (&dest[i].value);
386 g_array_set_size (dest_info->attributes,
387 src_info->attributes->len);
389 source = (GFileAttribute *)src_info->attributes->data;
390 dest = (GFileAttribute *)dest_info->attributes->data;
392 for (i = 0; i < src_info->attributes->len; i++)
394 dest[i].attribute = source[i].attribute;
395 dest[i].value.type = G_FILE_ATTRIBUTE_TYPE_INVALID;
396 _g_file_attribute_value_set (&dest[i].value, &source[i].value);
399 if (dest_info->mask != NO_ATTRIBUTE_MASK)
400 g_file_attribute_matcher_unref (dest_info->mask);
402 if (src_info->mask == NO_ATTRIBUTE_MASK)
403 dest_info->mask = NO_ATTRIBUTE_MASK;
405 dest_info->mask = g_file_attribute_matcher_ref (src_info->mask);
410 * @other: a #GFileInfo.
412 * Duplicates a file info structure.
414 * Returns: (transfer full): a duplicate #GFileInfo of @other.
417 g_file_info_dup (GFileInfo *other)
421 g_return_val_if_fail (G_IS_FILE_INFO (other), NULL);
423 new = g_file_info_new ();
424 g_file_info_copy_into (other, new);
429 * g_file_info_set_attribute_mask:
430 * @info: a #GFileInfo.
431 * @mask: a #GFileAttributeMatcher.
433 * Sets @mask on @info to match specific attribute types.
436 g_file_info_set_attribute_mask (GFileInfo *info,
437 GFileAttributeMatcher *mask)
439 GFileAttribute *attr;
442 g_return_if_fail (G_IS_FILE_INFO (info));
444 if (mask != info->mask)
446 if (info->mask != NO_ATTRIBUTE_MASK)
447 g_file_attribute_matcher_unref (info->mask);
448 info->mask = g_file_attribute_matcher_ref (mask);
450 /* Remove non-matching attributes */
451 for (i = 0; i < info->attributes->len; i++)
453 attr = &g_array_index (info->attributes, GFileAttribute, i);
454 if (!_g_file_attribute_matcher_matches_id (mask,
457 _g_file_attribute_value_clear (&attr->value);
458 g_array_remove_index (info->attributes, i);
466 * g_file_info_unset_attribute_mask:
469 * Unsets a mask set by g_file_info_set_attribute_mask(), if one
473 g_file_info_unset_attribute_mask (GFileInfo *info)
475 g_return_if_fail (G_IS_FILE_INFO (info));
477 if (info->mask != NO_ATTRIBUTE_MASK)
478 g_file_attribute_matcher_unref (info->mask);
479 info->mask = NO_ATTRIBUTE_MASK;
483 * g_file_info_clear_status:
484 * @info: a #GFileInfo.
486 * Clears the status information from @info.
489 g_file_info_clear_status (GFileInfo *info)
491 GFileAttribute *attrs;
494 g_return_if_fail (G_IS_FILE_INFO (info));
496 attrs = (GFileAttribute *)info->attributes->data;
497 for (i = 0; i < info->attributes->len; i++)
498 attrs[i].value.status = G_FILE_ATTRIBUTE_STATUS_UNSET;
502 g_file_info_find_place (GFileInfo *info,
506 GFileAttribute *attrs;
507 /* Binary search for the place where attribute would be, if it's
511 max = info->attributes->len;
513 attrs = (GFileAttribute *)info->attributes->data;
517 med = min + (max - min) / 2;
518 if (attrs[med].attribute == attribute)
523 else if (attrs[med].attribute < attribute)
525 else /* attrs[med].attribute > attribute */
532 static GFileAttributeValue *
533 g_file_info_find_value (GFileInfo *info,
536 GFileAttribute *attrs;
539 i = g_file_info_find_place (info, attr_id);
540 attrs = (GFileAttribute *)info->attributes->data;
541 if (i < info->attributes->len &&
542 attrs[i].attribute == attr_id)
543 return &attrs[i].value;
548 static GFileAttributeValue *
549 g_file_info_find_value_by_name (GFileInfo *info,
550 const char *attribute)
554 attr_id = lookup_attribute (attribute);
555 return g_file_info_find_value (info, attr_id);
559 * g_file_info_has_attribute:
560 * @info: a #GFileInfo.
561 * @attribute: a file attribute key.
563 * Checks if a file info structure has an attribute named @attribute.
565 * Returns: %TRUE if @Ginfo has an attribute named @attribute,
569 g_file_info_has_attribute (GFileInfo *info,
570 const char *attribute)
572 GFileAttributeValue *value;
574 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
575 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
577 value = g_file_info_find_value_by_name (info, attribute);
578 return value != NULL;
582 * g_file_info_has_namespace:
583 * @info: a #GFileInfo.
584 * @name_space: a file attribute namespace.
586 * Checks if a file info structure has an attribute in the
587 * specified @name_space.
589 * Returns: %TRUE if @Ginfo has an attribute in @name_space,
595 g_file_info_has_namespace (GFileInfo *info,
596 const char *name_space)
598 GFileAttribute *attrs;
602 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
603 g_return_val_if_fail (name_space != NULL, FALSE);
605 ns_id = lookup_namespace (name_space);
607 attrs = (GFileAttribute *)info->attributes->data;
608 for (i = 0; i < info->attributes->len; i++)
610 if (GET_NS (attrs[i].attribute) == ns_id)
618 * g_file_info_list_attributes:
619 * @info: a #GFileInfo.
620 * @name_space: a file attribute key's namespace.
622 * Lists the file info structure's attributes.
624 * Returns: (array zero-terminated=1) (transfer full): a null-terminated array of strings of all of the
625 * possible attribute types for the given @name_space, or
629 g_file_info_list_attributes (GFileInfo *info,
630 const char *name_space)
633 GFileAttribute *attrs;
635 guint32 ns_id = (name_space) ? lookup_namespace (name_space) : 0;
638 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
640 names = g_ptr_array_new ();
641 attrs = (GFileAttribute *)info->attributes->data;
642 for (i = 0; i < info->attributes->len; i++)
644 attribute = attrs[i].attribute;
645 if (ns_id == 0 || GET_NS (attribute) == ns_id)
646 g_ptr_array_add (names, g_strdup (get_attribute_for_id (attribute)));
650 g_ptr_array_add (names, NULL);
652 return (char **)g_ptr_array_free (names, FALSE);
656 * g_file_info_get_attribute_type:
657 * @info: a #GFileInfo.
658 * @attribute: a file attribute key.
660 * Gets the attribute type for an attribute key.
662 * Returns: a #GFileAttributeType for the given @attribute, or
663 * %G_FILE_ATTRIBUTE_TYPE_INVALID if the key is not set.
666 g_file_info_get_attribute_type (GFileInfo *info,
667 const char *attribute)
669 GFileAttributeValue *value;
671 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_ATTRIBUTE_TYPE_INVALID);
672 g_return_val_if_fail (attribute != NULL && *attribute != '\0', G_FILE_ATTRIBUTE_TYPE_INVALID);
674 value = g_file_info_find_value_by_name (info, attribute);
678 return G_FILE_ATTRIBUTE_TYPE_INVALID;
682 * g_file_info_remove_attribute:
683 * @info: a #GFileInfo.
684 * @attribute: a file attribute key.
686 * Removes all cases of @attribute from @info if it exists.
689 g_file_info_remove_attribute (GFileInfo *info,
690 const char *attribute)
693 GFileAttribute *attrs;
696 g_return_if_fail (G_IS_FILE_INFO (info));
697 g_return_if_fail (attribute != NULL && *attribute != '\0');
699 attr_id = lookup_attribute (attribute);
701 i = g_file_info_find_place (info, attr_id);
702 attrs = (GFileAttribute *)info->attributes->data;
703 if (i < info->attributes->len &&
704 attrs[i].attribute == attr_id)
706 _g_file_attribute_value_clear (&attrs[i].value);
707 g_array_remove_index (info->attributes, i);
712 * g_file_info_get_attribute_data:
713 * @info: a #GFileInfo
714 * @attribute: a file attribute key
715 * @type: (out) (allow-none): return location for the attribute type, or %NULL
716 * @value_pp: (out) (allow-none): return location for the attribute value, or %NULL
717 * @status: (out) (allow-none): return location for the attribute status, or %NULL
719 * Gets the attribute type, value and status for an attribute key.
721 * Returns: (transfer none): %TRUE if @info has an attribute named @attribute,
725 g_file_info_get_attribute_data (GFileInfo *info,
726 const char *attribute,
727 GFileAttributeType *type,
729 GFileAttributeStatus *status)
731 GFileAttributeValue *value;
733 value = g_file_info_find_value_by_name (info, attribute);
738 *status = value->status;
744 *value_pp = _g_file_attribute_value_peek_as_pointer (value);
750 * g_file_info_get_attribute_status:
751 * @info: a #GFileInfo
752 * @attribute: a file attribute key
754 * Gets the attribute status for an attribute key.
756 * Returns: a #GFileAttributeStatus for the given @attribute, or
757 * %G_FILE_ATTRIBUTE_STATUS_UNSET if the key is invalid.
761 g_file_info_get_attribute_status (GFileInfo *info,
762 const char *attribute)
764 GFileAttributeValue *val;
766 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
767 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
769 val = g_file_info_find_value_by_name (info, attribute);
773 return G_FILE_ATTRIBUTE_STATUS_UNSET;
777 * g_file_info_set_attribute_status:
778 * @info: a #GFileInfo
779 * @attribute: a file attribute key
780 * @status: a #GFileAttributeStatus
782 * Sets the attribute status for an attribute key. This is only
783 * needed by external code that implement g_file_set_attributes_from_info()
784 * or similar functions.
786 * The attribute must exist in @info for this to work. Otherwise %FALSE
787 * is returned and @info is unchanged.
789 * Returns: %TRUE if the status was changed, %FALSE if the key was not set.
794 g_file_info_set_attribute_status (GFileInfo *info,
795 const char *attribute,
796 GFileAttributeStatus status)
798 GFileAttributeValue *val;
800 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
801 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
803 val = g_file_info_find_value_by_name (info, attribute);
806 val->status = status;
813 GFileAttributeValue *
814 _g_file_info_get_attribute_value (GFileInfo *info,
815 const char *attribute)
818 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
819 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
821 return g_file_info_find_value_by_name (info, attribute);
825 * g_file_info_get_attribute_as_string:
826 * @info: a #GFileInfo.
827 * @attribute: a file attribute key.
829 * Gets the value of a attribute, formated as a string.
830 * This escapes things as needed to make the string valid
833 * Returns: a UTF-8 string associated with the given @attribute.
834 * When you're done with the string it must be freed with g_free().
837 g_file_info_get_attribute_as_string (GFileInfo *info,
838 const char *attribute)
840 GFileAttributeValue *val;
841 val = _g_file_info_get_attribute_value (info, attribute);
843 return _g_file_attribute_value_as_string (val);
849 * g_file_info_get_attribute_object:
850 * @info: a #GFileInfo.
851 * @attribute: a file attribute key.
853 * Gets the value of a #GObject attribute. If the attribute does
854 * not contain a #GObject, %NULL will be returned.
856 * Returns: (transfer none): a #GObject associated with the given @attribute, or
860 g_file_info_get_attribute_object (GFileInfo *info,
861 const char *attribute)
863 GFileAttributeValue *value;
865 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
866 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
868 value = g_file_info_find_value_by_name (info, attribute);
869 return _g_file_attribute_value_get_object (value);
873 * g_file_info_get_attribute_string:
874 * @info: a #GFileInfo.
875 * @attribute: a file attribute key.
877 * Gets the value of a string attribute. If the attribute does
878 * not contain a string, %NULL will be returned.
880 * Returns: the contents of the @attribute value as a UTF-8 string, or
884 g_file_info_get_attribute_string (GFileInfo *info,
885 const char *attribute)
887 GFileAttributeValue *value;
889 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
890 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
892 value = g_file_info_find_value_by_name (info, attribute);
893 return _g_file_attribute_value_get_string (value);
897 * g_file_info_get_attribute_byte_string:
898 * @info: a #GFileInfo.
899 * @attribute: a file attribute key.
901 * Gets the value of a byte string attribute. If the attribute does
902 * not contain a byte string, %NULL will be returned.
904 * Returns: the contents of the @attribute value as a byte string, or
908 g_file_info_get_attribute_byte_string (GFileInfo *info,
909 const char *attribute)
911 GFileAttributeValue *value;
913 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
914 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
916 value = g_file_info_find_value_by_name (info, attribute);
917 return _g_file_attribute_value_get_byte_string (value);
921 * g_file_info_get_attribute_stringv:
922 * @info: a #GFileInfo.
923 * @attribute: a file attribute key.
925 * Gets the value of a stringv attribute. If the attribute does
926 * not contain a stringv, %NULL will be returned.
928 * Returns: (transfer none): the contents of the @attribute value as a stringv, or
929 * %NULL otherwise. Do not free. These returned strings are UTF-8.
934 g_file_info_get_attribute_stringv (GFileInfo *info,
935 const char *attribute)
937 GFileAttributeValue *value;
939 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
940 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
942 value = g_file_info_find_value_by_name (info, attribute);
943 return _g_file_attribute_value_get_stringv (value);
947 * g_file_info_get_attribute_boolean:
948 * @info: a #GFileInfo.
949 * @attribute: a file attribute key.
951 * Gets the value of a boolean attribute. If the attribute does not
952 * contain a boolean value, %FALSE will be returned.
954 * Returns: the boolean value contained within the attribute.
957 g_file_info_get_attribute_boolean (GFileInfo *info,
958 const char *attribute)
960 GFileAttributeValue *value;
962 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
963 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
965 value = g_file_info_find_value_by_name (info, attribute);
966 return _g_file_attribute_value_get_boolean (value);
970 * g_file_info_get_attribute_uint32:
971 * @info: a #GFileInfo.
972 * @attribute: a file attribute key.
974 * Gets an unsigned 32-bit integer contained within the attribute. If the
975 * attribute does not contain an unsigned 32-bit integer, or is invalid,
976 * 0 will be returned.
978 * Returns: an unsigned 32-bit integer from the attribute.
981 g_file_info_get_attribute_uint32 (GFileInfo *info,
982 const char *attribute)
984 GFileAttributeValue *value;
986 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
987 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
989 value = g_file_info_find_value_by_name (info, attribute);
990 return _g_file_attribute_value_get_uint32 (value);
994 * g_file_info_get_attribute_int32:
995 * @info: a #GFileInfo.
996 * @attribute: a file attribute key.
998 * Gets a signed 32-bit integer contained within the attribute. If the
999 * attribute does not contain a signed 32-bit integer, or is invalid,
1000 * 0 will be returned.
1002 * Returns: a signed 32-bit integer from the attribute.
1005 g_file_info_get_attribute_int32 (GFileInfo *info,
1006 const char *attribute)
1008 GFileAttributeValue *value;
1010 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1011 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
1013 value = g_file_info_find_value_by_name (info, attribute);
1014 return _g_file_attribute_value_get_int32 (value);
1018 * g_file_info_get_attribute_uint64:
1019 * @info: a #GFileInfo.
1020 * @attribute: a file attribute key.
1022 * Gets a unsigned 64-bit integer contained within the attribute. If the
1023 * attribute does not contain an unsigned 64-bit integer, or is invalid,
1024 * 0 will be returned.
1026 * Returns: a unsigned 64-bit integer from the attribute.
1029 g_file_info_get_attribute_uint64 (GFileInfo *info,
1030 const char *attribute)
1032 GFileAttributeValue *value;
1034 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1035 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
1037 value = g_file_info_find_value_by_name (info, attribute);
1038 return _g_file_attribute_value_get_uint64 (value);
1042 * g_file_info_get_attribute_int64:
1043 * @info: a #GFileInfo.
1044 * @attribute: a file attribute key.
1046 * Gets a signed 64-bit integer contained within the attribute. If the
1047 * attribute does not contain an signed 64-bit integer, or is invalid,
1048 * 0 will be returned.
1050 * Returns: a signed 64-bit integer from the attribute.
1053 g_file_info_get_attribute_int64 (GFileInfo *info,
1054 const char *attribute)
1056 GFileAttributeValue *value;
1058 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1059 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
1061 value = g_file_info_find_value_by_name (info, attribute);
1062 return _g_file_attribute_value_get_int64 (value);
1065 static GFileAttributeValue *
1066 g_file_info_create_value (GFileInfo *info,
1069 GFileAttribute *attrs;
1072 if (info->mask != NO_ATTRIBUTE_MASK &&
1073 !_g_file_attribute_matcher_matches_id (info->mask, attr_id))
1076 i = g_file_info_find_place (info, attr_id);
1078 attrs = (GFileAttribute *)info->attributes->data;
1079 if (i < info->attributes->len &&
1080 attrs[i].attribute == attr_id)
1081 return &attrs[i].value;
1084 GFileAttribute attr = { 0 };
1085 attr.attribute = attr_id;
1086 g_array_insert_val (info->attributes, i, attr);
1088 attrs = (GFileAttribute *)info->attributes->data;
1089 return &attrs[i].value;
1094 _g_file_info_set_attribute_by_id (GFileInfo *info,
1096 GFileAttributeType type,
1099 GFileAttributeValue *value;
1101 value = g_file_info_create_value (info, attribute);
1104 _g_file_attribute_value_set_from_pointer (value, type, value_p, TRUE);
1108 * g_file_info_set_attribute:
1109 * @info: a #GFileInfo.
1110 * @attribute: a file attribute key.
1111 * @type: a #GFileAttributeType
1112 * @value_p: pointer to the value
1114 * Sets the @attribute to contain the given value, if possible. To unset the
1115 * attribute, use %G_ATTRIBUTE_TYPE_INVALID for @type.
1118 g_file_info_set_attribute (GFileInfo *info,
1119 const char *attribute,
1120 GFileAttributeType type,
1123 g_return_if_fail (G_IS_FILE_INFO (info));
1124 g_return_if_fail (attribute != NULL && *attribute != '\0');
1126 _g_file_info_set_attribute_by_id (info, lookup_attribute (attribute), type, value_p);
1130 _g_file_info_set_attribute_object_by_id (GFileInfo *info,
1132 GObject *attr_value)
1134 GFileAttributeValue *value;
1136 value = g_file_info_create_value (info, attribute);
1138 _g_file_attribute_value_set_object (value, attr_value);
1142 * g_file_info_set_attribute_object:
1143 * @info: a #GFileInfo.
1144 * @attribute: a file attribute key.
1145 * @attr_value: a #GObject.
1147 * Sets the @attribute to contain the given @attr_value,
1151 g_file_info_set_attribute_object (GFileInfo *info,
1152 const char *attribute,
1153 GObject *attr_value)
1155 g_return_if_fail (G_IS_FILE_INFO (info));
1156 g_return_if_fail (attribute != NULL && *attribute != '\0');
1157 g_return_if_fail (G_IS_OBJECT (attr_value));
1159 _g_file_info_set_attribute_object_by_id (info,
1160 lookup_attribute (attribute),
1165 _g_file_info_set_attribute_stringv_by_id (GFileInfo *info,
1169 GFileAttributeValue *value;
1171 value = g_file_info_create_value (info, attribute);
1173 _g_file_attribute_value_set_stringv (value, attr_value);
1177 * g_file_info_set_attribute_stringv:
1178 * @info: a #GFileInfo.
1179 * @attribute: a file attribute key
1180 * @attr_value: (array) (element-type utf8): a %NULL terminated array of UTF-8 strings.
1182 * Sets the @attribute to contain the given @attr_value,
1188 g_file_info_set_attribute_stringv (GFileInfo *info,
1189 const char *attribute,
1192 g_return_if_fail (G_IS_FILE_INFO (info));
1193 g_return_if_fail (attribute != NULL && *attribute != '\0');
1194 g_return_if_fail (attr_value != NULL);
1196 _g_file_info_set_attribute_stringv_by_id (info,
1197 lookup_attribute (attribute),
1202 _g_file_info_set_attribute_string_by_id (GFileInfo *info,
1204 const char *attr_value)
1206 GFileAttributeValue *value;
1208 value = g_file_info_create_value (info, attribute);
1210 _g_file_attribute_value_set_string (value, attr_value);
1214 * g_file_info_set_attribute_string:
1215 * @info: a #GFileInfo.
1216 * @attribute: a file attribute key.
1217 * @attr_value: a UTF-8 string.
1219 * Sets the @attribute to contain the given @attr_value,
1223 g_file_info_set_attribute_string (GFileInfo *info,
1224 const char *attribute,
1225 const char *attr_value)
1227 g_return_if_fail (G_IS_FILE_INFO (info));
1228 g_return_if_fail (attribute != NULL && *attribute != '\0');
1229 g_return_if_fail (attr_value != NULL);
1231 _g_file_info_set_attribute_string_by_id (info,
1232 lookup_attribute (attribute),
1237 _g_file_info_set_attribute_byte_string_by_id (GFileInfo *info,
1239 const char *attr_value)
1241 GFileAttributeValue *value;
1243 value = g_file_info_create_value (info, attribute);
1245 _g_file_attribute_value_set_byte_string (value, attr_value);
1249 * g_file_info_set_attribute_byte_string:
1250 * @info: a #GFileInfo.
1251 * @attribute: a file attribute key.
1252 * @attr_value: a byte string.
1254 * Sets the @attribute to contain the given @attr_value,
1258 g_file_info_set_attribute_byte_string (GFileInfo *info,
1259 const char *attribute,
1260 const char *attr_value)
1262 g_return_if_fail (G_IS_FILE_INFO (info));
1263 g_return_if_fail (attribute != NULL && *attribute != '\0');
1264 g_return_if_fail (attr_value != NULL);
1266 _g_file_info_set_attribute_byte_string_by_id (info,
1267 lookup_attribute (attribute),
1272 _g_file_info_set_attribute_boolean_by_id (GFileInfo *info,
1274 gboolean attr_value)
1276 GFileAttributeValue *value;
1278 value = g_file_info_create_value (info, attribute);
1280 _g_file_attribute_value_set_boolean (value, attr_value);
1284 * g_file_info_set_attribute_boolean:
1285 * @info: a #GFileInfo.
1286 * @attribute: a file attribute key.
1287 * @attr_value: a boolean value.
1289 * Sets the @attribute to contain the given @attr_value,
1293 g_file_info_set_attribute_boolean (GFileInfo *info,
1294 const char *attribute,
1295 gboolean attr_value)
1297 g_return_if_fail (G_IS_FILE_INFO (info));
1298 g_return_if_fail (attribute != NULL && *attribute != '\0');
1300 _g_file_info_set_attribute_boolean_by_id (info,
1301 lookup_attribute (attribute),
1306 _g_file_info_set_attribute_uint32_by_id (GFileInfo *info,
1310 GFileAttributeValue *value;
1312 value = g_file_info_create_value (info, attribute);
1314 _g_file_attribute_value_set_uint32 (value, attr_value);
1318 * g_file_info_set_attribute_uint32:
1319 * @info: a #GFileInfo.
1320 * @attribute: a file attribute key.
1321 * @attr_value: an unsigned 32-bit integer.
1323 * Sets the @attribute to contain the given @attr_value,
1327 g_file_info_set_attribute_uint32 (GFileInfo *info,
1328 const char *attribute,
1331 g_return_if_fail (G_IS_FILE_INFO (info));
1332 g_return_if_fail (attribute != NULL && *attribute != '\0');
1334 _g_file_info_set_attribute_uint32_by_id (info,
1335 lookup_attribute (attribute),
1340 _g_file_info_set_attribute_int32_by_id (GFileInfo *info,
1344 GFileAttributeValue *value;
1346 value = g_file_info_create_value (info, attribute);
1348 _g_file_attribute_value_set_int32 (value, attr_value);
1352 * g_file_info_set_attribute_int32:
1353 * @info: a #GFileInfo.
1354 * @attribute: a file attribute key.
1355 * @attr_value: a signed 32-bit integer
1357 * Sets the @attribute to contain the given @attr_value,
1361 g_file_info_set_attribute_int32 (GFileInfo *info,
1362 const char *attribute,
1365 g_return_if_fail (G_IS_FILE_INFO (info));
1366 g_return_if_fail (attribute != NULL && *attribute != '\0');
1368 _g_file_info_set_attribute_int32_by_id (info,
1369 lookup_attribute (attribute),
1374 _g_file_info_set_attribute_uint64_by_id (GFileInfo *info,
1378 GFileAttributeValue *value;
1380 value = g_file_info_create_value (info, attribute);
1382 _g_file_attribute_value_set_uint64 (value, attr_value);
1386 * g_file_info_set_attribute_uint64:
1387 * @info: a #GFileInfo.
1388 * @attribute: a file attribute key.
1389 * @attr_value: an unsigned 64-bit integer.
1391 * Sets the @attribute to contain the given @attr_value,
1395 g_file_info_set_attribute_uint64 (GFileInfo *info,
1396 const char *attribute,
1399 g_return_if_fail (G_IS_FILE_INFO (info));
1400 g_return_if_fail (attribute != NULL && *attribute != '\0');
1402 _g_file_info_set_attribute_uint64_by_id (info,
1403 lookup_attribute (attribute),
1408 _g_file_info_set_attribute_int64_by_id (GFileInfo *info,
1412 GFileAttributeValue *value;
1414 value = g_file_info_create_value (info, attribute);
1416 _g_file_attribute_value_set_int64 (value, attr_value);
1420 * g_file_info_set_attribute_int64:
1421 * @info: a #GFileInfo.
1422 * @attribute: attribute name to set.
1423 * @attr_value: int64 value to set attribute to.
1425 * Sets the @attribute to contain the given @attr_value,
1430 g_file_info_set_attribute_int64 (GFileInfo *info,
1431 const char *attribute,
1434 g_return_if_fail (G_IS_FILE_INFO (info));
1435 g_return_if_fail (attribute != NULL && *attribute != '\0');
1437 _g_file_info_set_attribute_int64_by_id (info,
1438 lookup_attribute (attribute),
1442 /* Helper getters */
1444 * g_file_info_get_deletion_date:
1445 * @info: a #GFileInfo.
1447 * Returns the #GDateTime representing the deletion date of the file, as
1448 * available in G_FILE_ATTRIBUTE_TRASH_DELETION_DATE. If the
1449 * G_FILE_ATTRIBUTE_TRASH_DELETION_DATE attribute is unset, %NULL is returned.
1451 * Returns: a #GDateTime, or %NULL.
1456 g_file_info_get_deletion_date (GFileInfo *info)
1458 static guint32 attr = 0;
1459 GFileAttributeValue *value;
1460 const char *date_str;
1463 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1466 attr = lookup_attribute (G_FILE_ATTRIBUTE_TRASH_DELETION_DATE);
1468 value = g_file_info_find_value (info, attr);
1469 date_str = _g_file_attribute_value_get_string (value);
1473 if (g_time_val_from_iso8601 (date_str, &tv) == FALSE)
1476 return g_date_time_new_from_timeval_local (&tv);
1480 * g_file_info_get_file_type:
1481 * @info: a #GFileInfo.
1483 * Gets a file's type (whether it is a regular file, symlink, etc).
1484 * This is different from the file's content type, see g_file_info_get_content_type().
1486 * Returns: a #GFileType for the given file.
1489 g_file_info_get_file_type (GFileInfo *info)
1491 static guint32 attr = 0;
1492 GFileAttributeValue *value;
1494 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_TYPE_UNKNOWN);
1497 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
1499 value = g_file_info_find_value (info, attr);
1500 return (GFileType)_g_file_attribute_value_get_uint32 (value);
1504 * g_file_info_get_is_hidden:
1505 * @info: a #GFileInfo.
1507 * Checks if a file is hidden.
1509 * Returns: %TRUE if the file is a hidden file, %FALSE otherwise.
1512 g_file_info_get_is_hidden (GFileInfo *info)
1514 static guint32 attr = 0;
1515 GFileAttributeValue *value;
1517 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1520 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
1522 value = g_file_info_find_value (info, attr);
1523 return (GFileType)_g_file_attribute_value_get_boolean (value);
1527 * g_file_info_get_is_backup:
1528 * @info: a #GFileInfo.
1530 * Checks if a file is a backup file.
1532 * Returns: %TRUE if file is a backup file, %FALSE otherwise.
1535 g_file_info_get_is_backup (GFileInfo *info)
1537 static guint32 attr = 0;
1538 GFileAttributeValue *value;
1540 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1543 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
1545 value = g_file_info_find_value (info, attr);
1546 return (GFileType)_g_file_attribute_value_get_boolean (value);
1550 * g_file_info_get_is_symlink:
1551 * @info: a #GFileInfo.
1553 * Checks if a file is a symlink.
1555 * Returns: %TRUE if the given @info is a symlink.
1558 g_file_info_get_is_symlink (GFileInfo *info)
1560 static guint32 attr = 0;
1561 GFileAttributeValue *value;
1563 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1566 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
1568 value = g_file_info_find_value (info, attr);
1569 return (GFileType)_g_file_attribute_value_get_boolean (value);
1573 * g_file_info_get_name:
1574 * @info: a #GFileInfo.
1576 * Gets the name for a file.
1578 * Returns: a string containing the file name.
1581 g_file_info_get_name (GFileInfo *info)
1583 static guint32 attr = 0;
1584 GFileAttributeValue *value;
1586 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1589 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
1591 value = g_file_info_find_value (info, attr);
1592 return _g_file_attribute_value_get_byte_string (value);
1596 * g_file_info_get_display_name:
1597 * @info: a #GFileInfo.
1599 * Gets a display name for a file.
1601 * Returns: a string containing the display name.
1604 g_file_info_get_display_name (GFileInfo *info)
1606 static guint32 attr = 0;
1607 GFileAttributeValue *value;
1609 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1612 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
1614 value = g_file_info_find_value (info, attr);
1615 return _g_file_attribute_value_get_string (value);
1619 * g_file_info_get_edit_name:
1620 * @info: a #GFileInfo.
1622 * Gets the edit name for a file.
1624 * Returns: a string containing the edit name.
1627 g_file_info_get_edit_name (GFileInfo *info)
1629 static guint32 attr = 0;
1630 GFileAttributeValue *value;
1632 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1635 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
1637 value = g_file_info_find_value (info, attr);
1638 return _g_file_attribute_value_get_string (value);
1642 * g_file_info_get_icon:
1643 * @info: a #GFileInfo.
1645 * Gets the icon for a file.
1647 * Returns: (transfer none): #GIcon for the given @info.
1650 g_file_info_get_icon (GFileInfo *info)
1652 static guint32 attr = 0;
1653 GFileAttributeValue *value;
1656 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1659 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
1661 value = g_file_info_find_value (info, attr);
1662 obj = _g_file_attribute_value_get_object (value);
1663 if (G_IS_ICON (obj))
1664 return G_ICON (obj);
1669 * g_file_info_get_symbolic_icon:
1670 * @info: a #GFileInfo.
1672 * Gets the symbolic icon for a file.
1674 * Returns: (transfer none): #GIcon for the given @info.
1679 g_file_info_get_symbolic_icon (GFileInfo *info)
1681 static guint32 attr = 0;
1682 GFileAttributeValue *value;
1685 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1688 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON);
1690 value = g_file_info_find_value (info, attr);
1691 obj = _g_file_attribute_value_get_object (value);
1692 if (G_IS_ICON (obj))
1693 return G_ICON (obj);
1698 * g_file_info_get_content_type:
1699 * @info: a #GFileInfo.
1701 * Gets the file's content type.
1703 * Returns: a string containing the file's content type.
1706 g_file_info_get_content_type (GFileInfo *info)
1708 static guint32 attr = 0;
1709 GFileAttributeValue *value;
1711 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1714 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1716 value = g_file_info_find_value (info, attr);
1717 return _g_file_attribute_value_get_string (value);
1721 * g_file_info_get_size:
1722 * @info: a #GFileInfo.
1724 * Gets the file's size.
1726 * Returns: a #goffset containing the file's size.
1729 g_file_info_get_size (GFileInfo *info)
1731 static guint32 attr = 0;
1732 GFileAttributeValue *value;
1734 g_return_val_if_fail (G_IS_FILE_INFO (info), (goffset) 0);
1737 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
1739 value = g_file_info_find_value (info, attr);
1740 return (goffset) _g_file_attribute_value_get_uint64 (value);
1744 * g_file_info_get_modification_time:
1745 * @info: a #GFileInfo.
1746 * @result: (out caller-allocates): a #GTimeVal.
1748 * Gets the modification time of the current @info and sets it
1752 g_file_info_get_modification_time (GFileInfo *info,
1755 static guint32 attr_mtime = 0, attr_mtime_usec;
1756 GFileAttributeValue *value;
1758 g_return_if_fail (G_IS_FILE_INFO (info));
1759 g_return_if_fail (result != NULL);
1761 if (attr_mtime == 0)
1763 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1764 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1767 value = g_file_info_find_value (info, attr_mtime);
1768 result->tv_sec = _g_file_attribute_value_get_uint64 (value);
1769 value = g_file_info_find_value (info, attr_mtime_usec);
1770 result->tv_usec = _g_file_attribute_value_get_uint32 (value);
1774 * g_file_info_get_symlink_target:
1775 * @info: a #GFileInfo.
1777 * Gets the symlink target for a given #GFileInfo.
1779 * Returns: a string containing the symlink target.
1782 g_file_info_get_symlink_target (GFileInfo *info)
1784 static guint32 attr = 0;
1785 GFileAttributeValue *value;
1787 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1790 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
1792 value = g_file_info_find_value (info, attr);
1793 return _g_file_attribute_value_get_byte_string (value);
1797 * g_file_info_get_etag:
1798 * @info: a #GFileInfo.
1800 * Gets the <link linkend="gfile-etag">entity tag</link> for a given
1801 * #GFileInfo. See %G_FILE_ATTRIBUTE_ETAG_VALUE.
1803 * Returns: a string containing the value of the "etag:value" attribute.
1806 g_file_info_get_etag (GFileInfo *info)
1808 static guint32 attr = 0;
1809 GFileAttributeValue *value;
1811 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1814 attr = lookup_attribute (G_FILE_ATTRIBUTE_ETAG_VALUE);
1816 value = g_file_info_find_value (info, attr);
1817 return _g_file_attribute_value_get_string (value);
1821 * g_file_info_get_sort_order:
1822 * @info: a #GFileInfo.
1824 * Gets the value of the sort_order attribute from the #GFileInfo.
1825 * See %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
1827 * Returns: a #gint32 containing the value of the "standard::sort_order" attribute.
1830 g_file_info_get_sort_order (GFileInfo *info)
1832 static guint32 attr = 0;
1833 GFileAttributeValue *value;
1835 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1838 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
1840 value = g_file_info_find_value (info, attr);
1841 return _g_file_attribute_value_get_int32 (value);
1844 /* Helper setters: */
1846 * g_file_info_set_file_type:
1847 * @info: a #GFileInfo.
1848 * @type: a #GFileType.
1850 * Sets the file type in a #GFileInfo to @type.
1851 * See %G_FILE_ATTRIBUTE_STANDARD_TYPE.
1854 g_file_info_set_file_type (GFileInfo *info,
1857 static guint32 attr = 0;
1858 GFileAttributeValue *value;
1860 g_return_if_fail (G_IS_FILE_INFO (info));
1863 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
1865 value = g_file_info_create_value (info, attr);
1867 _g_file_attribute_value_set_uint32 (value, type);
1871 * g_file_info_set_is_hidden:
1872 * @info: a #GFileInfo.
1873 * @is_hidden: a #gboolean.
1875 * Sets the "is_hidden" attribute in a #GFileInfo according to @is_hidden.
1876 * See %G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN.
1879 g_file_info_set_is_hidden (GFileInfo *info,
1882 static guint32 attr = 0;
1883 GFileAttributeValue *value;
1885 g_return_if_fail (G_IS_FILE_INFO (info));
1888 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
1890 value = g_file_info_create_value (info, attr);
1892 _g_file_attribute_value_set_boolean (value, is_hidden);
1896 * g_file_info_set_is_symlink:
1897 * @info: a #GFileInfo.
1898 * @is_symlink: a #gboolean.
1900 * Sets the "is_symlink" attribute in a #GFileInfo according to @is_symlink.
1901 * See %G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK.
1904 g_file_info_set_is_symlink (GFileInfo *info,
1905 gboolean is_symlink)
1907 static guint32 attr = 0;
1908 GFileAttributeValue *value;
1910 g_return_if_fail (G_IS_FILE_INFO (info));
1913 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
1915 value = g_file_info_create_value (info, attr);
1917 _g_file_attribute_value_set_boolean (value, is_symlink);
1921 * g_file_info_set_name:
1922 * @info: a #GFileInfo.
1923 * @name: a string containing a name.
1925 * Sets the name attribute for the current #GFileInfo.
1926 * See %G_FILE_ATTRIBUTE_STANDARD_NAME.
1929 g_file_info_set_name (GFileInfo *info,
1932 static guint32 attr = 0;
1933 GFileAttributeValue *value;
1935 g_return_if_fail (G_IS_FILE_INFO (info));
1936 g_return_if_fail (name != NULL);
1939 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
1941 value = g_file_info_create_value (info, attr);
1943 _g_file_attribute_value_set_byte_string (value, name);
1947 * g_file_info_set_display_name:
1948 * @info: a #GFileInfo.
1949 * @display_name: a string containing a display name.
1951 * Sets the display name for the current #GFileInfo.
1952 * See %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.
1955 g_file_info_set_display_name (GFileInfo *info,
1956 const char *display_name)
1958 static guint32 attr = 0;
1959 GFileAttributeValue *value;
1961 g_return_if_fail (G_IS_FILE_INFO (info));
1962 g_return_if_fail (display_name != NULL);
1965 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
1967 value = g_file_info_create_value (info, attr);
1969 _g_file_attribute_value_set_string (value, display_name);
1973 * g_file_info_set_edit_name:
1974 * @info: a #GFileInfo.
1975 * @edit_name: a string containing an edit name.
1977 * Sets the edit name for the current file.
1978 * See %G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME.
1981 g_file_info_set_edit_name (GFileInfo *info,
1982 const char *edit_name)
1984 static guint32 attr = 0;
1985 GFileAttributeValue *value;
1987 g_return_if_fail (G_IS_FILE_INFO (info));
1988 g_return_if_fail (edit_name != NULL);
1991 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
1993 value = g_file_info_create_value (info, attr);
1995 _g_file_attribute_value_set_string (value, edit_name);
1999 * g_file_info_set_icon:
2000 * @info: a #GFileInfo.
2003 * Sets the icon for a given #GFileInfo.
2004 * See %G_FILE_ATTRIBUTE_STANDARD_ICON.
2007 g_file_info_set_icon (GFileInfo *info,
2010 static guint32 attr = 0;
2011 GFileAttributeValue *value;
2013 g_return_if_fail (G_IS_FILE_INFO (info));
2014 g_return_if_fail (G_IS_ICON (icon));
2017 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
2019 value = g_file_info_create_value (info, attr);
2021 _g_file_attribute_value_set_object (value, G_OBJECT (icon));
2025 * g_file_info_set_symbolic_icon:
2026 * @info: a #GFileInfo.
2029 * Sets the symbolic icon for a given #GFileInfo.
2030 * See %G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON.
2035 g_file_info_set_symbolic_icon (GFileInfo *info,
2038 static guint32 attr = 0;
2039 GFileAttributeValue *value;
2041 g_return_if_fail (G_IS_FILE_INFO (info));
2042 g_return_if_fail (G_IS_ICON (icon));
2045 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON);
2047 value = g_file_info_create_value (info, attr);
2049 _g_file_attribute_value_set_object (value, G_OBJECT (icon));
2053 * g_file_info_set_content_type:
2054 * @info: a #GFileInfo.
2055 * @content_type: a content type. See <link linkend="gio-GContentType">GContentType</link>.
2057 * Sets the content type attribute for a given #GFileInfo.
2058 * See %G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE.
2061 g_file_info_set_content_type (GFileInfo *info,
2062 const char *content_type)
2064 static guint32 attr = 0;
2065 GFileAttributeValue *value;
2067 g_return_if_fail (G_IS_FILE_INFO (info));
2068 g_return_if_fail (content_type != NULL);
2071 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
2073 value = g_file_info_create_value (info, attr);
2075 _g_file_attribute_value_set_string (value, content_type);
2079 * g_file_info_set_size:
2080 * @info: a #GFileInfo.
2081 * @size: a #goffset containing the file's size.
2083 * Sets the %G_FILE_ATTRIBUTE_STANDARD_SIZE attribute in the file info
2084 * to the given size.
2087 g_file_info_set_size (GFileInfo *info,
2090 static guint32 attr = 0;
2091 GFileAttributeValue *value;
2093 g_return_if_fail (G_IS_FILE_INFO (info));
2096 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
2098 value = g_file_info_create_value (info, attr);
2100 _g_file_attribute_value_set_uint64 (value, size);
2104 * g_file_info_set_modification_time:
2105 * @info: a #GFileInfo.
2106 * @mtime: a #GTimeVal.
2108 * Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute in the file
2109 * info to the given time value.
2112 g_file_info_set_modification_time (GFileInfo *info,
2115 static guint32 attr_mtime = 0, attr_mtime_usec;
2116 GFileAttributeValue *value;
2118 g_return_if_fail (G_IS_FILE_INFO (info));
2119 g_return_if_fail (mtime != NULL);
2121 if (attr_mtime == 0)
2123 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
2124 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
2127 value = g_file_info_create_value (info, attr_mtime);
2129 _g_file_attribute_value_set_uint64 (value, mtime->tv_sec);
2130 value = g_file_info_create_value (info, attr_mtime_usec);
2132 _g_file_attribute_value_set_uint32 (value, mtime->tv_usec);
2136 * g_file_info_set_symlink_target:
2137 * @info: a #GFileInfo.
2138 * @symlink_target: a static string containing a path to a symlink target.
2140 * Sets the %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET attribute in the file info
2141 * to the given symlink target.
2144 g_file_info_set_symlink_target (GFileInfo *info,
2145 const char *symlink_target)
2147 static guint32 attr = 0;
2148 GFileAttributeValue *value;
2150 g_return_if_fail (G_IS_FILE_INFO (info));
2151 g_return_if_fail (symlink_target != NULL);
2154 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
2156 value = g_file_info_create_value (info, attr);
2158 _g_file_attribute_value_set_byte_string (value, symlink_target);
2162 * g_file_info_set_sort_order:
2163 * @info: a #GFileInfo.
2164 * @sort_order: a sort order integer.
2166 * Sets the sort order attribute in the file info structure. See
2167 * %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
2170 g_file_info_set_sort_order (GFileInfo *info,
2173 static guint32 attr = 0;
2174 GFileAttributeValue *value;
2176 g_return_if_fail (G_IS_FILE_INFO (info));
2179 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
2181 value = g_file_info_create_value (info, attr);
2183 _g_file_attribute_value_set_int32 (value, sort_order);
2192 struct _GFileAttributeMatcher {
2196 GArray *sub_matchers;
2199 guint32 iterator_ns;
2203 G_DEFINE_BOXED_TYPE (GFileAttributeMatcher, g_file_attribute_matcher,
2204 g_file_attribute_matcher_ref,
2205 g_file_attribute_matcher_unref)
2208 compare_sub_matchers (gconstpointer a,
2211 const SubMatcher *suba = a;
2212 const SubMatcher *subb = b;
2215 diff = suba->id - subb->id;
2220 return suba->mask - subb->mask;
2224 sub_matcher_matches (SubMatcher *matcher,
2225 SubMatcher *submatcher)
2227 if ((matcher->mask & submatcher->mask) != matcher->mask)
2230 return matcher->id == (submatcher->id & matcher->mask);
2233 /* Call this function after modifying a matcher.
2234 * It will ensure all the invariants other functions rely on.
2236 static GFileAttributeMatcher *
2237 matcher_optimize (GFileAttributeMatcher *matcher)
2239 SubMatcher *submatcher, *compare;
2242 /* remove sub_matchers if we match everything anyway */
2245 if (matcher->sub_matchers)
2247 g_array_free (matcher->sub_matchers, TRUE);
2248 matcher->sub_matchers = NULL;
2253 if (matcher->sub_matchers->len == 0)
2255 g_file_attribute_matcher_unref (matcher);
2259 /* sort sub_matchers by id (and then mask), so we can bsearch
2260 * and compare matchers in O(N) instead of O(N²) */
2261 g_array_sort (matcher->sub_matchers, compare_sub_matchers);
2263 /* remove duplicates and specific matches when we match the whole namespace */
2265 compare = &g_array_index (matcher->sub_matchers, SubMatcher, j);
2267 for (i = 1; i < matcher->sub_matchers->len; i++)
2269 submatcher = &g_array_index (matcher->sub_matchers, SubMatcher, i);
2270 if (sub_matcher_matches (compare, submatcher))
2277 *compare = *submatcher;
2280 g_array_set_size (matcher->sub_matchers, j + 1);
2286 * g_file_attribute_matcher_new:
2287 * @attributes: an attribute string to match.
2289 * Creates a new file attribute matcher, which matches attributes
2290 * against a given string. #GFileAttributeMatcher<!-- -->s are reference
2291 * counted structures, and are created with a reference count of 1. If
2292 * the number of references falls to 0, the #GFileAttributeMatcher is
2293 * automatically destroyed.
2295 * The @attribute string should be formatted with specific keys separated
2296 * from namespaces with a double colon. Several "namespace::key" strings may be
2297 * concatenated with a single comma (e.g. "standard::type,standard::is-hidden").
2298 * The wildcard "*" may be used to match all keys and namespaces, or
2299 * "namespace::*" will match all keys in a given namespace.
2301 * Examples of strings to use:
2303 * <title>File Attribute Matcher strings and results</title>
2304 * <tgroup cols='2' align='left'><thead>
2305 * <row><entry> Matcher String </entry><entry> Matches </entry></row></thead>
2307 * <row><entry>"*"</entry><entry>matches all attributes.</entry></row>
2308 * <row><entry>"standard::is-hidden"</entry><entry>matches only the key is-hidden in the standard namespace.</entry></row>
2309 * <row><entry>"standard::type,unix::*"</entry><entry>matches the type key in the standard namespace and
2310 * all keys in the unix namespace.</entry></row>
2314 * Returns: a #GFileAttributeMatcher.
2316 GFileAttributeMatcher *
2317 g_file_attribute_matcher_new (const char *attributes)
2322 GFileAttributeMatcher *matcher;
2324 if (attributes == NULL || *attributes == '\0')
2327 matcher = g_malloc0 (sizeof (GFileAttributeMatcher));
2329 matcher->sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
2331 split = g_strsplit (attributes, ",", -1);
2333 for (i = 0; split[i] != NULL; i++)
2335 if (strcmp (split[i], "*") == 0)
2336 matcher->all = TRUE;
2341 colon = strstr (split[i], "::");
2342 if (colon != NULL &&
2347 s.id = lookup_attribute (split[i]);
2348 s.mask = 0xffffffff;
2355 s.id = lookup_namespace (split[i]) << NS_POS;
2356 s.mask = NS_MASK << NS_POS;
2359 g_array_append_val (matcher->sub_matchers, s);
2365 matcher = matcher_optimize (matcher);
2371 * g_file_attribute_matcher_subtract:
2372 * @matcher: Matcher to subtract from
2373 * @subtract: The matcher to subtract
2375 * Subtracts all attributes of @subtract from @matcher and returns
2376 * a matcher that supports those attributes.
2378 * Note that currently it is not possible to remove a single
2379 * attribute when the @matcher matches the whole namespace - or remove
2380 * a namespace or attribute when the matcher matches everything. This
2381 * is a limitation of the current implementation, but may be fixed
2384 * Returns: A file attribute matcher matching all attributes of
2385 * @matcher that are not matched by @subtract
2387 GFileAttributeMatcher *
2388 g_file_attribute_matcher_subtract (GFileAttributeMatcher *matcher,
2389 GFileAttributeMatcher *subtract)
2391 GFileAttributeMatcher *result;
2393 SubMatcher *msub, *ssub;
2395 if (matcher == NULL)
2397 if (subtract == NULL)
2398 return g_file_attribute_matcher_ref (matcher);
2402 return g_file_attribute_matcher_ref (matcher);
2404 result = g_malloc0 (sizeof (GFileAttributeMatcher));
2406 result->sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
2409 g_assert (subtract->sub_matchers->len > 0);
2410 ssub = &g_array_index (subtract->sub_matchers, SubMatcher, si);
2412 for (mi = 0; mi < matcher->sub_matchers->len; mi++)
2414 msub = &g_array_index (matcher->sub_matchers, SubMatcher, mi);
2417 if (sub_matcher_matches (ssub, msub))
2421 if (si >= subtract->sub_matchers->len)
2424 ssub = &g_array_index (subtract->sub_matchers, SubMatcher, si);
2425 if (ssub->id <= msub->id)
2428 g_array_append_val (result->sub_matchers, *msub);
2431 if (mi < matcher->sub_matchers->len)
2432 g_array_append_vals (result->sub_matchers,
2433 &g_array_index (matcher->sub_matchers, SubMatcher, mi),
2434 matcher->sub_matchers->len - mi);
2436 result = matcher_optimize (result);
2442 * g_file_attribute_matcher_ref:
2443 * @matcher: a #GFileAttributeMatcher.
2445 * References a file attribute matcher.
2447 * Returns: a #GFileAttributeMatcher.
2449 GFileAttributeMatcher *
2450 g_file_attribute_matcher_ref (GFileAttributeMatcher *matcher)
2454 g_return_val_if_fail (matcher->ref > 0, NULL);
2455 g_atomic_int_inc (&matcher->ref);
2461 * g_file_attribute_matcher_unref:
2462 * @matcher: a #GFileAttributeMatcher.
2464 * Unreferences @matcher. If the reference count falls below 1,
2465 * the @matcher is automatically freed.
2469 g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher)
2473 g_return_if_fail (matcher->ref > 0);
2475 if (g_atomic_int_dec_and_test (&matcher->ref))
2477 if (matcher->sub_matchers)
2478 g_array_free (matcher->sub_matchers, TRUE);
2486 * g_file_attribute_matcher_matches_only:
2487 * @matcher: a #GFileAttributeMatcher.
2488 * @attribute: a file attribute key.
2490 * Checks if a attribute matcher only matches a given attribute. Always
2491 * returns %FALSE if "*" was used when creating the matcher.
2493 * Returns: %TRUE if the matcher only matches @attribute. %FALSE otherwise.
2496 g_file_attribute_matcher_matches_only (GFileAttributeMatcher *matcher,
2497 const char *attribute)
2499 SubMatcher *sub_matcher;
2502 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
2504 if (matcher == NULL ||
2508 if (matcher->sub_matchers->len != 1)
2511 id = lookup_attribute (attribute);
2513 sub_matcher = &g_array_index (matcher->sub_matchers, SubMatcher, 0);
2515 return sub_matcher->id == id &&
2516 sub_matcher->mask == 0xffffffff;
2520 matcher_matches_id (GFileAttributeMatcher *matcher,
2523 SubMatcher *sub_matchers;
2526 if (matcher->sub_matchers)
2528 sub_matchers = (SubMatcher *)matcher->sub_matchers->data;
2529 for (i = 0; i < matcher->sub_matchers->len; i++)
2531 if (sub_matchers[i].id == (id & sub_matchers[i].mask))
2540 _g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
2543 /* We return a NULL matcher for an empty match string, so handle this */
2544 if (matcher == NULL)
2550 return matcher_matches_id (matcher, id);
2554 * g_file_attribute_matcher_matches:
2555 * @matcher: a #GFileAttributeMatcher.
2556 * @attribute: a file attribute key.
2558 * Checks if an attribute will be matched by an attribute matcher. If
2559 * the matcher was created with the "*" matching string, this function
2560 * will always return %TRUE.
2562 * Returns: %TRUE if @attribute matches @matcher. %FALSE otherwise.
2565 g_file_attribute_matcher_matches (GFileAttributeMatcher *matcher,
2566 const char *attribute)
2568 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
2570 /* We return a NULL matcher for an empty match string, so handle this */
2571 if (matcher == NULL)
2577 return matcher_matches_id (matcher, lookup_attribute (attribute));
2580 /* return TRUE -> all */
2582 * g_file_attribute_matcher_enumerate_namespace:
2583 * @matcher: a #GFileAttributeMatcher.
2584 * @ns: a string containing a file attribute namespace.
2586 * Checks if the matcher will match all of the keys in a given namespace.
2587 * This will always return %TRUE if a wildcard character is in use (e.g. if
2588 * matcher was created with "standard::*" and @ns is "standard", or if matcher was created
2589 * using "*" and namespace is anything.)
2591 * TODO: this is awkwardly worded.
2593 * Returns: %TRUE if the matcher matches all of the entries
2594 * in the given @ns, %FALSE otherwise.
2597 g_file_attribute_matcher_enumerate_namespace (GFileAttributeMatcher *matcher,
2600 SubMatcher *sub_matchers;
2604 g_return_val_if_fail (ns != NULL && *ns != '\0', FALSE);
2606 /* We return a NULL matcher for an empty match string, so handle this */
2607 if (matcher == NULL)
2613 ns_id = lookup_namespace (ns) << NS_POS;
2615 if (matcher->sub_matchers)
2617 sub_matchers = (SubMatcher *)matcher->sub_matchers->data;
2618 for (i = 0; i < matcher->sub_matchers->len; i++)
2620 if (sub_matchers[i].id == ns_id)
2625 matcher->iterator_ns = ns_id;
2626 matcher->iterator_pos = 0;
2632 * g_file_attribute_matcher_enumerate_next:
2633 * @matcher: a #GFileAttributeMatcher.
2635 * Gets the next matched attribute from a #GFileAttributeMatcher.
2637 * Returns: a string containing the next attribute or %NULL if
2638 * no more attribute exist.
2641 g_file_attribute_matcher_enumerate_next (GFileAttributeMatcher *matcher)
2644 SubMatcher *sub_matcher;
2646 /* We return a NULL matcher for an empty match string, so handle this */
2647 if (matcher == NULL)
2652 i = matcher->iterator_pos++;
2654 if (matcher->sub_matchers == NULL)
2657 if (i < matcher->sub_matchers->len)
2658 sub_matcher = &g_array_index (matcher->sub_matchers, SubMatcher, i);
2662 if (sub_matcher->mask == 0xffffffff &&
2663 (sub_matcher->id & (NS_MASK << NS_POS)) == matcher->iterator_ns)
2664 return get_attribute_for_id (sub_matcher->id);
2669 * g_file_attribute_matcher_to_string:
2670 * @matcher: (allow-none): a #GFileAttributeMatcher.
2672 * Prints what the matcher is matching against. The format will be
2673 * equal to the format passed to g_file_attribute_matcher_new().
2674 * The output however, might not be identical, as the matcher may
2675 * decide to use a different order or omit needless parts.
2677 * Returns: a string describing the attributes the matcher matches
2678 * against or %NULL if @matcher was %NULL.
2683 g_file_attribute_matcher_to_string (GFileAttributeMatcher *matcher)
2688 if (matcher == NULL)
2692 return g_strdup ("*");
2694 string = g_string_new ("");
2695 for (i = 0; i < matcher->sub_matchers->len; i++)
2697 SubMatcher *submatcher = &g_array_index (matcher->sub_matchers, SubMatcher, i);
2700 g_string_append_c (string, ',');
2702 g_string_append (string, get_attribute_for_id (submatcher->id));
2705 return g_string_free (string, FALSE);