/src/rauc/subprojects/glib-2.76.5/gio/gfileinfo.c
Line | Count | Source |
1 | | /* GIO - GLib Input, Output and Streaming Library |
2 | | * |
3 | | * Copyright (C) 2006-2007 Red Hat, Inc. |
4 | | * |
5 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
6 | | * |
7 | | * This library is free software; you can redistribute it and/or |
8 | | * modify it under the terms of the GNU Lesser General Public |
9 | | * License as published by the Free Software Foundation; either |
10 | | * version 2.1 of the License, or (at your option) any later version. |
11 | | * |
12 | | * This library is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | | * Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General |
18 | | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
19 | | * |
20 | | * Author: Alexander Larsson <alexl@redhat.com> |
21 | | */ |
22 | | |
23 | | /** |
24 | | * SECTION:gfileinfo |
25 | | * @short_description: File Information and Attributes |
26 | | * @include: gio/gio.h |
27 | | * @see_also: #GFile, [GFileAttribute][gio-GFileAttribute] |
28 | | * |
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. |
32 | | * |
33 | | * See [GFileAttribute][gio-GFileAttribute] for more information on how |
34 | | * GIO handles file attributes. |
35 | | * |
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). |
40 | | * |
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. |
44 | | * |
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. |
50 | | * |
51 | | * The direct accessors, such as g_file_info_get_name(), are slightly more |
52 | | * optimized than the generic attribute accessors, such as |
53 | | * g_file_info_get_attribute_byte_string().This optimization will matter |
54 | | * only if calling the API in a tight loop. |
55 | | * |
56 | | * It is an error to call these accessors without specifying their required file |
57 | | * attributes when creating the #GFileInfo. Use g_file_info_has_attribute() or |
58 | | * g_file_info_list_attributes() to check what attributes are specified for a |
59 | | * #GFileInfo. |
60 | | * |
61 | | * #GFileAttributeMatcher allows for searching through a #GFileInfo for |
62 | | * attributes. |
63 | | **/ |
64 | | |
65 | | #include "config.h" |
66 | | |
67 | | #include <string.h> |
68 | | |
69 | | #include "gfileinfo.h" |
70 | | #include "gfileinfo-priv.h" |
71 | | #include "gfileattribute-priv.h" |
72 | | #include "gicon.h" |
73 | | #include "glibintl.h" |
74 | | |
75 | | |
76 | | /* We use this nasty thing, because NULL is a valid attribute matcher (matches nothing) */ |
77 | 290k | #define NO_ATTRIBUTE_MASK ((GFileAttributeMatcher *)1) |
78 | | |
79 | | typedef struct { |
80 | | guint32 attribute; |
81 | | GFileAttributeValue value; |
82 | | } GFileAttribute; |
83 | | |
84 | | struct _GFileInfo |
85 | | { |
86 | | GObject parent_instance; |
87 | | |
88 | | GArray *attributes; |
89 | | GFileAttributeMatcher *mask; |
90 | | }; |
91 | | |
92 | | struct _GFileInfoClass |
93 | | { |
94 | | GObjectClass parent_class; |
95 | | }; |
96 | | |
97 | | |
98 | 98.6k | G_DEFINE_TYPE (GFileInfo, g_file_info, G_TYPE_OBJECT) |
99 | 98.6k | |
100 | 98.6k | typedef struct { |
101 | 98.6k | guint32 id; |
102 | 98.6k | guint32 attribute_id_counter; |
103 | 98.6k | } NSInfo; |
104 | 98.6k | |
105 | 98.6k | G_LOCK_DEFINE_STATIC (attribute_hash); |
106 | 98.6k | static int namespace_id_counter = 0; |
107 | 98.6k | static GHashTable *ns_hash = NULL; |
108 | 98.6k | static GHashTable *attribute_hash = NULL; |
109 | 98.6k | static char ***global_attributes = NULL; |
110 | 98.6k | |
111 | 98.6k | /* Attribute ids are 32bit, we split it up like this: |
112 | 98.6k | * |------------|--------------------| |
113 | 98.6k | * 12 bit 20 bit |
114 | 98.6k | * namespace attribute id |
115 | 98.6k | * |
116 | 98.6k | * This way the attributes gets sorted in namespace order |
117 | 98.6k | */ |
118 | 98.6k | |
119 | 98.6k | #define NS_POS 20 |
120 | 11.0k | #define NS_MASK ((guint32)((1<<12) - 1)) |
121 | 96 | #define ID_POS 0 |
122 | 96 | #define ID_MASK ((guint32)((1<<20) - 1)) |
123 | | |
124 | | #define GET_NS(_attr_id) \ |
125 | 0 | (((guint32) (_attr_id) >> NS_POS) & NS_MASK) |
126 | | #define GET_ID(_attr_id) \ |
127 | 0 | (((guint32)(_attr_id) >> ID_POS) & ID_MASK) |
128 | | |
129 | | #define MAKE_ATTR_ID(_ns, _id) \ |
130 | 96 | ( ((((guint32) _ns) & NS_MASK) << NS_POS) | \ |
131 | 96 | ((((guint32) _id) & ID_MASK) << ID_POS) ) |
132 | | |
133 | | static NSInfo * |
134 | | _lookup_namespace (const char *namespace) |
135 | 11.0k | { |
136 | 11.0k | NSInfo *ns_info; |
137 | | |
138 | 11.0k | ns_info = g_hash_table_lookup (ns_hash, namespace); |
139 | 11.0k | if (ns_info == NULL) |
140 | 17 | { |
141 | 17 | ns_info = g_new0 (NSInfo, 1); |
142 | 17 | ns_info->id = ++namespace_id_counter; |
143 | 17 | g_hash_table_insert (ns_hash, g_strdup (namespace), ns_info); |
144 | 17 | global_attributes = g_realloc (global_attributes, (ns_info->id + 1) * sizeof (char **)); |
145 | 17 | global_attributes[ns_info->id] = g_new (char *, 1); |
146 | 17 | global_attributes[ns_info->id][0] = g_strconcat (namespace, "::*", NULL); |
147 | 17 | } |
148 | 11.0k | return ns_info; |
149 | 11.0k | } |
150 | | |
151 | | static guint32 |
152 | | _lookup_attribute (const char *attribute) |
153 | 5.57k | { |
154 | 5.57k | guint32 attr_id, id; |
155 | 5.57k | char *ns; |
156 | 5.57k | const char *colon; |
157 | 5.57k | NSInfo *ns_info; |
158 | | |
159 | 5.57k | attr_id = GPOINTER_TO_UINT (g_hash_table_lookup (attribute_hash, attribute)); |
160 | | |
161 | 5.57k | if (attr_id != 0) |
162 | 5.48k | return attr_id; |
163 | | |
164 | 96 | colon = strstr (attribute, "::"); |
165 | 96 | if (colon) |
166 | 96 | ns = g_strndup (attribute, colon - attribute); |
167 | 0 | else |
168 | 0 | ns = g_strdup (""); |
169 | | |
170 | 96 | ns_info = _lookup_namespace (ns); |
171 | 96 | g_free (ns); |
172 | | |
173 | 96 | id = ++ns_info->attribute_id_counter; |
174 | 96 | global_attributes[ns_info->id] = g_realloc (global_attributes[ns_info->id], (id + 1) * sizeof (char *)); |
175 | 96 | global_attributes[ns_info->id][id] = g_strdup (attribute); |
176 | | |
177 | 96 | attr_id = MAKE_ATTR_ID (ns_info->id, id); |
178 | | |
179 | 96 | g_hash_table_insert (attribute_hash, global_attributes[ns_info->id][id], GUINT_TO_POINTER (attr_id)); |
180 | | |
181 | 96 | return attr_id; |
182 | 5.57k | } |
183 | | |
184 | | static void |
185 | | ensure_attribute_hash (void) |
186 | 16.4k | { |
187 | 16.4k | if (attribute_hash != NULL) |
188 | 16.4k | return; |
189 | | |
190 | 1 | ns_hash = g_hash_table_new (g_str_hash, g_str_equal); |
191 | 1 | attribute_hash = g_hash_table_new (g_str_hash, g_str_equal); |
192 | | |
193 | 96 | #define REGISTER_ATTRIBUTE(name) G_STMT_START{\ |
194 | 96 | guint _u G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */; \ |
195 | 96 | _u = _lookup_attribute (G_FILE_ATTRIBUTE_ ## name); \ |
196 | | /* use for generating the ID: g_print ("#define G_FILE_ATTRIBUTE_ID_%s (%u + %u)\n", #name + 17, _u & ~ID_MASK, _u & ID_MASK); */ \ |
197 | 96 | g_assert (_u == G_FILE_ATTRIBUTE_ID_ ## name); \ |
198 | 96 | }G_STMT_END |
199 | | |
200 | 1 | REGISTER_ATTRIBUTE (STANDARD_TYPE); |
201 | 1 | REGISTER_ATTRIBUTE (STANDARD_IS_HIDDEN); |
202 | 1 | REGISTER_ATTRIBUTE (STANDARD_IS_BACKUP); |
203 | 1 | REGISTER_ATTRIBUTE (STANDARD_IS_SYMLINK); |
204 | 1 | REGISTER_ATTRIBUTE (STANDARD_IS_VIRTUAL); |
205 | 1 | REGISTER_ATTRIBUTE (STANDARD_NAME); |
206 | 1 | REGISTER_ATTRIBUTE (STANDARD_DISPLAY_NAME); |
207 | 1 | REGISTER_ATTRIBUTE (STANDARD_EDIT_NAME); |
208 | 1 | REGISTER_ATTRIBUTE (STANDARD_COPY_NAME); |
209 | 1 | REGISTER_ATTRIBUTE (STANDARD_DESCRIPTION); |
210 | 1 | REGISTER_ATTRIBUTE (STANDARD_ICON); |
211 | 1 | REGISTER_ATTRIBUTE (STANDARD_CONTENT_TYPE); |
212 | 1 | REGISTER_ATTRIBUTE (STANDARD_FAST_CONTENT_TYPE); |
213 | 1 | REGISTER_ATTRIBUTE (STANDARD_SIZE); |
214 | 1 | REGISTER_ATTRIBUTE (STANDARD_ALLOCATED_SIZE); |
215 | 1 | REGISTER_ATTRIBUTE (STANDARD_SYMLINK_TARGET); |
216 | 1 | REGISTER_ATTRIBUTE (STANDARD_TARGET_URI); |
217 | 1 | REGISTER_ATTRIBUTE (STANDARD_SORT_ORDER); |
218 | 1 | REGISTER_ATTRIBUTE (STANDARD_SYMBOLIC_ICON); |
219 | 1 | REGISTER_ATTRIBUTE (STANDARD_IS_VOLATILE); |
220 | 1 | REGISTER_ATTRIBUTE (ETAG_VALUE); |
221 | 1 | REGISTER_ATTRIBUTE (ID_FILE); |
222 | 1 | REGISTER_ATTRIBUTE (ID_FILESYSTEM); |
223 | 1 | REGISTER_ATTRIBUTE (ACCESS_CAN_READ); |
224 | 1 | REGISTER_ATTRIBUTE (ACCESS_CAN_WRITE); |
225 | 1 | REGISTER_ATTRIBUTE (ACCESS_CAN_EXECUTE); |
226 | 1 | REGISTER_ATTRIBUTE (ACCESS_CAN_DELETE); |
227 | 1 | REGISTER_ATTRIBUTE (ACCESS_CAN_TRASH); |
228 | 1 | REGISTER_ATTRIBUTE (ACCESS_CAN_RENAME); |
229 | 1 | REGISTER_ATTRIBUTE (MOUNTABLE_CAN_MOUNT); |
230 | 1 | REGISTER_ATTRIBUTE (MOUNTABLE_CAN_UNMOUNT); |
231 | 1 | REGISTER_ATTRIBUTE (MOUNTABLE_CAN_EJECT); |
232 | 1 | REGISTER_ATTRIBUTE (MOUNTABLE_UNIX_DEVICE); |
233 | 1 | REGISTER_ATTRIBUTE (MOUNTABLE_UNIX_DEVICE_FILE); |
234 | 1 | REGISTER_ATTRIBUTE (MOUNTABLE_HAL_UDI); |
235 | 1 | REGISTER_ATTRIBUTE (MOUNTABLE_CAN_START); |
236 | 1 | REGISTER_ATTRIBUTE (MOUNTABLE_CAN_START_DEGRADED); |
237 | 1 | REGISTER_ATTRIBUTE (MOUNTABLE_CAN_STOP); |
238 | 1 | REGISTER_ATTRIBUTE (MOUNTABLE_START_STOP_TYPE); |
239 | 1 | REGISTER_ATTRIBUTE (MOUNTABLE_CAN_POLL); |
240 | 1 | REGISTER_ATTRIBUTE (MOUNTABLE_IS_MEDIA_CHECK_AUTOMATIC); |
241 | 1 | REGISTER_ATTRIBUTE (TIME_MODIFIED); |
242 | 1 | REGISTER_ATTRIBUTE (TIME_MODIFIED_USEC); |
243 | 1 | REGISTER_ATTRIBUTE (TIME_ACCESS); |
244 | 1 | REGISTER_ATTRIBUTE (TIME_ACCESS_USEC); |
245 | 1 | REGISTER_ATTRIBUTE (TIME_CHANGED); |
246 | 1 | REGISTER_ATTRIBUTE (TIME_CHANGED_USEC); |
247 | 1 | REGISTER_ATTRIBUTE (TIME_CREATED); |
248 | 1 | REGISTER_ATTRIBUTE (TIME_CREATED_USEC); |
249 | 1 | REGISTER_ATTRIBUTE (TIME_MODIFIED_NSEC); |
250 | 1 | REGISTER_ATTRIBUTE (TIME_ACCESS_NSEC); |
251 | 1 | REGISTER_ATTRIBUTE (TIME_CREATED_NSEC); |
252 | 1 | REGISTER_ATTRIBUTE (TIME_CHANGED_NSEC); |
253 | 1 | REGISTER_ATTRIBUTE (UNIX_DEVICE); |
254 | 1 | REGISTER_ATTRIBUTE (UNIX_INODE); |
255 | 1 | REGISTER_ATTRIBUTE (UNIX_MODE); |
256 | 1 | REGISTER_ATTRIBUTE (UNIX_NLINK); |
257 | 1 | REGISTER_ATTRIBUTE (UNIX_UID); |
258 | 1 | REGISTER_ATTRIBUTE (UNIX_GID); |
259 | 1 | REGISTER_ATTRIBUTE (UNIX_RDEV); |
260 | 1 | REGISTER_ATTRIBUTE (UNIX_BLOCK_SIZE); |
261 | 1 | REGISTER_ATTRIBUTE (UNIX_BLOCKS); |
262 | 1 | REGISTER_ATTRIBUTE (UNIX_IS_MOUNTPOINT); |
263 | 1 | REGISTER_ATTRIBUTE (DOS_IS_ARCHIVE); |
264 | 1 | REGISTER_ATTRIBUTE (DOS_IS_SYSTEM); |
265 | 1 | REGISTER_ATTRIBUTE (DOS_IS_MOUNTPOINT); |
266 | 1 | REGISTER_ATTRIBUTE (DOS_REPARSE_POINT_TAG); |
267 | 1 | REGISTER_ATTRIBUTE (OWNER_USER); |
268 | 1 | REGISTER_ATTRIBUTE (OWNER_USER_REAL); |
269 | 1 | REGISTER_ATTRIBUTE (OWNER_GROUP); |
270 | 1 | REGISTER_ATTRIBUTE (THUMBNAIL_PATH); |
271 | 1 | REGISTER_ATTRIBUTE (THUMBNAILING_FAILED); |
272 | 1 | REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID); |
273 | 1 | REGISTER_ATTRIBUTE (THUMBNAIL_PATH_NORMAL); |
274 | 1 | REGISTER_ATTRIBUTE (THUMBNAILING_FAILED_NORMAL); |
275 | 1 | REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID_NORMAL); |
276 | 1 | REGISTER_ATTRIBUTE (THUMBNAIL_PATH_LARGE); |
277 | 1 | REGISTER_ATTRIBUTE (THUMBNAILING_FAILED_LARGE); |
278 | 1 | REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID_LARGE); |
279 | 1 | REGISTER_ATTRIBUTE (THUMBNAIL_PATH_XLARGE); |
280 | 1 | REGISTER_ATTRIBUTE (THUMBNAILING_FAILED_XLARGE); |
281 | 1 | REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID_XLARGE); |
282 | 1 | REGISTER_ATTRIBUTE (THUMBNAIL_PATH_XXLARGE); |
283 | 1 | REGISTER_ATTRIBUTE (THUMBNAILING_FAILED_XXLARGE); |
284 | 1 | REGISTER_ATTRIBUTE (THUMBNAIL_IS_VALID_XXLARGE); |
285 | 1 | REGISTER_ATTRIBUTE (PREVIEW_ICON); |
286 | 1 | REGISTER_ATTRIBUTE (FILESYSTEM_SIZE); |
287 | 1 | REGISTER_ATTRIBUTE (FILESYSTEM_FREE); |
288 | 1 | REGISTER_ATTRIBUTE (FILESYSTEM_TYPE); |
289 | 1 | REGISTER_ATTRIBUTE (FILESYSTEM_READONLY); |
290 | 1 | REGISTER_ATTRIBUTE (FILESYSTEM_USE_PREVIEW); |
291 | 1 | REGISTER_ATTRIBUTE (GVFS_BACKEND); |
292 | 1 | REGISTER_ATTRIBUTE (SELINUX_CONTEXT); |
293 | 1 | REGISTER_ATTRIBUTE (TRASH_ITEM_COUNT); |
294 | 1 | REGISTER_ATTRIBUTE (TRASH_ORIG_PATH); |
295 | 1 | REGISTER_ATTRIBUTE (TRASH_DELETION_DATE); |
296 | | |
297 | 1 | #undef REGISTER_ATTRIBUTE |
298 | 1 | } |
299 | | |
300 | | static guint32 |
301 | | lookup_namespace (const char *namespace) |
302 | 10.9k | { |
303 | 10.9k | NSInfo *ns_info; |
304 | 10.9k | guint32 id; |
305 | | |
306 | 10.9k | G_LOCK (attribute_hash); |
307 | | |
308 | 10.9k | ensure_attribute_hash (); |
309 | | |
310 | 10.9k | ns_info = _lookup_namespace (namespace); |
311 | 10.9k | id = 0; |
312 | 10.9k | if (ns_info) |
313 | 10.9k | id = ns_info->id; |
314 | | |
315 | 10.9k | G_UNLOCK (attribute_hash); |
316 | | |
317 | 10.9k | return id; |
318 | 10.9k | } |
319 | | |
320 | | static char * |
321 | | get_attribute_for_id (int attribute) |
322 | 0 | { |
323 | 0 | char *s; |
324 | 0 | G_LOCK (attribute_hash); |
325 | 0 | s = global_attributes[GET_NS (attribute)][GET_ID (attribute)]; |
326 | 0 | G_UNLOCK (attribute_hash); |
327 | 0 | return s; |
328 | 0 | } |
329 | | |
330 | | static guint32 |
331 | | lookup_attribute (const char *attribute) |
332 | 5.48k | { |
333 | 5.48k | guint32 attr_id; |
334 | | |
335 | 5.48k | G_LOCK (attribute_hash); |
336 | 5.48k | ensure_attribute_hash (); |
337 | | |
338 | 5.48k | attr_id = _lookup_attribute (attribute); |
339 | | |
340 | 5.48k | G_UNLOCK (attribute_hash); |
341 | | |
342 | 5.48k | return attr_id; |
343 | 5.48k | } |
344 | | |
345 | | static void |
346 | | g_file_info_finalize (GObject *object) |
347 | 5.47k | { |
348 | 5.47k | GFileInfo *info; |
349 | 5.47k | guint i; |
350 | 5.47k | GFileAttribute *attrs; |
351 | | |
352 | 5.47k | info = G_FILE_INFO (object); |
353 | | |
354 | 5.47k | attrs = (GFileAttribute *)info->attributes->data; |
355 | 10.9k | for (i = 0; i < info->attributes->len; i++) |
356 | 5.47k | _g_file_attribute_value_clear (&attrs[i].value); |
357 | 5.47k | g_array_free (info->attributes, TRUE); |
358 | | |
359 | 5.47k | if (info->mask != NO_ATTRIBUTE_MASK) |
360 | 0 | g_file_attribute_matcher_unref (info->mask); |
361 | | |
362 | 5.47k | G_OBJECT_CLASS (g_file_info_parent_class)->finalize (object); |
363 | 5.47k | } |
364 | | |
365 | | static void |
366 | | g_file_info_class_init (GFileInfoClass *klass) |
367 | 1 | { |
368 | 1 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass); |
369 | | |
370 | 1 | gobject_class->finalize = g_file_info_finalize; |
371 | 1 | } |
372 | | |
373 | | static void |
374 | | g_file_info_init (GFileInfo *info) |
375 | 5.47k | { |
376 | 5.47k | info->mask = NO_ATTRIBUTE_MASK; |
377 | 5.47k | info->attributes = g_array_new (FALSE, FALSE, |
378 | 5.47k | sizeof (GFileAttribute)); |
379 | 5.47k | } |
380 | | |
381 | | /** |
382 | | * g_file_info_new: |
383 | | * |
384 | | * Creates a new file info structure. |
385 | | * |
386 | | * Returns: a #GFileInfo. |
387 | | **/ |
388 | | GFileInfo * |
389 | | g_file_info_new (void) |
390 | 5.47k | { |
391 | 5.47k | return g_object_new (G_TYPE_FILE_INFO, NULL); |
392 | 5.47k | } |
393 | | |
394 | | /** |
395 | | * g_file_info_copy_into: |
396 | | * @src_info: source to copy attributes from. |
397 | | * @dest_info: destination to copy attributes to. |
398 | | * |
399 | | * First clears all of the [GFileAttribute][gio-GFileAttribute] of @dest_info, |
400 | | * and then copies all of the file attributes from @src_info to @dest_info. |
401 | | **/ |
402 | | void |
403 | | g_file_info_copy_into (GFileInfo *src_info, |
404 | | GFileInfo *dest_info) |
405 | 0 | { |
406 | 0 | GFileAttribute *source, *dest; |
407 | 0 | guint i; |
408 | |
|
409 | 0 | g_return_if_fail (G_IS_FILE_INFO (src_info)); |
410 | 0 | g_return_if_fail (G_IS_FILE_INFO (dest_info)); |
411 | | |
412 | 0 | dest = (GFileAttribute *)dest_info->attributes->data; |
413 | 0 | for (i = 0; i < dest_info->attributes->len; i++) |
414 | 0 | _g_file_attribute_value_clear (&dest[i].value); |
415 | |
|
416 | 0 | g_array_set_size (dest_info->attributes, |
417 | 0 | src_info->attributes->len); |
418 | |
|
419 | 0 | source = (GFileAttribute *)src_info->attributes->data; |
420 | 0 | dest = (GFileAttribute *)dest_info->attributes->data; |
421 | |
|
422 | 0 | for (i = 0; i < src_info->attributes->len; i++) |
423 | 0 | { |
424 | 0 | dest[i].attribute = source[i].attribute; |
425 | 0 | dest[i].value.type = G_FILE_ATTRIBUTE_TYPE_INVALID; |
426 | 0 | _g_file_attribute_value_set (&dest[i].value, &source[i].value); |
427 | 0 | } |
428 | |
|
429 | 0 | if (dest_info->mask != NO_ATTRIBUTE_MASK) |
430 | 0 | g_file_attribute_matcher_unref (dest_info->mask); |
431 | |
|
432 | 0 | if (src_info->mask == NO_ATTRIBUTE_MASK) |
433 | 0 | dest_info->mask = NO_ATTRIBUTE_MASK; |
434 | 0 | else |
435 | 0 | dest_info->mask = g_file_attribute_matcher_ref (src_info->mask); |
436 | 0 | } |
437 | | |
438 | | /** |
439 | | * g_file_info_dup: |
440 | | * @other: a #GFileInfo. |
441 | | * |
442 | | * Duplicates a file info structure. |
443 | | * |
444 | | * Returns: (transfer full): a duplicate #GFileInfo of @other. |
445 | | **/ |
446 | | GFileInfo * |
447 | | g_file_info_dup (GFileInfo *other) |
448 | 0 | { |
449 | 0 | GFileInfo *new; |
450 | |
|
451 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (other), NULL); |
452 | | |
453 | 0 | new = g_file_info_new (); |
454 | 0 | g_file_info_copy_into (other, new); |
455 | 0 | return new; |
456 | 0 | } |
457 | | |
458 | | /** |
459 | | * g_file_info_set_attribute_mask: |
460 | | * @info: a #GFileInfo. |
461 | | * @mask: a #GFileAttributeMatcher. |
462 | | * |
463 | | * Sets @mask on @info to match specific attribute types. |
464 | | **/ |
465 | | void |
466 | | g_file_info_set_attribute_mask (GFileInfo *info, |
467 | | GFileAttributeMatcher *mask) |
468 | 5.47k | { |
469 | 5.47k | GFileAttribute *attr; |
470 | 5.47k | guint i; |
471 | | |
472 | 5.47k | g_return_if_fail (G_IS_FILE_INFO (info)); |
473 | | |
474 | 5.47k | if (mask != info->mask) |
475 | 5.47k | { |
476 | 5.47k | if (info->mask != NO_ATTRIBUTE_MASK) |
477 | 0 | g_file_attribute_matcher_unref (info->mask); |
478 | 5.47k | info->mask = g_file_attribute_matcher_ref (mask); |
479 | | |
480 | | /* Remove non-matching attributes */ |
481 | 5.47k | for (i = 0; i < info->attributes->len; i++) |
482 | 0 | { |
483 | 0 | attr = &g_array_index (info->attributes, GFileAttribute, i); |
484 | 0 | if (!_g_file_attribute_matcher_matches_id (mask, |
485 | 0 | attr->attribute)) |
486 | 0 | { |
487 | 0 | _g_file_attribute_value_clear (&attr->value); |
488 | 0 | g_array_remove_index (info->attributes, i); |
489 | 0 | i--; |
490 | 0 | } |
491 | 0 | } |
492 | 5.47k | } |
493 | 5.47k | } |
494 | | |
495 | | /** |
496 | | * g_file_info_unset_attribute_mask: |
497 | | * @info: #GFileInfo. |
498 | | * |
499 | | * Unsets a mask set by g_file_info_set_attribute_mask(), if one |
500 | | * is set. |
501 | | **/ |
502 | | void |
503 | | g_file_info_unset_attribute_mask (GFileInfo *info) |
504 | 5.47k | { |
505 | 5.47k | g_return_if_fail (G_IS_FILE_INFO (info)); |
506 | | |
507 | 5.47k | if (info->mask != NO_ATTRIBUTE_MASK) |
508 | 5.47k | g_file_attribute_matcher_unref (info->mask); |
509 | 5.47k | info->mask = NO_ATTRIBUTE_MASK; |
510 | 5.47k | } |
511 | | |
512 | | /** |
513 | | * g_file_info_clear_status: |
514 | | * @info: a #GFileInfo. |
515 | | * |
516 | | * Clears the status information from @info. |
517 | | **/ |
518 | | void |
519 | | g_file_info_clear_status (GFileInfo *info) |
520 | 0 | { |
521 | 0 | GFileAttribute *attrs; |
522 | 0 | guint i; |
523 | |
|
524 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
525 | | |
526 | 0 | attrs = (GFileAttribute *)info->attributes->data; |
527 | 0 | for (i = 0; i < info->attributes->len; i++) |
528 | 0 | attrs[i].value.status = G_FILE_ATTRIBUTE_STATUS_UNSET; |
529 | 0 | } |
530 | | |
531 | | static int |
532 | | g_file_info_find_place (GFileInfo *info, |
533 | | guint32 attribute) |
534 | 10.9k | { |
535 | 10.9k | int min, max, med; |
536 | 10.9k | GFileAttribute *attrs; |
537 | | /* Binary search for the place where attribute would be, if it's |
538 | | in the array */ |
539 | | |
540 | 10.9k | min = 0; |
541 | 10.9k | max = info->attributes->len; |
542 | | |
543 | 10.9k | attrs = (GFileAttribute *)info->attributes->data; |
544 | | |
545 | 10.9k | while (min < max) |
546 | 5.47k | { |
547 | 5.47k | med = min + (max - min) / 2; |
548 | 5.47k | if (attrs[med].attribute == attribute) |
549 | 5.47k | { |
550 | 5.47k | min = med; |
551 | 5.47k | break; |
552 | 5.47k | } |
553 | 0 | else if (attrs[med].attribute < attribute) |
554 | 0 | min = med + 1; |
555 | 0 | else /* attrs[med].attribute > attribute */ |
556 | 0 | max = med; |
557 | 5.47k | } |
558 | | |
559 | 10.9k | return min; |
560 | 10.9k | } |
561 | | |
562 | | static GFileAttributeValue * |
563 | | g_file_info_find_value (GFileInfo *info, |
564 | | guint32 attr_id) |
565 | 5.47k | { |
566 | 5.47k | GFileAttribute *attrs; |
567 | 5.47k | guint i; |
568 | | |
569 | 5.47k | i = g_file_info_find_place (info, attr_id); |
570 | 5.47k | attrs = (GFileAttribute *)info->attributes->data; |
571 | 5.47k | if (i < info->attributes->len && |
572 | 5.47k | attrs[i].attribute == attr_id) |
573 | 5.47k | return &attrs[i].value; |
574 | | |
575 | 0 | return NULL; |
576 | 5.47k | } |
577 | | |
578 | | static GFileAttributeValue * |
579 | | g_file_info_find_value_by_name (GFileInfo *info, |
580 | | const char *attribute) |
581 | 0 | { |
582 | 0 | guint32 attr_id; |
583 | |
|
584 | 0 | attr_id = lookup_attribute (attribute); |
585 | 0 | return g_file_info_find_value (info, attr_id); |
586 | 0 | } |
587 | | |
588 | | /** |
589 | | * g_file_info_has_attribute: |
590 | | * @info: a #GFileInfo. |
591 | | * @attribute: a file attribute key. |
592 | | * |
593 | | * Checks if a file info structure has an attribute named @attribute. |
594 | | * |
595 | | * Returns: %TRUE if @info has an attribute named @attribute, |
596 | | * %FALSE otherwise. |
597 | | **/ |
598 | | gboolean |
599 | | g_file_info_has_attribute (GFileInfo *info, |
600 | | const char *attribute) |
601 | 0 | { |
602 | 0 | GFileAttributeValue *value; |
603 | |
|
604 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE); |
605 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE); |
606 | | |
607 | 0 | value = g_file_info_find_value_by_name (info, attribute); |
608 | 0 | return value != NULL; |
609 | 0 | } |
610 | | |
611 | | /** |
612 | | * g_file_info_has_namespace: |
613 | | * @info: a #GFileInfo. |
614 | | * @name_space: a file attribute namespace. |
615 | | * |
616 | | * Checks if a file info structure has an attribute in the |
617 | | * specified @name_space. |
618 | | * |
619 | | * Returns: %TRUE if @info has an attribute in @name_space, |
620 | | * %FALSE otherwise. |
621 | | * |
622 | | * Since: 2.22 |
623 | | **/ |
624 | | gboolean |
625 | | g_file_info_has_namespace (GFileInfo *info, |
626 | | const char *name_space) |
627 | 0 | { |
628 | 0 | GFileAttribute *attrs; |
629 | 0 | guint32 ns_id; |
630 | 0 | guint i; |
631 | |
|
632 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE); |
633 | 0 | g_return_val_if_fail (name_space != NULL, FALSE); |
634 | | |
635 | 0 | ns_id = lookup_namespace (name_space); |
636 | |
|
637 | 0 | attrs = (GFileAttribute *)info->attributes->data; |
638 | 0 | for (i = 0; i < info->attributes->len; i++) |
639 | 0 | { |
640 | 0 | if (GET_NS (attrs[i].attribute) == ns_id) |
641 | 0 | return TRUE; |
642 | 0 | } |
643 | | |
644 | 0 | return FALSE; |
645 | 0 | } |
646 | | |
647 | | /** |
648 | | * g_file_info_list_attributes: |
649 | | * @info: a #GFileInfo. |
650 | | * @name_space: (nullable): a file attribute key's namespace, or %NULL to list |
651 | | * all attributes. |
652 | | * |
653 | | * Lists the file info structure's attributes. |
654 | | * |
655 | | * Returns: (nullable) (array zero-terminated=1) (transfer full): a |
656 | | * null-terminated array of strings of all of the possible attribute |
657 | | * types for the given @name_space, or %NULL on error. |
658 | | **/ |
659 | | char ** |
660 | | g_file_info_list_attributes (GFileInfo *info, |
661 | | const char *name_space) |
662 | 0 | { |
663 | 0 | GPtrArray *names; |
664 | 0 | GFileAttribute *attrs; |
665 | 0 | guint32 attribute; |
666 | 0 | guint32 ns_id = (name_space) ? lookup_namespace (name_space) : 0; |
667 | 0 | guint i; |
668 | |
|
669 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
670 | | |
671 | 0 | names = g_ptr_array_new (); |
672 | 0 | attrs = (GFileAttribute *)info->attributes->data; |
673 | 0 | for (i = 0; i < info->attributes->len; i++) |
674 | 0 | { |
675 | 0 | attribute = attrs[i].attribute; |
676 | 0 | if (ns_id == 0 || GET_NS (attribute) == ns_id) |
677 | 0 | g_ptr_array_add (names, g_strdup (get_attribute_for_id (attribute))); |
678 | 0 | } |
679 | | |
680 | | /* NULL terminate */ |
681 | 0 | g_ptr_array_add (names, NULL); |
682 | |
|
683 | 0 | return (char **)g_ptr_array_free (names, FALSE); |
684 | 0 | } |
685 | | |
686 | | /** |
687 | | * g_file_info_get_attribute_type: |
688 | | * @info: a #GFileInfo. |
689 | | * @attribute: a file attribute key. |
690 | | * |
691 | | * Gets the attribute type for an attribute key. |
692 | | * |
693 | | * Returns: a #GFileAttributeType for the given @attribute, or |
694 | | * %G_FILE_ATTRIBUTE_TYPE_INVALID if the key is not set. |
695 | | **/ |
696 | | GFileAttributeType |
697 | | g_file_info_get_attribute_type (GFileInfo *info, |
698 | | const char *attribute) |
699 | 0 | { |
700 | 0 | GFileAttributeValue *value; |
701 | |
|
702 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_ATTRIBUTE_TYPE_INVALID); |
703 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', G_FILE_ATTRIBUTE_TYPE_INVALID); |
704 | | |
705 | 0 | value = g_file_info_find_value_by_name (info, attribute); |
706 | 0 | if (value) |
707 | 0 | return value->type; |
708 | 0 | else |
709 | 0 | return G_FILE_ATTRIBUTE_TYPE_INVALID; |
710 | 0 | } |
711 | | |
712 | | static void |
713 | | g_file_info_remove_value (GFileInfo *info, |
714 | | guint32 attr_id) |
715 | 0 | { |
716 | 0 | GFileAttribute *attrs; |
717 | 0 | guint i; |
718 | |
|
719 | 0 | if (info->mask != NO_ATTRIBUTE_MASK && |
720 | 0 | !_g_file_attribute_matcher_matches_id (info->mask, attr_id)) |
721 | 0 | return; |
722 | | |
723 | 0 | i = g_file_info_find_place (info, attr_id); |
724 | |
|
725 | 0 | attrs = (GFileAttribute *)info->attributes->data; |
726 | 0 | if (i < info->attributes->len && |
727 | 0 | attrs[i].attribute == attr_id) |
728 | 0 | { |
729 | 0 | _g_file_attribute_value_clear (&attrs[i].value); |
730 | 0 | g_array_remove_index (info->attributes, i); |
731 | 0 | } |
732 | 0 | } |
733 | | |
734 | | /** |
735 | | * g_file_info_remove_attribute: |
736 | | * @info: a #GFileInfo. |
737 | | * @attribute: a file attribute key. |
738 | | * |
739 | | * Removes all cases of @attribute from @info if it exists. |
740 | | **/ |
741 | | void |
742 | | g_file_info_remove_attribute (GFileInfo *info, |
743 | | const char *attribute) |
744 | 0 | { |
745 | 0 | guint32 attr_id; |
746 | |
|
747 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
748 | 0 | g_return_if_fail (attribute != NULL && *attribute != '\0'); |
749 | | |
750 | 0 | attr_id = lookup_attribute (attribute); |
751 | |
|
752 | 0 | g_file_info_remove_value (info, attr_id); |
753 | 0 | } |
754 | | |
755 | | /** |
756 | | * g_file_info_get_attribute_data: |
757 | | * @info: a #GFileInfo |
758 | | * @attribute: a file attribute key |
759 | | * @type: (out) (optional): return location for the attribute type, or %NULL |
760 | | * @value_pp: (out) (optional) (not nullable): return location for the |
761 | | * attribute value, or %NULL; the attribute value will not be %NULL |
762 | | * @status: (out) (optional): return location for the attribute status, or %NULL |
763 | | * |
764 | | * Gets the attribute type, value and status for an attribute key. |
765 | | * |
766 | | * Returns: (transfer none): %TRUE if @info has an attribute named @attribute, |
767 | | * %FALSE otherwise. |
768 | | */ |
769 | | gboolean |
770 | | g_file_info_get_attribute_data (GFileInfo *info, |
771 | | const char *attribute, |
772 | | GFileAttributeType *type, |
773 | | gpointer *value_pp, |
774 | | GFileAttributeStatus *status) |
775 | 0 | { |
776 | 0 | GFileAttributeValue *value; |
777 | |
|
778 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE); |
779 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE); |
780 | | |
781 | 0 | value = g_file_info_find_value_by_name (info, attribute); |
782 | 0 | if (value == NULL) |
783 | 0 | return FALSE; |
784 | | |
785 | 0 | if (status) |
786 | 0 | *status = value->status; |
787 | |
|
788 | 0 | if (type) |
789 | 0 | *type = value->type; |
790 | |
|
791 | 0 | if (value_pp) |
792 | 0 | *value_pp = _g_file_attribute_value_peek_as_pointer (value); |
793 | |
|
794 | 0 | return TRUE; |
795 | 0 | } |
796 | | |
797 | | /** |
798 | | * g_file_info_get_attribute_status: |
799 | | * @info: a #GFileInfo |
800 | | * @attribute: a file attribute key |
801 | | * |
802 | | * Gets the attribute status for an attribute key. |
803 | | * |
804 | | * Returns: a #GFileAttributeStatus for the given @attribute, or |
805 | | * %G_FILE_ATTRIBUTE_STATUS_UNSET if the key is invalid. |
806 | | * |
807 | | */ |
808 | | GFileAttributeStatus |
809 | | g_file_info_get_attribute_status (GFileInfo *info, |
810 | | const char *attribute) |
811 | 0 | { |
812 | 0 | GFileAttributeValue *val; |
813 | |
|
814 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), 0); |
815 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0); |
816 | | |
817 | 0 | val = g_file_info_find_value_by_name (info, attribute); |
818 | 0 | if (val) |
819 | 0 | return val->status; |
820 | | |
821 | 0 | return G_FILE_ATTRIBUTE_STATUS_UNSET; |
822 | 0 | } |
823 | | |
824 | | /** |
825 | | * g_file_info_set_attribute_status: |
826 | | * @info: a #GFileInfo |
827 | | * @attribute: a file attribute key |
828 | | * @status: a #GFileAttributeStatus |
829 | | * |
830 | | * Sets the attribute status for an attribute key. This is only |
831 | | * needed by external code that implement g_file_set_attributes_from_info() |
832 | | * or similar functions. |
833 | | * |
834 | | * The attribute must exist in @info for this to work. Otherwise %FALSE |
835 | | * is returned and @info is unchanged. |
836 | | * |
837 | | * Returns: %TRUE if the status was changed, %FALSE if the key was not set. |
838 | | * |
839 | | * Since: 2.22 |
840 | | */ |
841 | | gboolean |
842 | | g_file_info_set_attribute_status (GFileInfo *info, |
843 | | const char *attribute, |
844 | | GFileAttributeStatus status) |
845 | 0 | { |
846 | 0 | GFileAttributeValue *val; |
847 | |
|
848 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE); |
849 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE); |
850 | | |
851 | 0 | val = g_file_info_find_value_by_name (info, attribute); |
852 | 0 | if (val) |
853 | 0 | { |
854 | 0 | val->status = status; |
855 | 0 | return TRUE; |
856 | 0 | } |
857 | | |
858 | 0 | return FALSE; |
859 | 0 | } |
860 | | |
861 | | GFileAttributeValue * |
862 | | _g_file_info_get_attribute_value (GFileInfo *info, |
863 | | const char *attribute) |
864 | | |
865 | 0 | { |
866 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
867 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL); |
868 | | |
869 | 0 | return g_file_info_find_value_by_name (info, attribute); |
870 | 0 | } |
871 | | |
872 | | /** |
873 | | * g_file_info_get_attribute_as_string: |
874 | | * @info: a #GFileInfo. |
875 | | * @attribute: a file attribute key. |
876 | | * |
877 | | * Gets the value of an attribute, formatted as a string. |
878 | | * This escapes things as needed to make the string valid |
879 | | * UTF-8. |
880 | | * |
881 | | * Returns: (nullable): a UTF-8 string associated with the given @attribute, or |
882 | | * %NULL if the attribute wasn’t set. |
883 | | * When you're done with the string it must be freed with g_free(). |
884 | | **/ |
885 | | char * |
886 | | g_file_info_get_attribute_as_string (GFileInfo *info, |
887 | | const char *attribute) |
888 | 0 | { |
889 | 0 | GFileAttributeValue *val; |
890 | 0 | val = _g_file_info_get_attribute_value (info, attribute); |
891 | 0 | if (val) |
892 | 0 | return _g_file_attribute_value_as_string (val); |
893 | 0 | return NULL; |
894 | 0 | } |
895 | | |
896 | | |
897 | | /** |
898 | | * g_file_info_get_attribute_object: |
899 | | * @info: a #GFileInfo. |
900 | | * @attribute: a file attribute key. |
901 | | * |
902 | | * Gets the value of a #GObject attribute. If the attribute does |
903 | | * not contain a #GObject, %NULL will be returned. |
904 | | * |
905 | | * Returns: (transfer none) (nullable): a #GObject associated with the given @attribute, |
906 | | * or %NULL otherwise. |
907 | | **/ |
908 | | GObject * |
909 | | g_file_info_get_attribute_object (GFileInfo *info, |
910 | | const char *attribute) |
911 | 0 | { |
912 | 0 | GFileAttributeValue *value; |
913 | |
|
914 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
915 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL); |
916 | | |
917 | 0 | value = g_file_info_find_value_by_name (info, attribute); |
918 | 0 | return _g_file_attribute_value_get_object (value); |
919 | 0 | } |
920 | | |
921 | | /** |
922 | | * g_file_info_get_attribute_string: |
923 | | * @info: a #GFileInfo. |
924 | | * @attribute: a file attribute key. |
925 | | * |
926 | | * Gets the value of a string attribute. If the attribute does |
927 | | * not contain a string, %NULL will be returned. |
928 | | * |
929 | | * Returns: (nullable): the contents of the @attribute value as a UTF-8 string, |
930 | | * or %NULL otherwise. |
931 | | **/ |
932 | | const char * |
933 | | g_file_info_get_attribute_string (GFileInfo *info, |
934 | | const char *attribute) |
935 | 0 | { |
936 | 0 | GFileAttributeValue *value; |
937 | |
|
938 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
939 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL); |
940 | | |
941 | 0 | value = g_file_info_find_value_by_name (info, attribute); |
942 | 0 | return _g_file_attribute_value_get_string (value); |
943 | 0 | } |
944 | | |
945 | | /** |
946 | | * g_file_info_get_attribute_byte_string: |
947 | | * @info: a #GFileInfo. |
948 | | * @attribute: a file attribute key. |
949 | | * |
950 | | * Gets the value of a byte string attribute. If the attribute does |
951 | | * not contain a byte string, %NULL will be returned. |
952 | | * |
953 | | * Returns: (nullable): the contents of the @attribute value as a byte string, or |
954 | | * %NULL otherwise. |
955 | | **/ |
956 | | const char * |
957 | | g_file_info_get_attribute_byte_string (GFileInfo *info, |
958 | | const char *attribute) |
959 | 0 | { |
960 | 0 | GFileAttributeValue *value; |
961 | |
|
962 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
963 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL); |
964 | | |
965 | 0 | value = g_file_info_find_value_by_name (info, attribute); |
966 | 0 | return _g_file_attribute_value_get_byte_string (value); |
967 | 0 | } |
968 | | |
969 | | /** |
970 | | * g_file_info_get_attribute_stringv: |
971 | | * @info: a #GFileInfo. |
972 | | * @attribute: a file attribute key. |
973 | | * |
974 | | * Gets the value of a stringv attribute. If the attribute does |
975 | | * not contain a stringv, %NULL will be returned. |
976 | | * |
977 | | * Returns: (transfer none) (nullable): the contents of the @attribute value as a stringv, |
978 | | * or %NULL otherwise. Do not free. These returned strings are UTF-8. |
979 | | * |
980 | | * Since: 2.22 |
981 | | **/ |
982 | | char ** |
983 | | g_file_info_get_attribute_stringv (GFileInfo *info, |
984 | | const char *attribute) |
985 | 0 | { |
986 | 0 | GFileAttributeValue *value; |
987 | |
|
988 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
989 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL); |
990 | | |
991 | 0 | value = g_file_info_find_value_by_name (info, attribute); |
992 | 0 | return _g_file_attribute_value_get_stringv (value); |
993 | 0 | } |
994 | | |
995 | | /** |
996 | | * g_file_info_get_attribute_boolean: |
997 | | * @info: a #GFileInfo. |
998 | | * @attribute: a file attribute key. |
999 | | * |
1000 | | * Gets the value of a boolean attribute. If the attribute does not |
1001 | | * contain a boolean value, %FALSE will be returned. |
1002 | | * |
1003 | | * Returns: the boolean value contained within the attribute. |
1004 | | **/ |
1005 | | gboolean |
1006 | | g_file_info_get_attribute_boolean (GFileInfo *info, |
1007 | | const char *attribute) |
1008 | 0 | { |
1009 | 0 | GFileAttributeValue *value; |
1010 | |
|
1011 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE); |
1012 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE); |
1013 | | |
1014 | 0 | value = g_file_info_find_value_by_name (info, attribute); |
1015 | 0 | return _g_file_attribute_value_get_boolean (value); |
1016 | 0 | } |
1017 | | |
1018 | | /** |
1019 | | * g_file_info_get_attribute_uint32: |
1020 | | * @info: a #GFileInfo. |
1021 | | * @attribute: a file attribute key. |
1022 | | * |
1023 | | * Gets an unsigned 32-bit integer contained within the attribute. If the |
1024 | | * attribute does not contain an unsigned 32-bit integer, or is invalid, |
1025 | | * 0 will be returned. |
1026 | | * |
1027 | | * Returns: an unsigned 32-bit integer from the attribute. |
1028 | | **/ |
1029 | | guint32 |
1030 | | g_file_info_get_attribute_uint32 (GFileInfo *info, |
1031 | | const char *attribute) |
1032 | 0 | { |
1033 | 0 | GFileAttributeValue *value; |
1034 | |
|
1035 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), 0); |
1036 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0); |
1037 | | |
1038 | 0 | value = g_file_info_find_value_by_name (info, attribute); |
1039 | 0 | return _g_file_attribute_value_get_uint32 (value); |
1040 | 0 | } |
1041 | | |
1042 | | /** |
1043 | | * g_file_info_get_attribute_int32: |
1044 | | * @info: a #GFileInfo. |
1045 | | * @attribute: a file attribute key. |
1046 | | * |
1047 | | * Gets a signed 32-bit integer contained within the attribute. If the |
1048 | | * attribute does not contain a signed 32-bit integer, or is invalid, |
1049 | | * 0 will be returned. |
1050 | | * |
1051 | | * Returns: a signed 32-bit integer from the attribute. |
1052 | | **/ |
1053 | | gint32 |
1054 | | g_file_info_get_attribute_int32 (GFileInfo *info, |
1055 | | const char *attribute) |
1056 | 0 | { |
1057 | 0 | GFileAttributeValue *value; |
1058 | |
|
1059 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), 0); |
1060 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0); |
1061 | | |
1062 | 0 | value = g_file_info_find_value_by_name (info, attribute); |
1063 | 0 | return _g_file_attribute_value_get_int32 (value); |
1064 | 0 | } |
1065 | | |
1066 | | /** |
1067 | | * g_file_info_get_attribute_uint64: |
1068 | | * @info: a #GFileInfo. |
1069 | | * @attribute: a file attribute key. |
1070 | | * |
1071 | | * Gets a unsigned 64-bit integer contained within the attribute. If the |
1072 | | * attribute does not contain an unsigned 64-bit integer, or is invalid, |
1073 | | * 0 will be returned. |
1074 | | * |
1075 | | * Returns: a unsigned 64-bit integer from the attribute. |
1076 | | **/ |
1077 | | guint64 |
1078 | | g_file_info_get_attribute_uint64 (GFileInfo *info, |
1079 | | const char *attribute) |
1080 | 0 | { |
1081 | 0 | GFileAttributeValue *value; |
1082 | |
|
1083 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), 0); |
1084 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0); |
1085 | | |
1086 | 0 | value = g_file_info_find_value_by_name (info, attribute); |
1087 | 0 | return _g_file_attribute_value_get_uint64 (value); |
1088 | 0 | } |
1089 | | |
1090 | | /** |
1091 | | * g_file_info_get_attribute_int64: |
1092 | | * @info: a #GFileInfo. |
1093 | | * @attribute: a file attribute key. |
1094 | | * |
1095 | | * Gets a signed 64-bit integer contained within the attribute. If the |
1096 | | * attribute does not contain a signed 64-bit integer, or is invalid, |
1097 | | * 0 will be returned. |
1098 | | * |
1099 | | * Returns: a signed 64-bit integer from the attribute. |
1100 | | **/ |
1101 | | gint64 |
1102 | | g_file_info_get_attribute_int64 (GFileInfo *info, |
1103 | | const char *attribute) |
1104 | 0 | { |
1105 | 0 | GFileAttributeValue *value; |
1106 | |
|
1107 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), 0); |
1108 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0); |
1109 | | |
1110 | 0 | value = g_file_info_find_value_by_name (info, attribute); |
1111 | 0 | return _g_file_attribute_value_get_int64 (value); |
1112 | 0 | } |
1113 | | |
1114 | | static GFileAttributeValue * |
1115 | | g_file_info_create_value (GFileInfo *info, |
1116 | | guint32 attr_id) |
1117 | 131k | { |
1118 | 131k | GFileAttribute *attrs; |
1119 | 131k | guint i; |
1120 | | |
1121 | 131k | if (info->mask != NO_ATTRIBUTE_MASK && |
1122 | 131k | !_g_file_attribute_matcher_matches_id (info->mask, attr_id)) |
1123 | 126k | return NULL; |
1124 | | |
1125 | 5.47k | i = g_file_info_find_place (info, attr_id); |
1126 | | |
1127 | 5.47k | attrs = (GFileAttribute *)info->attributes->data; |
1128 | 5.47k | if (i < info->attributes->len && |
1129 | 0 | attrs[i].attribute == attr_id) |
1130 | 0 | return &attrs[i].value; |
1131 | 5.47k | else |
1132 | 5.47k | { |
1133 | 5.47k | GFileAttribute attr = { 0 }; |
1134 | 5.47k | attr.attribute = attr_id; |
1135 | 5.47k | g_array_insert_val (info->attributes, i, attr); |
1136 | | |
1137 | 5.47k | attrs = (GFileAttribute *)info->attributes->data; |
1138 | 5.47k | return &attrs[i].value; |
1139 | 5.47k | } |
1140 | 5.47k | } |
1141 | | |
1142 | | void |
1143 | | _g_file_info_set_attribute_by_id (GFileInfo *info, |
1144 | | guint32 attribute, |
1145 | | GFileAttributeType type, |
1146 | | gpointer value_p) |
1147 | 0 | { |
1148 | 0 | GFileAttributeValue *value; |
1149 | |
|
1150 | 0 | value = g_file_info_create_value (info, attribute); |
1151 | |
|
1152 | 0 | if (value) |
1153 | 0 | _g_file_attribute_value_set_from_pointer (value, type, value_p, TRUE); |
1154 | 0 | } |
1155 | | |
1156 | | /** |
1157 | | * g_file_info_set_attribute: |
1158 | | * @info: a #GFileInfo. |
1159 | | * @attribute: a file attribute key. |
1160 | | * @type: a #GFileAttributeType |
1161 | | * @value_p: (not nullable): pointer to the value |
1162 | | * |
1163 | | * Sets the @attribute to contain the given value, if possible. To unset the |
1164 | | * attribute, use %G_FILE_ATTRIBUTE_TYPE_INVALID for @type. |
1165 | | **/ |
1166 | | void |
1167 | | g_file_info_set_attribute (GFileInfo *info, |
1168 | | const char *attribute, |
1169 | | GFileAttributeType type, |
1170 | | gpointer value_p) |
1171 | 0 | { |
1172 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
1173 | 0 | g_return_if_fail (attribute != NULL && *attribute != '\0'); |
1174 | | |
1175 | 0 | _g_file_info_set_attribute_by_id (info, lookup_attribute (attribute), type, value_p); |
1176 | 0 | } |
1177 | | |
1178 | | void |
1179 | | _g_file_info_set_attribute_object_by_id (GFileInfo *info, |
1180 | | guint32 attribute, |
1181 | | GObject *attr_value) |
1182 | 0 | { |
1183 | 0 | GFileAttributeValue *value; |
1184 | |
|
1185 | 0 | value = g_file_info_create_value (info, attribute); |
1186 | 0 | if (value) |
1187 | 0 | _g_file_attribute_value_set_object (value, attr_value); |
1188 | 0 | } |
1189 | | |
1190 | | /** |
1191 | | * g_file_info_set_attribute_object: |
1192 | | * @info: a #GFileInfo. |
1193 | | * @attribute: a file attribute key. |
1194 | | * @attr_value: a #GObject. |
1195 | | * |
1196 | | * Sets the @attribute to contain the given @attr_value, |
1197 | | * if possible. |
1198 | | **/ |
1199 | | void |
1200 | | g_file_info_set_attribute_object (GFileInfo *info, |
1201 | | const char *attribute, |
1202 | | GObject *attr_value) |
1203 | 0 | { |
1204 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
1205 | 0 | g_return_if_fail (attribute != NULL && *attribute != '\0'); |
1206 | 0 | g_return_if_fail (G_IS_OBJECT (attr_value)); |
1207 | | |
1208 | 0 | _g_file_info_set_attribute_object_by_id (info, |
1209 | 0 | lookup_attribute (attribute), |
1210 | 0 | attr_value); |
1211 | 0 | } |
1212 | | |
1213 | | void |
1214 | | _g_file_info_set_attribute_stringv_by_id (GFileInfo *info, |
1215 | | guint32 attribute, |
1216 | | char **attr_value) |
1217 | 0 | { |
1218 | 0 | GFileAttributeValue *value; |
1219 | |
|
1220 | 0 | value = g_file_info_create_value (info, attribute); |
1221 | 0 | if (value) |
1222 | 0 | _g_file_attribute_value_set_stringv (value, attr_value); |
1223 | 0 | } |
1224 | | |
1225 | | /** |
1226 | | * g_file_info_set_attribute_stringv: |
1227 | | * @info: a #GFileInfo. |
1228 | | * @attribute: a file attribute key |
1229 | | * @attr_value: (array zero-terminated=1) (element-type utf8): a %NULL |
1230 | | * terminated array of UTF-8 strings. |
1231 | | * |
1232 | | * Sets the @attribute to contain the given @attr_value, |
1233 | | * if possible. |
1234 | | * |
1235 | | * Sinze: 2.22 |
1236 | | **/ |
1237 | | void |
1238 | | g_file_info_set_attribute_stringv (GFileInfo *info, |
1239 | | const char *attribute, |
1240 | | char **attr_value) |
1241 | 0 | { |
1242 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
1243 | 0 | g_return_if_fail (attribute != NULL && *attribute != '\0'); |
1244 | 0 | g_return_if_fail (attr_value != NULL); |
1245 | | |
1246 | 0 | _g_file_info_set_attribute_stringv_by_id (info, |
1247 | 0 | lookup_attribute (attribute), |
1248 | 0 | attr_value); |
1249 | 0 | } |
1250 | | |
1251 | | void |
1252 | | _g_file_info_set_attribute_string_by_id (GFileInfo *info, |
1253 | | guint32 attribute, |
1254 | | const char *attr_value) |
1255 | 0 | { |
1256 | 0 | GFileAttributeValue *value; |
1257 | |
|
1258 | 0 | value = g_file_info_create_value (info, attribute); |
1259 | 0 | if (value) |
1260 | 0 | _g_file_attribute_value_set_string (value, attr_value); |
1261 | 0 | } |
1262 | | |
1263 | | /** |
1264 | | * g_file_info_set_attribute_string: |
1265 | | * @info: a #GFileInfo. |
1266 | | * @attribute: a file attribute key. |
1267 | | * @attr_value: a UTF-8 string. |
1268 | | * |
1269 | | * Sets the @attribute to contain the given @attr_value, |
1270 | | * if possible. |
1271 | | **/ |
1272 | | void |
1273 | | g_file_info_set_attribute_string (GFileInfo *info, |
1274 | | const char *attribute, |
1275 | | const char *attr_value) |
1276 | 0 | { |
1277 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
1278 | 0 | g_return_if_fail (attribute != NULL && *attribute != '\0'); |
1279 | 0 | g_return_if_fail (attr_value != NULL); |
1280 | | |
1281 | 0 | _g_file_info_set_attribute_string_by_id (info, |
1282 | 0 | lookup_attribute (attribute), |
1283 | 0 | attr_value); |
1284 | 0 | } |
1285 | | |
1286 | | void |
1287 | | _g_file_info_set_attribute_byte_string_by_id (GFileInfo *info, |
1288 | | guint32 attribute, |
1289 | | const char *attr_value) |
1290 | 0 | { |
1291 | 0 | GFileAttributeValue *value; |
1292 | |
|
1293 | 0 | value = g_file_info_create_value (info, attribute); |
1294 | 0 | if (value) |
1295 | 0 | _g_file_attribute_value_set_byte_string (value, attr_value); |
1296 | 0 | } |
1297 | | |
1298 | | /** |
1299 | | * g_file_info_set_attribute_byte_string: |
1300 | | * @info: a #GFileInfo. |
1301 | | * @attribute: a file attribute key. |
1302 | | * @attr_value: a byte string. |
1303 | | * |
1304 | | * Sets the @attribute to contain the given @attr_value, |
1305 | | * if possible. |
1306 | | **/ |
1307 | | void |
1308 | | g_file_info_set_attribute_byte_string (GFileInfo *info, |
1309 | | const char *attribute, |
1310 | | const char *attr_value) |
1311 | 0 | { |
1312 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
1313 | 0 | g_return_if_fail (attribute != NULL && *attribute != '\0'); |
1314 | 0 | g_return_if_fail (attr_value != NULL); |
1315 | | |
1316 | 0 | _g_file_info_set_attribute_byte_string_by_id (info, |
1317 | 0 | lookup_attribute (attribute), |
1318 | 0 | attr_value); |
1319 | 0 | } |
1320 | | |
1321 | | void |
1322 | | _g_file_info_set_attribute_boolean_by_id (GFileInfo *info, |
1323 | | guint32 attribute, |
1324 | | gboolean attr_value) |
1325 | 0 | { |
1326 | 0 | GFileAttributeValue *value; |
1327 | |
|
1328 | 0 | value = g_file_info_create_value (info, attribute); |
1329 | 0 | if (value) |
1330 | 0 | _g_file_attribute_value_set_boolean (value, attr_value); |
1331 | 0 | } |
1332 | | |
1333 | | /** |
1334 | | * g_file_info_set_attribute_boolean: |
1335 | | * @info: a #GFileInfo. |
1336 | | * @attribute: a file attribute key. |
1337 | | * @attr_value: a boolean value. |
1338 | | * |
1339 | | * Sets the @attribute to contain the given @attr_value, |
1340 | | * if possible. |
1341 | | **/ |
1342 | | void |
1343 | | g_file_info_set_attribute_boolean (GFileInfo *info, |
1344 | | const char *attribute, |
1345 | | gboolean attr_value) |
1346 | 0 | { |
1347 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
1348 | 0 | g_return_if_fail (attribute != NULL && *attribute != '\0'); |
1349 | | |
1350 | 0 | _g_file_info_set_attribute_boolean_by_id (info, |
1351 | 0 | lookup_attribute (attribute), |
1352 | 0 | attr_value); |
1353 | 0 | } |
1354 | | |
1355 | | void |
1356 | | _g_file_info_set_attribute_uint32_by_id (GFileInfo *info, |
1357 | | guint32 attribute, |
1358 | | guint32 attr_value) |
1359 | 82.1k | { |
1360 | 82.1k | GFileAttributeValue *value; |
1361 | | |
1362 | 82.1k | value = g_file_info_create_value (info, attribute); |
1363 | 82.1k | if (value) |
1364 | 0 | _g_file_attribute_value_set_uint32 (value, attr_value); |
1365 | 82.1k | } |
1366 | | |
1367 | | /** |
1368 | | * g_file_info_set_attribute_uint32: |
1369 | | * @info: a #GFileInfo. |
1370 | | * @attribute: a file attribute key. |
1371 | | * @attr_value: an unsigned 32-bit integer. |
1372 | | * |
1373 | | * Sets the @attribute to contain the given @attr_value, |
1374 | | * if possible. |
1375 | | **/ |
1376 | | void |
1377 | | g_file_info_set_attribute_uint32 (GFileInfo *info, |
1378 | | const char *attribute, |
1379 | | guint32 attr_value) |
1380 | 0 | { |
1381 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
1382 | 0 | g_return_if_fail (attribute != NULL && *attribute != '\0'); |
1383 | | |
1384 | 0 | _g_file_info_set_attribute_uint32_by_id (info, |
1385 | 0 | lookup_attribute (attribute), |
1386 | 0 | attr_value); |
1387 | 0 | } |
1388 | | |
1389 | | void |
1390 | | _g_file_info_set_attribute_int32_by_id (GFileInfo *info, |
1391 | | guint32 attribute, |
1392 | | gint32 attr_value) |
1393 | 0 | { |
1394 | 0 | GFileAttributeValue *value; |
1395 | |
|
1396 | 0 | value = g_file_info_create_value (info, attribute); |
1397 | 0 | if (value) |
1398 | 0 | _g_file_attribute_value_set_int32 (value, attr_value); |
1399 | 0 | } |
1400 | | |
1401 | | /** |
1402 | | * g_file_info_set_attribute_int32: |
1403 | | * @info: a #GFileInfo. |
1404 | | * @attribute: a file attribute key. |
1405 | | * @attr_value: a signed 32-bit integer |
1406 | | * |
1407 | | * Sets the @attribute to contain the given @attr_value, |
1408 | | * if possible. |
1409 | | **/ |
1410 | | void |
1411 | | g_file_info_set_attribute_int32 (GFileInfo *info, |
1412 | | const char *attribute, |
1413 | | gint32 attr_value) |
1414 | 0 | { |
1415 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
1416 | 0 | g_return_if_fail (attribute != NULL && *attribute != '\0'); |
1417 | | |
1418 | 0 | _g_file_info_set_attribute_int32_by_id (info, |
1419 | 0 | lookup_attribute (attribute), |
1420 | 0 | attr_value); |
1421 | 0 | } |
1422 | | |
1423 | | void |
1424 | | _g_file_info_set_attribute_uint64_by_id (GFileInfo *info, |
1425 | | guint32 attribute, |
1426 | | guint64 attr_value) |
1427 | 38.3k | { |
1428 | 38.3k | GFileAttributeValue *value; |
1429 | | |
1430 | 38.3k | value = g_file_info_create_value (info, attribute); |
1431 | 38.3k | if (value) |
1432 | 0 | _g_file_attribute_value_set_uint64 (value, attr_value); |
1433 | 38.3k | } |
1434 | | |
1435 | | /** |
1436 | | * g_file_info_set_attribute_uint64: |
1437 | | * @info: a #GFileInfo. |
1438 | | * @attribute: a file attribute key. |
1439 | | * @attr_value: an unsigned 64-bit integer. |
1440 | | * |
1441 | | * Sets the @attribute to contain the given @attr_value, |
1442 | | * if possible. |
1443 | | **/ |
1444 | | void |
1445 | | g_file_info_set_attribute_uint64 (GFileInfo *info, |
1446 | | const char *attribute, |
1447 | | guint64 attr_value) |
1448 | 0 | { |
1449 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
1450 | 0 | g_return_if_fail (attribute != NULL && *attribute != '\0'); |
1451 | | |
1452 | 0 | _g_file_info_set_attribute_uint64_by_id (info, |
1453 | 0 | lookup_attribute (attribute), |
1454 | 0 | attr_value); |
1455 | 0 | } |
1456 | | |
1457 | | void |
1458 | | _g_file_info_set_attribute_int64_by_id (GFileInfo *info, |
1459 | | guint32 attribute, |
1460 | | gint64 attr_value) |
1461 | 0 | { |
1462 | 0 | GFileAttributeValue *value; |
1463 | |
|
1464 | 0 | value = g_file_info_create_value (info, attribute); |
1465 | 0 | if (value) |
1466 | 0 | _g_file_attribute_value_set_int64 (value, attr_value); |
1467 | 0 | } |
1468 | | |
1469 | | /** |
1470 | | * g_file_info_set_attribute_int64: |
1471 | | * @info: a #GFileInfo. |
1472 | | * @attribute: attribute name to set. |
1473 | | * @attr_value: int64 value to set attribute to. |
1474 | | * |
1475 | | * Sets the @attribute to contain the given @attr_value, |
1476 | | * if possible. |
1477 | | * |
1478 | | **/ |
1479 | | void |
1480 | | g_file_info_set_attribute_int64 (GFileInfo *info, |
1481 | | const char *attribute, |
1482 | | gint64 attr_value) |
1483 | 0 | { |
1484 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
1485 | 0 | g_return_if_fail (attribute != NULL && *attribute != '\0'); |
1486 | | |
1487 | 0 | _g_file_info_set_attribute_int64_by_id (info, |
1488 | 0 | lookup_attribute (attribute), |
1489 | 0 | attr_value); |
1490 | 0 | } |
1491 | | |
1492 | | /* Helper getters */ |
1493 | | #define get_required_attribute(value_ptr, info, attribute_name, error_value) \ |
1494 | 5.47k | G_STMT_START { \ |
1495 | 5.47k | static guint32 attr = 0; \ |
1496 | 5.47k | \ |
1497 | 5.47k | if (attr == 0) \ |
1498 | 5.47k | attr = lookup_attribute (attribute_name); \ |
1499 | 5.47k | \ |
1500 | 5.47k | *value_ptr = g_file_info_find_value (info, attr); \ |
1501 | 5.47k | if (G_UNLIKELY (*value_ptr == NULL)) \ |
1502 | 5.47k | { \ |
1503 | 0 | g_debug ("GFileInfo created without " attribute_name); \ |
1504 | 0 | return error_value; \ |
1505 | 0 | } \ |
1506 | 5.47k | } G_STMT_END |
1507 | | |
1508 | | /** |
1509 | | * g_file_info_get_deletion_date: |
1510 | | * @info: a #GFileInfo. |
1511 | | * |
1512 | | * Returns the #GDateTime representing the deletion date of the file, as |
1513 | | * available in %G_FILE_ATTRIBUTE_TRASH_DELETION_DATE. If the |
1514 | | * %G_FILE_ATTRIBUTE_TRASH_DELETION_DATE attribute is unset, %NULL is returned. |
1515 | | * |
1516 | | * Returns: (nullable): a #GDateTime, or %NULL. |
1517 | | * |
1518 | | * Since: 2.36 |
1519 | | **/ |
1520 | | GDateTime * |
1521 | | g_file_info_get_deletion_date (GFileInfo *info) |
1522 | 0 | { |
1523 | 0 | static guint32 attr = 0; |
1524 | 0 | GFileAttributeValue *value; |
1525 | 0 | const char *date_str; |
1526 | 0 | GTimeZone *local_tz = NULL; |
1527 | 0 | GDateTime *dt = NULL; |
1528 | |
|
1529 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE); |
1530 | | |
1531 | 0 | if (attr == 0) |
1532 | 0 | attr = lookup_attribute (G_FILE_ATTRIBUTE_TRASH_DELETION_DATE); |
1533 | |
|
1534 | 0 | value = g_file_info_find_value (info, attr); |
1535 | 0 | date_str = _g_file_attribute_value_get_string (value); |
1536 | 0 | if (!date_str) |
1537 | 0 | return NULL; |
1538 | | |
1539 | 0 | local_tz = g_time_zone_new_local (); |
1540 | 0 | dt = g_date_time_new_from_iso8601 (date_str, local_tz); |
1541 | 0 | g_time_zone_unref (local_tz); |
1542 | |
|
1543 | 0 | return g_steal_pointer (&dt); |
1544 | 0 | } |
1545 | | |
1546 | | /** |
1547 | | * g_file_info_get_file_type: |
1548 | | * @info: a #GFileInfo. |
1549 | | * |
1550 | | * Gets a file's type (whether it is a regular file, symlink, etc). |
1551 | | * This is different from the file's content type, see g_file_info_get_content_type(). |
1552 | | * |
1553 | | * It is an error to call this if the #GFileInfo does not contain |
1554 | | * %G_FILE_ATTRIBUTE_STANDARD_TYPE. |
1555 | | * |
1556 | | * Returns: a #GFileType for the given file. |
1557 | | **/ |
1558 | | GFileType |
1559 | | g_file_info_get_file_type (GFileInfo *info) |
1560 | 5.47k | { |
1561 | 5.47k | GFileAttributeValue *value; |
1562 | | |
1563 | 5.47k | g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_TYPE_UNKNOWN); |
1564 | | |
1565 | 5.47k | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_TYPE_UNKNOWN); |
1566 | 5.47k | return (GFileType)_g_file_attribute_value_get_uint32 (value); |
1567 | 5.47k | } |
1568 | | |
1569 | | /** |
1570 | | * g_file_info_get_is_hidden: |
1571 | | * @info: a #GFileInfo. |
1572 | | * |
1573 | | * Checks if a file is hidden. |
1574 | | * |
1575 | | * It is an error to call this if the #GFileInfo does not contain |
1576 | | * %G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN. |
1577 | | * |
1578 | | * Returns: %TRUE if the file is a hidden file, %FALSE otherwise. |
1579 | | **/ |
1580 | | gboolean |
1581 | | g_file_info_get_is_hidden (GFileInfo *info) |
1582 | 0 | { |
1583 | 0 | GFileAttributeValue *value; |
1584 | |
|
1585 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE); |
1586 | | |
1587 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN, FALSE); |
1588 | 0 | return _g_file_attribute_value_get_boolean (value); |
1589 | 0 | } |
1590 | | |
1591 | | /** |
1592 | | * g_file_info_get_is_backup: |
1593 | | * @info: a #GFileInfo. |
1594 | | * |
1595 | | * Checks if a file is a backup file. |
1596 | | * |
1597 | | * It is an error to call this if the #GFileInfo does not contain |
1598 | | * %G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP. |
1599 | | * |
1600 | | * Returns: %TRUE if file is a backup file, %FALSE otherwise. |
1601 | | **/ |
1602 | | gboolean |
1603 | | g_file_info_get_is_backup (GFileInfo *info) |
1604 | 0 | { |
1605 | 0 | GFileAttributeValue *value; |
1606 | |
|
1607 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE); |
1608 | | |
1609 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP, FALSE); |
1610 | 0 | return _g_file_attribute_value_get_boolean (value); |
1611 | 0 | } |
1612 | | |
1613 | | /** |
1614 | | * g_file_info_get_is_symlink: |
1615 | | * @info: a #GFileInfo. |
1616 | | * |
1617 | | * Checks if a file is a symlink. |
1618 | | * |
1619 | | * It is an error to call this if the #GFileInfo does not contain |
1620 | | * %G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK. |
1621 | | * |
1622 | | * Returns: %TRUE if the given @info is a symlink. |
1623 | | **/ |
1624 | | gboolean |
1625 | | g_file_info_get_is_symlink (GFileInfo *info) |
1626 | 0 | { |
1627 | 0 | GFileAttributeValue *value; |
1628 | |
|
1629 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE); |
1630 | | |
1631 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK, FALSE); |
1632 | 0 | return _g_file_attribute_value_get_boolean (value); |
1633 | 0 | } |
1634 | | |
1635 | | /** |
1636 | | * g_file_info_get_name: |
1637 | | * @info: a #GFileInfo. |
1638 | | * |
1639 | | * Gets the name for a file. This is guaranteed to always be set. |
1640 | | * |
1641 | | * It is an error to call this if the #GFileInfo does not contain |
1642 | | * %G_FILE_ATTRIBUTE_STANDARD_NAME. |
1643 | | * |
1644 | | * Returns: (type filename) (not nullable): a string containing the file name. |
1645 | | **/ |
1646 | | const char * |
1647 | | g_file_info_get_name (GFileInfo *info) |
1648 | 0 | { |
1649 | 0 | GFileAttributeValue *value; |
1650 | |
|
1651 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
1652 | | |
1653 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_NAME, NULL); |
1654 | 0 | return _g_file_attribute_value_get_byte_string (value); |
1655 | 0 | } |
1656 | | |
1657 | | /** |
1658 | | * g_file_info_get_display_name: |
1659 | | * @info: a #GFileInfo. |
1660 | | * |
1661 | | * Gets a display name for a file. This is guaranteed to always be set. |
1662 | | * |
1663 | | * It is an error to call this if the #GFileInfo does not contain |
1664 | | * %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME. |
1665 | | * |
1666 | | * Returns: (not nullable): a string containing the display name. |
1667 | | **/ |
1668 | | const char * |
1669 | | g_file_info_get_display_name (GFileInfo *info) |
1670 | 0 | { |
1671 | 0 | GFileAttributeValue *value; |
1672 | |
|
1673 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
1674 | | |
1675 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, NULL); |
1676 | 0 | return _g_file_attribute_value_get_string (value); |
1677 | 0 | } |
1678 | | |
1679 | | /** |
1680 | | * g_file_info_get_edit_name: |
1681 | | * @info: a #GFileInfo. |
1682 | | * |
1683 | | * Gets the edit name for a file. |
1684 | | * |
1685 | | * It is an error to call this if the #GFileInfo does not contain |
1686 | | * %G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME. |
1687 | | * |
1688 | | * Returns: a string containing the edit name. |
1689 | | **/ |
1690 | | const char * |
1691 | | g_file_info_get_edit_name (GFileInfo *info) |
1692 | 0 | { |
1693 | 0 | GFileAttributeValue *value; |
1694 | |
|
1695 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
1696 | | |
1697 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME, NULL); |
1698 | 0 | return _g_file_attribute_value_get_string (value); |
1699 | 0 | } |
1700 | | |
1701 | | /** |
1702 | | * g_file_info_get_icon: |
1703 | | * @info: a #GFileInfo. |
1704 | | * |
1705 | | * Gets the icon for a file. |
1706 | | * |
1707 | | * It is an error to call this if the #GFileInfo does not contain |
1708 | | * %G_FILE_ATTRIBUTE_STANDARD_ICON. |
1709 | | * |
1710 | | * Returns: (nullable) (transfer none): #GIcon for the given @info. |
1711 | | **/ |
1712 | | GIcon * |
1713 | | g_file_info_get_icon (GFileInfo *info) |
1714 | 0 | { |
1715 | 0 | GFileAttributeValue *value; |
1716 | 0 | GObject *obj; |
1717 | |
|
1718 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
1719 | | |
1720 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_ICON, NULL); |
1721 | | |
1722 | 0 | obj = _g_file_attribute_value_get_object (value); |
1723 | 0 | if (G_IS_ICON (obj)) |
1724 | 0 | return G_ICON (obj); |
1725 | 0 | return NULL; |
1726 | 0 | } |
1727 | | |
1728 | | /** |
1729 | | * g_file_info_get_symbolic_icon: |
1730 | | * @info: a #GFileInfo. |
1731 | | * |
1732 | | * Gets the symbolic icon for a file. |
1733 | | * |
1734 | | * It is an error to call this if the #GFileInfo does not contain |
1735 | | * %G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON. |
1736 | | * |
1737 | | * Returns: (nullable) (transfer none): #GIcon for the given @info. |
1738 | | * |
1739 | | * Since: 2.34 |
1740 | | **/ |
1741 | | GIcon * |
1742 | | g_file_info_get_symbolic_icon (GFileInfo *info) |
1743 | 0 | { |
1744 | 0 | GFileAttributeValue *value; |
1745 | 0 | GObject *obj; |
1746 | |
|
1747 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
1748 | | |
1749 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON, NULL); |
1750 | | |
1751 | 0 | obj = _g_file_attribute_value_get_object (value); |
1752 | 0 | if (G_IS_ICON (obj)) |
1753 | 0 | return G_ICON (obj); |
1754 | 0 | return NULL; |
1755 | 0 | } |
1756 | | |
1757 | | /** |
1758 | | * g_file_info_get_content_type: |
1759 | | * @info: a #GFileInfo. |
1760 | | * |
1761 | | * Gets the file's content type. |
1762 | | * |
1763 | | * It is an error to call this if the #GFileInfo does not contain |
1764 | | * %G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE. |
1765 | | * |
1766 | | * Returns: (nullable): a string containing the file's content type, |
1767 | | * or %NULL if unknown. |
1768 | | **/ |
1769 | | const char * |
1770 | | g_file_info_get_content_type (GFileInfo *info) |
1771 | 0 | { |
1772 | 0 | GFileAttributeValue *value; |
1773 | |
|
1774 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
1775 | | |
1776 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, NULL); |
1777 | 0 | return _g_file_attribute_value_get_string (value); |
1778 | 0 | } |
1779 | | |
1780 | | /** |
1781 | | * g_file_info_get_size: |
1782 | | * @info: a #GFileInfo. |
1783 | | * |
1784 | | * Gets the file's size (in bytes). The size is retrieved through the value of |
1785 | | * the %G_FILE_ATTRIBUTE_STANDARD_SIZE attribute and is converted |
1786 | | * from #guint64 to #goffset before returning the result. |
1787 | | * |
1788 | | * It is an error to call this if the #GFileInfo does not contain |
1789 | | * %G_FILE_ATTRIBUTE_STANDARD_SIZE. |
1790 | | * |
1791 | | * Returns: a #goffset containing the file's size (in bytes). |
1792 | | **/ |
1793 | | goffset |
1794 | | g_file_info_get_size (GFileInfo *info) |
1795 | 0 | { |
1796 | 0 | GFileAttributeValue *value; |
1797 | |
|
1798 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), (goffset) 0); |
1799 | | |
1800 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_SIZE, (goffset) 0); |
1801 | 0 | return (goffset) _g_file_attribute_value_get_uint64 (value); |
1802 | 0 | } |
1803 | | |
1804 | | /** |
1805 | | * g_file_info_get_modification_time: |
1806 | | * @info: a #GFileInfo. |
1807 | | * @result: (out caller-allocates): a #GTimeVal. |
1808 | | * |
1809 | | * Gets the modification time of the current @info and sets it |
1810 | | * in @result. |
1811 | | * |
1812 | | * It is an error to call this if the #GFileInfo does not contain |
1813 | | * %G_FILE_ATTRIBUTE_TIME_MODIFIED. If %G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC is |
1814 | | * provided it will be used too. |
1815 | | * |
1816 | | * Deprecated: 2.62: Use g_file_info_get_modification_date_time() instead, as |
1817 | | * #GTimeVal is deprecated due to the year 2038 problem. |
1818 | | **/ |
1819 | | G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
1820 | | void |
1821 | | g_file_info_get_modification_time (GFileInfo *info, |
1822 | | GTimeVal *result) |
1823 | 0 | { |
1824 | 0 | static guint32 attr_mtime = 0, attr_mtime_usec; |
1825 | 0 | GFileAttributeValue *value; |
1826 | |
|
1827 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
1828 | 0 | g_return_if_fail (result != NULL); |
1829 | | |
1830 | 0 | if (attr_mtime == 0) |
1831 | 0 | { |
1832 | 0 | attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED); |
1833 | 0 | attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC); |
1834 | 0 | } |
1835 | |
|
1836 | 0 | value = g_file_info_find_value (info, attr_mtime); |
1837 | |
|
1838 | 0 | if (G_UNLIKELY (value == NULL)) |
1839 | 0 | { |
1840 | 0 | g_debug ("GFileInfo created without " G_FILE_ATTRIBUTE_TIME_MODIFIED); |
1841 | 0 | result->tv_sec = result->tv_usec = 0; |
1842 | 0 | return; |
1843 | 0 | } |
1844 | | |
1845 | 0 | result->tv_sec = _g_file_attribute_value_get_uint64 (value); |
1846 | 0 | value = g_file_info_find_value (info, attr_mtime_usec); |
1847 | 0 | result->tv_usec = _g_file_attribute_value_get_uint32 (value); |
1848 | 0 | } |
1849 | | G_GNUC_END_IGNORE_DEPRECATIONS |
1850 | | |
1851 | | /** |
1852 | | * g_file_info_get_modification_date_time: |
1853 | | * @info: a #GFileInfo. |
1854 | | * |
1855 | | * Gets the modification time of the current @info and returns it as a |
1856 | | * #GDateTime. |
1857 | | * |
1858 | | * It is an error to call this if the #GFileInfo does not contain |
1859 | | * %G_FILE_ATTRIBUTE_TIME_MODIFIED. If %G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC is |
1860 | | * provided, the resulting #GDateTime will additionally have microsecond |
1861 | | * precision. |
1862 | | * |
1863 | | * If nanosecond precision is needed, %G_FILE_ATTRIBUTE_TIME_MODIFIED_NSEC must |
1864 | | * be queried separately using g_file_info_get_attribute_uint32(). |
1865 | | * |
1866 | | * Returns: (transfer full) (nullable): modification time, or %NULL if unknown |
1867 | | * Since: 2.62 |
1868 | | */ |
1869 | | GDateTime * |
1870 | | g_file_info_get_modification_date_time (GFileInfo *info) |
1871 | 0 | { |
1872 | 0 | static guint32 attr_mtime = 0, attr_mtime_usec; |
1873 | 0 | GFileAttributeValue *value, *value_usec; |
1874 | 0 | GDateTime *dt = NULL, *dt2 = NULL; |
1875 | |
|
1876 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
1877 | | |
1878 | 0 | if (attr_mtime == 0) |
1879 | 0 | { |
1880 | 0 | attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED); |
1881 | 0 | attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC); |
1882 | 0 | } |
1883 | |
|
1884 | 0 | value = g_file_info_find_value (info, attr_mtime); |
1885 | 0 | if (value == NULL) |
1886 | 0 | return NULL; |
1887 | | |
1888 | 0 | dt = g_date_time_new_from_unix_utc (_g_file_attribute_value_get_uint64 (value)); |
1889 | |
|
1890 | 0 | value_usec = g_file_info_find_value (info, attr_mtime_usec); |
1891 | 0 | if (value_usec == NULL) |
1892 | 0 | return g_steal_pointer (&dt); |
1893 | | |
1894 | 0 | dt2 = g_date_time_add (dt, _g_file_attribute_value_get_uint32 (value_usec)); |
1895 | 0 | g_date_time_unref (dt); |
1896 | |
|
1897 | 0 | return g_steal_pointer (&dt2); |
1898 | 0 | } |
1899 | | |
1900 | | /** |
1901 | | * g_file_info_get_access_date_time: |
1902 | | * @info: a #GFileInfo. |
1903 | | * |
1904 | | * Gets the access time of the current @info and returns it as a |
1905 | | * #GDateTime. |
1906 | | * |
1907 | | * It is an error to call this if the #GFileInfo does not contain |
1908 | | * %G_FILE_ATTRIBUTE_TIME_ACCESS. If %G_FILE_ATTRIBUTE_TIME_ACCESS_USEC is |
1909 | | * provided, the resulting #GDateTime will additionally have microsecond |
1910 | | * precision. |
1911 | | * |
1912 | | * If nanosecond precision is needed, %G_FILE_ATTRIBUTE_TIME_ACCESS_NSEC must |
1913 | | * be queried separately using g_file_info_get_attribute_uint32(). |
1914 | | * |
1915 | | * Returns: (transfer full) (nullable): access time, or %NULL if unknown |
1916 | | * Since: 2.70 |
1917 | | */ |
1918 | | GDateTime * |
1919 | | g_file_info_get_access_date_time (GFileInfo *info) |
1920 | 0 | { |
1921 | 0 | static guint32 attr_atime = 0, attr_atime_usec; |
1922 | 0 | GFileAttributeValue *value, *value_usec; |
1923 | 0 | GDateTime *dt = NULL, *dt2 = NULL; |
1924 | |
|
1925 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
1926 | | |
1927 | 0 | if (attr_atime == 0) |
1928 | 0 | { |
1929 | 0 | attr_atime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_ACCESS); |
1930 | 0 | attr_atime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_ACCESS_USEC); |
1931 | 0 | } |
1932 | |
|
1933 | 0 | value = g_file_info_find_value (info, attr_atime); |
1934 | 0 | if (value == NULL) |
1935 | 0 | return NULL; |
1936 | | |
1937 | 0 | dt = g_date_time_new_from_unix_utc (_g_file_attribute_value_get_uint64 (value)); |
1938 | |
|
1939 | 0 | value_usec = g_file_info_find_value (info, attr_atime_usec); |
1940 | 0 | if (value_usec == NULL) |
1941 | 0 | return g_steal_pointer (&dt); |
1942 | | |
1943 | 0 | dt2 = g_date_time_add (dt, _g_file_attribute_value_get_uint32 (value_usec)); |
1944 | 0 | g_date_time_unref (dt); |
1945 | |
|
1946 | 0 | return g_steal_pointer (&dt2); |
1947 | 0 | } |
1948 | | |
1949 | | /** |
1950 | | * g_file_info_get_creation_date_time: |
1951 | | * @info: a #GFileInfo. |
1952 | | * |
1953 | | * Gets the creation time of the current @info and returns it as a |
1954 | | * #GDateTime. |
1955 | | * |
1956 | | * It is an error to call this if the #GFileInfo does not contain |
1957 | | * %G_FILE_ATTRIBUTE_TIME_CREATED. If %G_FILE_ATTRIBUTE_TIME_CREATED_USEC is |
1958 | | * provided, the resulting #GDateTime will additionally have microsecond |
1959 | | * precision. |
1960 | | * |
1961 | | * If nanosecond precision is needed, %G_FILE_ATTRIBUTE_TIME_CREATED_NSEC must |
1962 | | * be queried separately using g_file_info_get_attribute_uint32(). |
1963 | | * |
1964 | | * Returns: (transfer full) (nullable): creation time, or %NULL if unknown |
1965 | | * Since: 2.70 |
1966 | | */ |
1967 | | GDateTime * |
1968 | | g_file_info_get_creation_date_time (GFileInfo *info) |
1969 | 0 | { |
1970 | 0 | static guint32 attr_ctime = 0, attr_ctime_usec; |
1971 | 0 | GFileAttributeValue *value, *value_usec; |
1972 | 0 | GDateTime *dt = NULL, *dt2 = NULL; |
1973 | |
|
1974 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
1975 | | |
1976 | 0 | if (attr_ctime == 0) |
1977 | 0 | { |
1978 | 0 | attr_ctime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_CREATED); |
1979 | 0 | attr_ctime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_CREATED_USEC); |
1980 | 0 | } |
1981 | |
|
1982 | 0 | value = g_file_info_find_value (info, attr_ctime); |
1983 | 0 | if (value == NULL) |
1984 | 0 | return NULL; |
1985 | | |
1986 | 0 | dt = g_date_time_new_from_unix_utc (_g_file_attribute_value_get_uint64 (value)); |
1987 | |
|
1988 | 0 | value_usec = g_file_info_find_value (info, attr_ctime_usec); |
1989 | 0 | if (value_usec == NULL) |
1990 | 0 | return g_steal_pointer (&dt); |
1991 | | |
1992 | 0 | dt2 = g_date_time_add (dt, _g_file_attribute_value_get_uint32 (value_usec)); |
1993 | 0 | g_date_time_unref (dt); |
1994 | |
|
1995 | 0 | return g_steal_pointer (&dt2); |
1996 | 0 | } |
1997 | | |
1998 | | /** |
1999 | | * g_file_info_get_symlink_target: |
2000 | | * @info: a #GFileInfo. |
2001 | | * |
2002 | | * Gets the symlink target for a given #GFileInfo. |
2003 | | * |
2004 | | * It is an error to call this if the #GFileInfo does not contain |
2005 | | * %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET. |
2006 | | * |
2007 | | * Returns: (nullable): a string containing the symlink target. |
2008 | | **/ |
2009 | | const char * |
2010 | | g_file_info_get_symlink_target (GFileInfo *info) |
2011 | 0 | { |
2012 | 0 | GFileAttributeValue *value; |
2013 | |
|
2014 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
2015 | | |
2016 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET, NULL); |
2017 | 0 | return _g_file_attribute_value_get_byte_string (value); |
2018 | 0 | } |
2019 | | |
2020 | | /** |
2021 | | * g_file_info_get_etag: |
2022 | | * @info: a #GFileInfo. |
2023 | | * |
2024 | | * Gets the [entity tag][gfile-etag] for a given |
2025 | | * #GFileInfo. See %G_FILE_ATTRIBUTE_ETAG_VALUE. |
2026 | | * |
2027 | | * It is an error to call this if the #GFileInfo does not contain |
2028 | | * %G_FILE_ATTRIBUTE_ETAG_VALUE. |
2029 | | * |
2030 | | * Returns: (nullable): a string containing the value of the "etag:value" attribute. |
2031 | | **/ |
2032 | | const char * |
2033 | | g_file_info_get_etag (GFileInfo *info) |
2034 | 0 | { |
2035 | 0 | GFileAttributeValue *value; |
2036 | |
|
2037 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), NULL); |
2038 | | |
2039 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_ETAG_VALUE, NULL); |
2040 | 0 | return _g_file_attribute_value_get_string (value); |
2041 | 0 | } |
2042 | | |
2043 | | /** |
2044 | | * g_file_info_get_sort_order: |
2045 | | * @info: a #GFileInfo. |
2046 | | * |
2047 | | * Gets the value of the sort_order attribute from the #GFileInfo. |
2048 | | * See %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER. |
2049 | | * |
2050 | | * It is an error to call this if the #GFileInfo does not contain |
2051 | | * %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER. |
2052 | | * |
2053 | | * Returns: a #gint32 containing the value of the "standard::sort_order" attribute. |
2054 | | **/ |
2055 | | gint32 |
2056 | | g_file_info_get_sort_order (GFileInfo *info) |
2057 | 0 | { |
2058 | 0 | GFileAttributeValue *value; |
2059 | |
|
2060 | 0 | g_return_val_if_fail (G_IS_FILE_INFO (info), 0); |
2061 | | |
2062 | 0 | get_required_attribute (&value, info, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER, 0); |
2063 | 0 | return _g_file_attribute_value_get_int32 (value); |
2064 | 0 | } |
2065 | | |
2066 | | /* Helper setters: */ |
2067 | | /** |
2068 | | * g_file_info_set_file_type: |
2069 | | * @info: a #GFileInfo. |
2070 | | * @type: a #GFileType. |
2071 | | * |
2072 | | * Sets the file type in a #GFileInfo to @type. |
2073 | | * See %G_FILE_ATTRIBUTE_STANDARD_TYPE. |
2074 | | **/ |
2075 | | void |
2076 | | g_file_info_set_file_type (GFileInfo *info, |
2077 | | GFileType type) |
2078 | 5.47k | { |
2079 | 5.47k | static guint32 attr = 0; |
2080 | 5.47k | GFileAttributeValue *value; |
2081 | | |
2082 | 5.47k | g_return_if_fail (G_IS_FILE_INFO (info)); |
2083 | | |
2084 | 5.47k | if (attr == 0) |
2085 | 1 | attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE); |
2086 | | |
2087 | 5.47k | value = g_file_info_create_value (info, attr); |
2088 | 5.47k | if (value) |
2089 | 5.47k | _g_file_attribute_value_set_uint32 (value, type); |
2090 | 5.47k | } |
2091 | | |
2092 | | /** |
2093 | | * g_file_info_set_is_hidden: |
2094 | | * @info: a #GFileInfo. |
2095 | | * @is_hidden: a #gboolean. |
2096 | | * |
2097 | | * Sets the "is_hidden" attribute in a #GFileInfo according to @is_hidden. |
2098 | | * See %G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN. |
2099 | | **/ |
2100 | | void |
2101 | | g_file_info_set_is_hidden (GFileInfo *info, |
2102 | | gboolean is_hidden) |
2103 | 0 | { |
2104 | 0 | static guint32 attr = 0; |
2105 | 0 | GFileAttributeValue *value; |
2106 | |
|
2107 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2108 | | |
2109 | 0 | if (attr == 0) |
2110 | 0 | attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN); |
2111 | |
|
2112 | 0 | value = g_file_info_create_value (info, attr); |
2113 | 0 | if (value) |
2114 | 0 | _g_file_attribute_value_set_boolean (value, is_hidden); |
2115 | 0 | } |
2116 | | |
2117 | | /** |
2118 | | * g_file_info_set_is_symlink: |
2119 | | * @info: a #GFileInfo. |
2120 | | * @is_symlink: a #gboolean. |
2121 | | * |
2122 | | * Sets the "is_symlink" attribute in a #GFileInfo according to @is_symlink. |
2123 | | * See %G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK. |
2124 | | **/ |
2125 | | void |
2126 | | g_file_info_set_is_symlink (GFileInfo *info, |
2127 | | gboolean is_symlink) |
2128 | 0 | { |
2129 | 0 | static guint32 attr = 0; |
2130 | 0 | GFileAttributeValue *value; |
2131 | |
|
2132 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2133 | | |
2134 | 0 | if (attr == 0) |
2135 | 0 | attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK); |
2136 | |
|
2137 | 0 | value = g_file_info_create_value (info, attr); |
2138 | 0 | if (value) |
2139 | 0 | _g_file_attribute_value_set_boolean (value, is_symlink); |
2140 | 0 | } |
2141 | | |
2142 | | /** |
2143 | | * g_file_info_set_name: |
2144 | | * @info: a #GFileInfo. |
2145 | | * @name: (type filename): a string containing a name. |
2146 | | * |
2147 | | * Sets the name attribute for the current #GFileInfo. |
2148 | | * See %G_FILE_ATTRIBUTE_STANDARD_NAME. |
2149 | | **/ |
2150 | | void |
2151 | | g_file_info_set_name (GFileInfo *info, |
2152 | | const char *name) |
2153 | 0 | { |
2154 | 0 | static guint32 attr = 0; |
2155 | 0 | GFileAttributeValue *value; |
2156 | |
|
2157 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2158 | 0 | g_return_if_fail (name != NULL); |
2159 | | |
2160 | 0 | if (attr == 0) |
2161 | 0 | attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME); |
2162 | |
|
2163 | 0 | value = g_file_info_create_value (info, attr); |
2164 | 0 | if (value) |
2165 | 0 | _g_file_attribute_value_set_byte_string (value, name); |
2166 | 0 | } |
2167 | | |
2168 | | /** |
2169 | | * g_file_info_set_display_name: |
2170 | | * @info: a #GFileInfo. |
2171 | | * @display_name: a string containing a display name. |
2172 | | * |
2173 | | * Sets the display name for the current #GFileInfo. |
2174 | | * See %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME. |
2175 | | **/ |
2176 | | void |
2177 | | g_file_info_set_display_name (GFileInfo *info, |
2178 | | const char *display_name) |
2179 | 0 | { |
2180 | 0 | static guint32 attr = 0; |
2181 | 0 | GFileAttributeValue *value; |
2182 | |
|
2183 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2184 | 0 | g_return_if_fail (display_name != NULL); |
2185 | | |
2186 | 0 | if (attr == 0) |
2187 | 0 | attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME); |
2188 | |
|
2189 | 0 | value = g_file_info_create_value (info, attr); |
2190 | 0 | if (value) |
2191 | 0 | _g_file_attribute_value_set_string (value, display_name); |
2192 | 0 | } |
2193 | | |
2194 | | /** |
2195 | | * g_file_info_set_edit_name: |
2196 | | * @info: a #GFileInfo. |
2197 | | * @edit_name: a string containing an edit name. |
2198 | | * |
2199 | | * Sets the edit name for the current file. |
2200 | | * See %G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME. |
2201 | | **/ |
2202 | | void |
2203 | | g_file_info_set_edit_name (GFileInfo *info, |
2204 | | const char *edit_name) |
2205 | 0 | { |
2206 | 0 | static guint32 attr = 0; |
2207 | 0 | GFileAttributeValue *value; |
2208 | |
|
2209 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2210 | 0 | g_return_if_fail (edit_name != NULL); |
2211 | | |
2212 | 0 | if (attr == 0) |
2213 | 0 | attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME); |
2214 | |
|
2215 | 0 | value = g_file_info_create_value (info, attr); |
2216 | 0 | if (value) |
2217 | 0 | _g_file_attribute_value_set_string (value, edit_name); |
2218 | 0 | } |
2219 | | |
2220 | | /** |
2221 | | * g_file_info_set_icon: |
2222 | | * @info: a #GFileInfo. |
2223 | | * @icon: a #GIcon. |
2224 | | * |
2225 | | * Sets the icon for a given #GFileInfo. |
2226 | | * See %G_FILE_ATTRIBUTE_STANDARD_ICON. |
2227 | | **/ |
2228 | | void |
2229 | | g_file_info_set_icon (GFileInfo *info, |
2230 | | GIcon *icon) |
2231 | 0 | { |
2232 | 0 | static guint32 attr = 0; |
2233 | 0 | GFileAttributeValue *value; |
2234 | |
|
2235 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2236 | 0 | g_return_if_fail (G_IS_ICON (icon)); |
2237 | | |
2238 | 0 | if (attr == 0) |
2239 | 0 | attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON); |
2240 | |
|
2241 | 0 | value = g_file_info_create_value (info, attr); |
2242 | 0 | if (value) |
2243 | 0 | _g_file_attribute_value_set_object (value, G_OBJECT (icon)); |
2244 | 0 | } |
2245 | | |
2246 | | /** |
2247 | | * g_file_info_set_symbolic_icon: |
2248 | | * @info: a #GFileInfo. |
2249 | | * @icon: a #GIcon. |
2250 | | * |
2251 | | * Sets the symbolic icon for a given #GFileInfo. |
2252 | | * See %G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON. |
2253 | | * |
2254 | | * Since: 2.34 |
2255 | | **/ |
2256 | | void |
2257 | | g_file_info_set_symbolic_icon (GFileInfo *info, |
2258 | | GIcon *icon) |
2259 | 0 | { |
2260 | 0 | static guint32 attr = 0; |
2261 | 0 | GFileAttributeValue *value; |
2262 | |
|
2263 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2264 | 0 | g_return_if_fail (G_IS_ICON (icon)); |
2265 | | |
2266 | 0 | if (attr == 0) |
2267 | 0 | attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON); |
2268 | |
|
2269 | 0 | value = g_file_info_create_value (info, attr); |
2270 | 0 | if (value) |
2271 | 0 | _g_file_attribute_value_set_object (value, G_OBJECT (icon)); |
2272 | 0 | } |
2273 | | |
2274 | | /** |
2275 | | * g_file_info_set_content_type: |
2276 | | * @info: a #GFileInfo. |
2277 | | * @content_type: a content type. See [GContentType][gio-GContentType] |
2278 | | * |
2279 | | * Sets the content type attribute for a given #GFileInfo. |
2280 | | * See %G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE. |
2281 | | **/ |
2282 | | void |
2283 | | g_file_info_set_content_type (GFileInfo *info, |
2284 | | const char *content_type) |
2285 | 0 | { |
2286 | 0 | static guint32 attr = 0; |
2287 | 0 | GFileAttributeValue *value; |
2288 | |
|
2289 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2290 | 0 | g_return_if_fail (content_type != NULL); |
2291 | | |
2292 | 0 | if (attr == 0) |
2293 | 0 | attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); |
2294 | |
|
2295 | 0 | value = g_file_info_create_value (info, attr); |
2296 | 0 | if (value) |
2297 | 0 | _g_file_attribute_value_set_string (value, content_type); |
2298 | 0 | } |
2299 | | |
2300 | | /** |
2301 | | * g_file_info_set_size: |
2302 | | * @info: a #GFileInfo. |
2303 | | * @size: a #goffset containing the file's size. |
2304 | | * |
2305 | | * Sets the %G_FILE_ATTRIBUTE_STANDARD_SIZE attribute in the file info |
2306 | | * to the given size. |
2307 | | **/ |
2308 | | void |
2309 | | g_file_info_set_size (GFileInfo *info, |
2310 | | goffset size) |
2311 | 5.47k | { |
2312 | 5.47k | static guint32 attr = 0; |
2313 | 5.47k | GFileAttributeValue *value; |
2314 | | |
2315 | 5.47k | g_return_if_fail (G_IS_FILE_INFO (info)); |
2316 | | |
2317 | 5.47k | if (attr == 0) |
2318 | 1 | attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE); |
2319 | | |
2320 | 5.47k | value = g_file_info_create_value (info, attr); |
2321 | 5.47k | if (value) |
2322 | 0 | _g_file_attribute_value_set_uint64 (value, size); |
2323 | 5.47k | } |
2324 | | |
2325 | | /** |
2326 | | * g_file_info_set_modification_time: |
2327 | | * @info: a #GFileInfo. |
2328 | | * @mtime: a #GTimeVal. |
2329 | | * |
2330 | | * Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED and |
2331 | | * %G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC attributes in the file info to the |
2332 | | * given time value. |
2333 | | * |
2334 | | * %G_FILE_ATTRIBUTE_TIME_MODIFIED_NSEC will be cleared. |
2335 | | * |
2336 | | * Deprecated: 2.62: Use g_file_info_set_modification_date_time() instead, as |
2337 | | * #GTimeVal is deprecated due to the year 2038 problem. |
2338 | | **/ |
2339 | | G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
2340 | | void |
2341 | | g_file_info_set_modification_time (GFileInfo *info, |
2342 | | GTimeVal *mtime) |
2343 | 0 | { |
2344 | 0 | static guint32 attr_mtime = 0, attr_mtime_usec = 0, attr_mtime_nsec = 0; |
2345 | 0 | GFileAttributeValue *value; |
2346 | |
|
2347 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2348 | 0 | g_return_if_fail (mtime != NULL); |
2349 | | |
2350 | 0 | if (attr_mtime == 0) |
2351 | 0 | { |
2352 | 0 | attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED); |
2353 | 0 | attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC); |
2354 | 0 | attr_mtime_nsec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_NSEC); |
2355 | 0 | } |
2356 | |
|
2357 | 0 | value = g_file_info_create_value (info, attr_mtime); |
2358 | 0 | if (value) |
2359 | 0 | _g_file_attribute_value_set_uint64 (value, mtime->tv_sec); |
2360 | 0 | value = g_file_info_create_value (info, attr_mtime_usec); |
2361 | 0 | if (value) |
2362 | 0 | _g_file_attribute_value_set_uint32 (value, mtime->tv_usec); |
2363 | | |
2364 | | /* nsecs can’t be known from a #GTimeVal, so remove them */ |
2365 | 0 | g_file_info_remove_value (info, attr_mtime_nsec); |
2366 | 0 | } |
2367 | | G_GNUC_END_IGNORE_DEPRECATIONS |
2368 | | |
2369 | | /** |
2370 | | * g_file_info_set_modification_date_time: |
2371 | | * @info: a #GFileInfo. |
2372 | | * @mtime: (not nullable): a #GDateTime. |
2373 | | * |
2374 | | * Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED and |
2375 | | * %G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC attributes in the file info to the |
2376 | | * given date/time value. |
2377 | | * |
2378 | | * %G_FILE_ATTRIBUTE_TIME_MODIFIED_NSEC will be cleared. |
2379 | | * |
2380 | | * Since: 2.62 |
2381 | | */ |
2382 | | void |
2383 | | g_file_info_set_modification_date_time (GFileInfo *info, |
2384 | | GDateTime *mtime) |
2385 | 0 | { |
2386 | 0 | static guint32 attr_mtime = 0, attr_mtime_usec = 0, attr_mtime_nsec = 0; |
2387 | 0 | GFileAttributeValue *value; |
2388 | |
|
2389 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2390 | 0 | g_return_if_fail (mtime != NULL); |
2391 | | |
2392 | 0 | if (attr_mtime == 0) |
2393 | 0 | { |
2394 | 0 | attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED); |
2395 | 0 | attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC); |
2396 | 0 | attr_mtime_nsec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_NSEC); |
2397 | 0 | } |
2398 | |
|
2399 | 0 | value = g_file_info_create_value (info, attr_mtime); |
2400 | 0 | if (value) |
2401 | 0 | _g_file_attribute_value_set_uint64 (value, g_date_time_to_unix (mtime)); |
2402 | 0 | value = g_file_info_create_value (info, attr_mtime_usec); |
2403 | 0 | if (value) |
2404 | 0 | _g_file_attribute_value_set_uint32 (value, g_date_time_get_microsecond (mtime)); |
2405 | | |
2406 | | /* nsecs can’t be known from a #GDateTime, so remove them */ |
2407 | 0 | g_file_info_remove_value (info, attr_mtime_nsec); |
2408 | 0 | } |
2409 | | |
2410 | | /** |
2411 | | * g_file_info_set_access_date_time: |
2412 | | * @info: a #GFileInfo. |
2413 | | * @atime: (not nullable): a #GDateTime. |
2414 | | * |
2415 | | * Sets the %G_FILE_ATTRIBUTE_TIME_ACCESS and |
2416 | | * %G_FILE_ATTRIBUTE_TIME_ACCESS_USEC attributes in the file info to the |
2417 | | * given date/time value. |
2418 | | * |
2419 | | * %G_FILE_ATTRIBUTE_TIME_ACCESS_NSEC will be cleared. |
2420 | | * |
2421 | | * Since: 2.70 |
2422 | | */ |
2423 | | void |
2424 | | g_file_info_set_access_date_time (GFileInfo *info, |
2425 | | GDateTime *atime) |
2426 | 0 | { |
2427 | 0 | static guint32 attr_atime = 0, attr_atime_usec = 0, attr_atime_nsec = 0; |
2428 | 0 | GFileAttributeValue *value; |
2429 | |
|
2430 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2431 | 0 | g_return_if_fail (atime != NULL); |
2432 | | |
2433 | 0 | if (attr_atime == 0) |
2434 | 0 | { |
2435 | 0 | attr_atime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_ACCESS); |
2436 | 0 | attr_atime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_ACCESS_USEC); |
2437 | 0 | attr_atime_nsec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_ACCESS_NSEC); |
2438 | 0 | } |
2439 | |
|
2440 | 0 | value = g_file_info_create_value (info, attr_atime); |
2441 | 0 | if (value) |
2442 | 0 | _g_file_attribute_value_set_uint64 (value, g_date_time_to_unix (atime)); |
2443 | 0 | value = g_file_info_create_value (info, attr_atime_usec); |
2444 | 0 | if (value) |
2445 | 0 | _g_file_attribute_value_set_uint32 (value, g_date_time_get_microsecond (atime)); |
2446 | | |
2447 | | /* nsecs can’t be known from a #GDateTime, so remove them */ |
2448 | 0 | g_file_info_remove_value (info, attr_atime_nsec); |
2449 | 0 | } |
2450 | | |
2451 | | /** |
2452 | | * g_file_info_set_creation_date_time: |
2453 | | * @info: a #GFileInfo. |
2454 | | * @creation_time: (not nullable): a #GDateTime. |
2455 | | * |
2456 | | * Sets the %G_FILE_ATTRIBUTE_TIME_CREATED and |
2457 | | * %G_FILE_ATTRIBUTE_TIME_CREATED_USEC attributes in the file info to the |
2458 | | * given date/time value. |
2459 | | * |
2460 | | * %G_FILE_ATTRIBUTE_TIME_CREATED_NSEC will be cleared. |
2461 | | * |
2462 | | * Since: 2.70 |
2463 | | */ |
2464 | | void |
2465 | | g_file_info_set_creation_date_time (GFileInfo *info, |
2466 | | GDateTime *creation_time) |
2467 | 0 | { |
2468 | 0 | static guint32 attr_ctime = 0, attr_ctime_usec = 0, attr_ctime_nsec = 0; |
2469 | 0 | GFileAttributeValue *value; |
2470 | |
|
2471 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2472 | 0 | g_return_if_fail (creation_time != NULL); |
2473 | | |
2474 | 0 | if (attr_ctime == 0) |
2475 | 0 | { |
2476 | 0 | attr_ctime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_CREATED); |
2477 | 0 | attr_ctime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_CREATED_USEC); |
2478 | 0 | attr_ctime_nsec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_CREATED_NSEC); |
2479 | 0 | } |
2480 | |
|
2481 | 0 | value = g_file_info_create_value (info, attr_ctime); |
2482 | 0 | if (value) |
2483 | 0 | _g_file_attribute_value_set_uint64 (value, g_date_time_to_unix (creation_time)); |
2484 | 0 | value = g_file_info_create_value (info, attr_ctime_usec); |
2485 | 0 | if (value) |
2486 | 0 | _g_file_attribute_value_set_uint32 (value, g_date_time_get_microsecond (creation_time)); |
2487 | | |
2488 | | /* nsecs can’t be known from a #GDateTime, so remove them */ |
2489 | 0 | g_file_info_remove_value (info, attr_ctime_nsec); |
2490 | 0 | } |
2491 | | |
2492 | | /** |
2493 | | * g_file_info_set_symlink_target: |
2494 | | * @info: a #GFileInfo. |
2495 | | * @symlink_target: a static string containing a path to a symlink target. |
2496 | | * |
2497 | | * Sets the %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET attribute in the file info |
2498 | | * to the given symlink target. |
2499 | | **/ |
2500 | | void |
2501 | | g_file_info_set_symlink_target (GFileInfo *info, |
2502 | | const char *symlink_target) |
2503 | 0 | { |
2504 | 0 | static guint32 attr = 0; |
2505 | 0 | GFileAttributeValue *value; |
2506 | |
|
2507 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2508 | 0 | g_return_if_fail (symlink_target != NULL); |
2509 | | |
2510 | 0 | if (attr == 0) |
2511 | 0 | attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET); |
2512 | |
|
2513 | 0 | value = g_file_info_create_value (info, attr); |
2514 | 0 | if (value) |
2515 | 0 | _g_file_attribute_value_set_byte_string (value, symlink_target); |
2516 | 0 | } |
2517 | | |
2518 | | /** |
2519 | | * g_file_info_set_sort_order: |
2520 | | * @info: a #GFileInfo. |
2521 | | * @sort_order: a sort order integer. |
2522 | | * |
2523 | | * Sets the sort order attribute in the file info structure. See |
2524 | | * %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER. |
2525 | | **/ |
2526 | | void |
2527 | | g_file_info_set_sort_order (GFileInfo *info, |
2528 | | gint32 sort_order) |
2529 | 0 | { |
2530 | 0 | static guint32 attr = 0; |
2531 | 0 | GFileAttributeValue *value; |
2532 | |
|
2533 | 0 | g_return_if_fail (G_IS_FILE_INFO (info)); |
2534 | | |
2535 | 0 | if (attr == 0) |
2536 | 0 | attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER); |
2537 | |
|
2538 | 0 | value = g_file_info_create_value (info, attr); |
2539 | 0 | if (value) |
2540 | 0 | _g_file_attribute_value_set_int32 (value, sort_order); |
2541 | 0 | } |
2542 | | |
2543 | | |
2544 | | typedef struct { |
2545 | | guint32 id; |
2546 | | guint32 mask; |
2547 | | } SubMatcher; |
2548 | | |
2549 | | struct _GFileAttributeMatcher { |
2550 | | gboolean all; |
2551 | | gint ref; |
2552 | | |
2553 | | GArray *sub_matchers; |
2554 | | |
2555 | | /* Iterator */ |
2556 | | guint32 iterator_ns; |
2557 | | gint iterator_pos; |
2558 | | }; |
2559 | | |
2560 | 0 | G_DEFINE_BOXED_TYPE (GFileAttributeMatcher, g_file_attribute_matcher, |
2561 | 0 | g_file_attribute_matcher_ref, |
2562 | 0 | g_file_attribute_matcher_unref) |
2563 | 0 |
|
2564 | 0 | static gint |
2565 | 0 | compare_sub_matchers (gconstpointer a, |
2566 | 0 | gconstpointer b) |
2567 | 0 | { |
2568 | 0 | const SubMatcher *suba = a; |
2569 | 0 | const SubMatcher *subb = b; |
2570 | 0 | int diff; |
2571 | |
|
2572 | 0 | diff = suba->id - subb->id; |
2573 | |
|
2574 | 0 | if (diff) |
2575 | 0 | return diff; |
2576 | | |
2577 | 0 | return suba->mask - subb->mask; |
2578 | 0 | } |
2579 | | |
2580 | | static gboolean |
2581 | | sub_matcher_matches (SubMatcher *matcher, |
2582 | | SubMatcher *submatcher) |
2583 | 0 | { |
2584 | 0 | if ((matcher->mask & submatcher->mask) != matcher->mask) |
2585 | 0 | return FALSE; |
2586 | | |
2587 | 0 | return matcher->id == (submatcher->id & matcher->mask); |
2588 | 0 | } |
2589 | | |
2590 | | /* Call this function after modifying a matcher. |
2591 | | * It will ensure all the invariants other functions rely on. |
2592 | | */ |
2593 | | static GFileAttributeMatcher * |
2594 | | matcher_optimize (GFileAttributeMatcher *matcher) |
2595 | 5.47k | { |
2596 | 5.47k | SubMatcher *submatcher, *compare; |
2597 | 5.47k | guint i, j; |
2598 | | |
2599 | | /* remove sub_matchers if we match everything anyway */ |
2600 | 5.47k | if (matcher->all) |
2601 | 0 | { |
2602 | 0 | if (matcher->sub_matchers) |
2603 | 0 | { |
2604 | 0 | g_array_free (matcher->sub_matchers, TRUE); |
2605 | 0 | matcher->sub_matchers = NULL; |
2606 | 0 | } |
2607 | 0 | return matcher; |
2608 | 0 | } |
2609 | | |
2610 | 5.47k | if (matcher->sub_matchers->len == 0) |
2611 | 0 | { |
2612 | 0 | g_file_attribute_matcher_unref (matcher); |
2613 | 0 | return NULL; |
2614 | 0 | } |
2615 | | |
2616 | | /* sort sub_matchers by id (and then mask), so we can bsearch |
2617 | | * and compare matchers in O(N) instead of O(N²) */ |
2618 | 5.47k | g_array_sort (matcher->sub_matchers, compare_sub_matchers); |
2619 | | |
2620 | | /* remove duplicates and specific matches when we match the whole namespace */ |
2621 | 5.47k | j = 0; |
2622 | 5.47k | compare = &g_array_index (matcher->sub_matchers, SubMatcher, j); |
2623 | | |
2624 | 5.47k | for (i = 1; i < matcher->sub_matchers->len; i++) |
2625 | 0 | { |
2626 | 0 | submatcher = &g_array_index (matcher->sub_matchers, SubMatcher, i); |
2627 | 0 | if (sub_matcher_matches (compare, submatcher)) |
2628 | 0 | continue; |
2629 | | |
2630 | 0 | j++; |
2631 | 0 | compare++; |
2632 | |
|
2633 | 0 | if (j < i) |
2634 | 0 | *compare = *submatcher; |
2635 | 0 | } |
2636 | | |
2637 | 5.47k | g_array_set_size (matcher->sub_matchers, j + 1); |
2638 | | |
2639 | 5.47k | return matcher; |
2640 | 5.47k | } |
2641 | | |
2642 | | /** |
2643 | | * g_file_attribute_matcher_new: |
2644 | | * @attributes: an attribute string to match. |
2645 | | * |
2646 | | * Creates a new file attribute matcher, which matches attributes |
2647 | | * against a given string. #GFileAttributeMatchers are reference |
2648 | | * counted structures, and are created with a reference count of 1. If |
2649 | | * the number of references falls to 0, the #GFileAttributeMatcher is |
2650 | | * automatically destroyed. |
2651 | | * |
2652 | | * The @attributes string should be formatted with specific keys separated |
2653 | | * from namespaces with a double colon. Several "namespace::key" strings may be |
2654 | | * concatenated with a single comma (e.g. "standard::type,standard::is-hidden"). |
2655 | | * The wildcard "*" may be used to match all keys and namespaces, or |
2656 | | * "namespace::*" will match all keys in a given namespace. |
2657 | | * |
2658 | | * ## Examples of file attribute matcher strings and results |
2659 | | * |
2660 | | * - `"*"`: matches all attributes. |
2661 | | * - `"standard::is-hidden"`: matches only the key is-hidden in the |
2662 | | * standard namespace. |
2663 | | * - `"standard::type,unix::*"`: matches the type key in the standard |
2664 | | * namespace and all keys in the unix namespace. |
2665 | | * |
2666 | | * Returns: a #GFileAttributeMatcher |
2667 | | */ |
2668 | | GFileAttributeMatcher * |
2669 | | g_file_attribute_matcher_new (const char *attributes) |
2670 | 5.47k | { |
2671 | 5.47k | char **split; |
2672 | 5.47k | char *colon; |
2673 | 5.47k | int i; |
2674 | 5.47k | GFileAttributeMatcher *matcher; |
2675 | | |
2676 | 5.47k | if (attributes == NULL || *attributes == '\0') |
2677 | 0 | return NULL; |
2678 | | |
2679 | 5.47k | matcher = g_malloc0 (sizeof (GFileAttributeMatcher)); |
2680 | 5.47k | matcher->ref = 1; |
2681 | 5.47k | matcher->sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher)); |
2682 | | |
2683 | 5.47k | split = g_strsplit (attributes, ",", -1); |
2684 | | |
2685 | 10.9k | for (i = 0; split[i] != NULL; i++) |
2686 | 5.47k | { |
2687 | 5.47k | if (strcmp (split[i], "*") == 0) |
2688 | 0 | matcher->all = TRUE; |
2689 | 5.47k | else |
2690 | 5.47k | { |
2691 | 5.47k | SubMatcher s; |
2692 | | |
2693 | 5.47k | colon = strstr (split[i], "::"); |
2694 | 5.47k | if (colon != NULL && |
2695 | 5.47k | !(colon[2] == 0 || |
2696 | 5.47k | (colon[2] == '*' && |
2697 | 0 | colon[3] == 0))) |
2698 | 5.47k | { |
2699 | 5.47k | s.id = lookup_attribute (split[i]); |
2700 | 5.47k | s.mask = 0xffffffff; |
2701 | 5.47k | } |
2702 | 0 | else |
2703 | 0 | { |
2704 | 0 | if (colon) |
2705 | 0 | *colon = 0; |
2706 | |
|
2707 | 0 | s.id = lookup_namespace (split[i]) << NS_POS; |
2708 | 0 | s.mask = NS_MASK << NS_POS; |
2709 | 0 | } |
2710 | | |
2711 | 5.47k | g_array_append_val (matcher->sub_matchers, s); |
2712 | 5.47k | } |
2713 | 5.47k | } |
2714 | | |
2715 | 5.47k | g_strfreev (split); |
2716 | | |
2717 | 5.47k | matcher = matcher_optimize (matcher); |
2718 | | |
2719 | 5.47k | return matcher; |
2720 | 5.47k | } |
2721 | | |
2722 | | /** |
2723 | | * g_file_attribute_matcher_subtract: |
2724 | | * @matcher: (nullable): Matcher to subtract from |
2725 | | * @subtract: (nullable): The matcher to subtract |
2726 | | * |
2727 | | * Subtracts all attributes of @subtract from @matcher and returns |
2728 | | * a matcher that supports those attributes. |
2729 | | * |
2730 | | * Note that currently it is not possible to remove a single |
2731 | | * attribute when the @matcher matches the whole namespace - or remove |
2732 | | * a namespace or attribute when the matcher matches everything. This |
2733 | | * is a limitation of the current implementation, but may be fixed |
2734 | | * in the future. |
2735 | | * |
2736 | | * Returns: (nullable): A file attribute matcher matching all attributes of |
2737 | | * @matcher that are not matched by @subtract |
2738 | | **/ |
2739 | | GFileAttributeMatcher * |
2740 | | g_file_attribute_matcher_subtract (GFileAttributeMatcher *matcher, |
2741 | | GFileAttributeMatcher *subtract) |
2742 | 0 | { |
2743 | 0 | GFileAttributeMatcher *result; |
2744 | 0 | guint mi, si; |
2745 | 0 | SubMatcher *msub, *ssub; |
2746 | |
|
2747 | 0 | if (matcher == NULL) |
2748 | 0 | return NULL; |
2749 | 0 | if (subtract == NULL) |
2750 | 0 | return g_file_attribute_matcher_ref (matcher); |
2751 | 0 | if (subtract->all) |
2752 | 0 | return NULL; |
2753 | 0 | if (matcher->all) |
2754 | 0 | return g_file_attribute_matcher_ref (matcher); |
2755 | | |
2756 | 0 | result = g_malloc0 (sizeof (GFileAttributeMatcher)); |
2757 | 0 | result->ref = 1; |
2758 | 0 | result->sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher)); |
2759 | |
|
2760 | 0 | si = 0; |
2761 | 0 | g_assert (subtract->sub_matchers->len > 0); |
2762 | 0 | ssub = &g_array_index (subtract->sub_matchers, SubMatcher, si); |
2763 | |
|
2764 | 0 | for (mi = 0; mi < matcher->sub_matchers->len; mi++) |
2765 | 0 | { |
2766 | 0 | msub = &g_array_index (matcher->sub_matchers, SubMatcher, mi); |
2767 | |
|
2768 | 0 | retry: |
2769 | 0 | if (sub_matcher_matches (ssub, msub)) |
2770 | 0 | continue; |
2771 | | |
2772 | 0 | si++; |
2773 | 0 | if (si >= subtract->sub_matchers->len) |
2774 | 0 | break; |
2775 | | |
2776 | 0 | ssub = &g_array_index (subtract->sub_matchers, SubMatcher, si); |
2777 | 0 | if (ssub->id <= msub->id) |
2778 | 0 | goto retry; |
2779 | | |
2780 | 0 | g_array_append_val (result->sub_matchers, *msub); |
2781 | 0 | } |
2782 | | |
2783 | 0 | if (mi < matcher->sub_matchers->len) |
2784 | 0 | g_array_append_vals (result->sub_matchers, |
2785 | 0 | &g_array_index (matcher->sub_matchers, SubMatcher, mi), |
2786 | 0 | matcher->sub_matchers->len - mi); |
2787 | |
|
2788 | 0 | result = matcher_optimize (result); |
2789 | |
|
2790 | 0 | return result; |
2791 | 0 | } |
2792 | | |
2793 | | /** |
2794 | | * g_file_attribute_matcher_ref: |
2795 | | * @matcher: a #GFileAttributeMatcher. |
2796 | | * |
2797 | | * References a file attribute matcher. |
2798 | | * |
2799 | | * Returns: a #GFileAttributeMatcher. |
2800 | | **/ |
2801 | | GFileAttributeMatcher * |
2802 | | g_file_attribute_matcher_ref (GFileAttributeMatcher *matcher) |
2803 | 5.47k | { |
2804 | 5.47k | if (matcher) |
2805 | 5.47k | { |
2806 | 5.47k | g_return_val_if_fail (matcher->ref > 0, NULL); |
2807 | 5.47k | g_atomic_int_inc (&matcher->ref); |
2808 | 5.47k | } |
2809 | 5.47k | return matcher; |
2810 | 5.47k | } |
2811 | | |
2812 | | /** |
2813 | | * g_file_attribute_matcher_unref: |
2814 | | * @matcher: a #GFileAttributeMatcher. |
2815 | | * |
2816 | | * Unreferences @matcher. If the reference count falls below 1, |
2817 | | * the @matcher is automatically freed. |
2818 | | * |
2819 | | **/ |
2820 | | void |
2821 | | g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher) |
2822 | 10.9k | { |
2823 | 10.9k | if (matcher) |
2824 | 10.9k | { |
2825 | 10.9k | g_return_if_fail (matcher->ref > 0); |
2826 | | |
2827 | 10.9k | if (g_atomic_int_dec_and_test (&matcher->ref)) |
2828 | 5.47k | { |
2829 | 5.47k | if (matcher->sub_matchers) |
2830 | 5.47k | g_array_free (matcher->sub_matchers, TRUE); |
2831 | | |
2832 | 5.47k | g_free (matcher); |
2833 | 5.47k | } |
2834 | 10.9k | } |
2835 | 10.9k | } |
2836 | | |
2837 | | /** |
2838 | | * g_file_attribute_matcher_matches_only: |
2839 | | * @matcher: a #GFileAttributeMatcher. |
2840 | | * @attribute: a file attribute key. |
2841 | | * |
2842 | | * Checks if an attribute matcher only matches a given attribute. Always |
2843 | | * returns %FALSE if "*" was used when creating the matcher. |
2844 | | * |
2845 | | * Returns: %TRUE if the matcher only matches @attribute. %FALSE otherwise. |
2846 | | **/ |
2847 | | gboolean |
2848 | | g_file_attribute_matcher_matches_only (GFileAttributeMatcher *matcher, |
2849 | | const char *attribute) |
2850 | 0 | { |
2851 | 0 | SubMatcher *sub_matcher; |
2852 | 0 | guint32 id; |
2853 | |
|
2854 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE); |
2855 | | |
2856 | 0 | if (matcher == NULL || |
2857 | 0 | matcher->all) |
2858 | 0 | return FALSE; |
2859 | | |
2860 | 0 | if (matcher->sub_matchers->len != 1) |
2861 | 0 | return FALSE; |
2862 | | |
2863 | 0 | id = lookup_attribute (attribute); |
2864 | | |
2865 | 0 | sub_matcher = &g_array_index (matcher->sub_matchers, SubMatcher, 0); |
2866 | | |
2867 | 0 | return sub_matcher->id == id && |
2868 | 0 | sub_matcher->mask == 0xffffffff; |
2869 | 0 | } |
2870 | | |
2871 | | static gboolean |
2872 | | matcher_matches_id (GFileAttributeMatcher *matcher, |
2873 | | guint32 id) |
2874 | 147k | { |
2875 | 147k | SubMatcher *sub_matchers; |
2876 | 147k | guint i; |
2877 | | |
2878 | 147k | if (matcher->sub_matchers) |
2879 | 147k | { |
2880 | 147k | sub_matchers = (SubMatcher *)matcher->sub_matchers->data; |
2881 | 290k | for (i = 0; i < matcher->sub_matchers->len; i++) |
2882 | 147k | { |
2883 | 147k | if (sub_matchers[i].id == (id & sub_matchers[i].mask)) |
2884 | 5.47k | return TRUE; |
2885 | 147k | } |
2886 | 147k | } |
2887 | | |
2888 | 142k | return FALSE; |
2889 | 147k | } |
2890 | | |
2891 | | gboolean |
2892 | | _g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher, |
2893 | | guint32 id) |
2894 | 147k | { |
2895 | | /* We return a NULL matcher for an empty match string, so handle this */ |
2896 | 147k | if (matcher == NULL) |
2897 | 0 | return FALSE; |
2898 | | |
2899 | 147k | if (matcher->all) |
2900 | 0 | return TRUE; |
2901 | | |
2902 | 147k | return matcher_matches_id (matcher, id); |
2903 | 147k | } |
2904 | | |
2905 | | /** |
2906 | | * g_file_attribute_matcher_matches: |
2907 | | * @matcher: a #GFileAttributeMatcher. |
2908 | | * @attribute: a file attribute key. |
2909 | | * |
2910 | | * Checks if an attribute will be matched by an attribute matcher. If |
2911 | | * the matcher was created with the "*" matching string, this function |
2912 | | * will always return %TRUE. |
2913 | | * |
2914 | | * Returns: %TRUE if @attribute matches @matcher. %FALSE otherwise. |
2915 | | **/ |
2916 | | gboolean |
2917 | | g_file_attribute_matcher_matches (GFileAttributeMatcher *matcher, |
2918 | | const char *attribute) |
2919 | 0 | { |
2920 | 0 | g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE); |
2921 | | |
2922 | | /* We return a NULL matcher for an empty match string, so handle this */ |
2923 | 0 | if (matcher == NULL) |
2924 | 0 | return FALSE; |
2925 | | |
2926 | 0 | if (matcher->all) |
2927 | 0 | return TRUE; |
2928 | | |
2929 | 0 | return matcher_matches_id (matcher, lookup_attribute (attribute)); |
2930 | 0 | } |
2931 | | |
2932 | | /* return TRUE -> all */ |
2933 | | /** |
2934 | | * g_file_attribute_matcher_enumerate_namespace: |
2935 | | * @matcher: a #GFileAttributeMatcher. |
2936 | | * @ns: a string containing a file attribute namespace. |
2937 | | * |
2938 | | * Checks if the matcher will match all of the keys in a given namespace. |
2939 | | * This will always return %TRUE if a wildcard character is in use (e.g. if |
2940 | | * matcher was created with "standard::*" and @ns is "standard", or if matcher was created |
2941 | | * using "*" and namespace is anything.) |
2942 | | * |
2943 | | * TODO: this is awkwardly worded. |
2944 | | * |
2945 | | * Returns: %TRUE if the matcher matches all of the entries |
2946 | | * in the given @ns, %FALSE otherwise. |
2947 | | **/ |
2948 | | gboolean |
2949 | | g_file_attribute_matcher_enumerate_namespace (GFileAttributeMatcher *matcher, |
2950 | | const char *ns) |
2951 | 10.9k | { |
2952 | 10.9k | SubMatcher *sub_matchers; |
2953 | 10.9k | guint ns_id; |
2954 | 10.9k | guint i; |
2955 | | |
2956 | 10.9k | g_return_val_if_fail (ns != NULL && *ns != '\0', FALSE); |
2957 | | |
2958 | | /* We return a NULL matcher for an empty match string, so handle this */ |
2959 | 10.9k | if (matcher == NULL) |
2960 | 0 | return FALSE; |
2961 | | |
2962 | 10.9k | if (matcher->all) |
2963 | 0 | return TRUE; |
2964 | | |
2965 | 10.9k | ns_id = lookup_namespace (ns) << NS_POS; |
2966 | | |
2967 | 10.9k | if (matcher->sub_matchers) |
2968 | 10.9k | { |
2969 | 10.9k | sub_matchers = (SubMatcher *)matcher->sub_matchers->data; |
2970 | 21.9k | for (i = 0; i < matcher->sub_matchers->len; i++) |
2971 | 10.9k | { |
2972 | 10.9k | if (sub_matchers[i].id == ns_id) |
2973 | 0 | return TRUE; |
2974 | 10.9k | } |
2975 | 10.9k | } |
2976 | | |
2977 | 10.9k | matcher->iterator_ns = ns_id; |
2978 | 10.9k | matcher->iterator_pos = 0; |
2979 | | |
2980 | 10.9k | return FALSE; |
2981 | 10.9k | } |
2982 | | |
2983 | | /** |
2984 | | * g_file_attribute_matcher_enumerate_next: |
2985 | | * @matcher: a #GFileAttributeMatcher. |
2986 | | * |
2987 | | * Gets the next matched attribute from a #GFileAttributeMatcher. |
2988 | | * |
2989 | | * Returns: (nullable): a string containing the next attribute or, %NULL if |
2990 | | * no more attribute exist. |
2991 | | **/ |
2992 | | const char * |
2993 | | g_file_attribute_matcher_enumerate_next (GFileAttributeMatcher *matcher) |
2994 | 10.9k | { |
2995 | 10.9k | guint i; |
2996 | 10.9k | SubMatcher *sub_matcher; |
2997 | | |
2998 | | /* We return a NULL matcher for an empty match string, so handle this */ |
2999 | 10.9k | if (matcher == NULL) |
3000 | 0 | return NULL; |
3001 | | |
3002 | 21.9k | while (1) |
3003 | 21.9k | { |
3004 | 21.9k | i = matcher->iterator_pos++; |
3005 | | |
3006 | 21.9k | if (matcher->sub_matchers == NULL) |
3007 | 0 | return NULL; |
3008 | | |
3009 | 21.9k | if (i < matcher->sub_matchers->len) |
3010 | 10.9k | sub_matcher = &g_array_index (matcher->sub_matchers, SubMatcher, i); |
3011 | 10.9k | else |
3012 | 10.9k | return NULL; |
3013 | | |
3014 | 10.9k | if (sub_matcher->mask == 0xffffffff && |
3015 | 10.9k | (sub_matcher->id & (NS_MASK << NS_POS)) == matcher->iterator_ns) |
3016 | 0 | return get_attribute_for_id (sub_matcher->id); |
3017 | 10.9k | } |
3018 | 10.9k | } |
3019 | | |
3020 | | /** |
3021 | | * g_file_attribute_matcher_to_string: |
3022 | | * @matcher: (nullable): a #GFileAttributeMatcher. |
3023 | | * |
3024 | | * Prints what the matcher is matching against. The format will be |
3025 | | * equal to the format passed to g_file_attribute_matcher_new(). |
3026 | | * The output however, might not be identical, as the matcher may |
3027 | | * decide to use a different order or omit needless parts. |
3028 | | * |
3029 | | * Returns: a string describing the attributes the matcher matches |
3030 | | * against or %NULL if @matcher was %NULL. |
3031 | | * |
3032 | | * Since: 2.32 |
3033 | | **/ |
3034 | | char * |
3035 | | g_file_attribute_matcher_to_string (GFileAttributeMatcher *matcher) |
3036 | 0 | { |
3037 | 0 | GString *string; |
3038 | 0 | guint i; |
3039 | |
|
3040 | 0 | if (matcher == NULL) |
3041 | 0 | return NULL; |
3042 | | |
3043 | 0 | if (matcher->all) |
3044 | 0 | return g_strdup ("*"); |
3045 | | |
3046 | 0 | string = g_string_new (""); |
3047 | 0 | for (i = 0; i < matcher->sub_matchers->len; i++) |
3048 | 0 | { |
3049 | 0 | SubMatcher *submatcher = &g_array_index (matcher->sub_matchers, SubMatcher, i); |
3050 | |
|
3051 | 0 | if (i > 0) |
3052 | 0 | g_string_append_c (string, ','); |
3053 | |
|
3054 | 0 | g_string_append (string, get_attribute_for_id (submatcher->id)); |
3055 | 0 | } |
3056 | |
|
3057 | 0 | return g_string_free (string, FALSE); |
3058 | 0 | } |