1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2006-2007 Red Hat, Inc.
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 of the License, or (at your option) any later version.
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.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
22 * Author: Alexander Larsson <alexl@redhat.com>
34 #include <sys/types.h>
40 #include "gioscheduler.h"
41 #include "gsimpleasyncresult.h"
42 #include "gfileattribute-priv.h"
43 #include "gfiledescriptorbased.h"
44 #include "gpollfilemonitor.h"
46 #include "gfileinputstream.h"
47 #include "gfileoutputstream.h"
48 #include "gcancellable.h"
49 #include "gasyncresult.h"
57 * @short_description: File and Directory Handling
59 * @see_also: #GFileInfo, #GFileEnumerator
61 * #GFile is a high level abstraction for manipulating files on a
62 * virtual file system. #GFile<!-- -->s are lightweight, immutable
63 * objects that do no I/O upon creation. It is necessary to understand that
64 * #GFile objects do not represent files, merely an identifier for a file. All
65 * file content I/O is implemented as streaming operations (see #GInputStream and
68 * To construct a #GFile, you can use:
69 * g_file_new_for_path() if you have a path.
70 * g_file_new_for_uri() if you have a URI.
71 * g_file_new_for_commandline_arg() for a command line argument.
72 * g_file_parse_name() from a utf8 string gotten from g_file_get_parse_name().
74 * One way to think of a #GFile is as an abstraction of a pathname. For normal
75 * files the system pathname is what is stored internally, but as #GFile<!-- -->s
76 * are extensible it could also be something else that corresponds to a pathname
77 * in a userspace implementation of a filesystem.
79 * #GFile<!-- -->s make up hierarchies of directories and files that correspond to the
80 * files on a filesystem. You can move through the file system with #GFile using
81 * g_file_get_parent() to get an identifier for the parent directory, g_file_get_child()
82 * to get a child within a directory, g_file_resolve_relative_path() to resolve a relative
83 * path between two #GFile<!-- -->s. There can be multiple hierarchies, so you may not
84 * end up at the same root if you repeatedly call g_file_get_parent() on two different
87 * All #GFile<!-- -->s have a basename (get with g_file_get_basename()). These names
88 * are byte strings that are used to identify the file on the filesystem (relative to
89 * its parent directory) and there is no guarantees that they have any particular charset
90 * encoding or even make any sense at all. If you want to use filenames in a user
91 * interface you should use the display name that you can get by requesting the
92 * %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info().
93 * This is guaranteed to be in utf8 and can be used in a user interface. But always
94 * store the real basename or the #GFile to use to actually access the file, because
95 * there is no way to go from a display name to the actual name.
97 * Using #GFile as an identifier has the same weaknesses as using a path in that
98 * there may be multiple aliases for the same file. For instance, hard or
99 * soft links may cause two different #GFile<!-- -->s to refer to the same file.
100 * Other possible causes for aliases are: case insensitive filesystems, short
101 * and long names on Fat/NTFS, or bind mounts in Linux. If you want to check if
102 * two #GFile<!-- -->s point to the same file you can query for the
103 * %G_FILE_ATTRIBUTE_ID_FILE attribute. Note that #GFile does some trivial
104 * canonicalization of pathnames passed in, so that trivial differences in the
105 * path string used at creation (duplicated slashes, slash at end of path, "."
106 * or ".." path segments, etc) does not create different #GFile<!-- -->s.
108 * Many #GFile operations have both synchronous and asynchronous versions
109 * to suit your application. Asynchronous versions of synchronous functions
110 * simply have _async() appended to their function names. The asynchronous
111 * I/O functions call a #GAsyncReadyCallback which is then used to finalize
112 * the operation, producing a GAsyncResult which is then passed to the
113 * function's matching _finish() operation.
115 * Some #GFile operations do not have synchronous analogs, as they may
116 * take a very long time to finish, and blocking may leave an application
117 * unusable. Notable cases include:
118 * g_file_mount_mountable() to mount a mountable file.
119 * g_file_unmount_mountable_with_operation() to unmount a mountable file.
120 * g_file_eject_mountable_with_operation() to eject a mountable file.
122 * <para id="gfile-etag"><indexterm><primary>entity tag</primary></indexterm>
123 * One notable feature of #GFile<!-- -->s are entity tags, or "etags" for
124 * short. Entity tags are somewhat like a more abstract version of the
125 * traditional mtime, and can be used to quickly determine if the file has
126 * been modified from the version on the file system. See the HTTP 1.1
127 * <ulink url="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">specification</ulink>
128 * for HTTP Etag headers, which are a very similar concept.
132 static void g_file_real_query_info_async (GFile *file,
133 const char *attributes,
134 GFileQueryInfoFlags flags,
136 GCancellable *cancellable,
137 GAsyncReadyCallback callback,
139 static GFileInfo * g_file_real_query_info_finish (GFile *file,
142 static void g_file_real_query_filesystem_info_async (GFile *file,
143 const char *attributes,
145 GCancellable *cancellable,
146 GAsyncReadyCallback callback,
148 static GFileInfo * g_file_real_query_filesystem_info_finish (GFile *file,
151 static void g_file_real_enumerate_children_async (GFile *file,
152 const char *attributes,
153 GFileQueryInfoFlags flags,
155 GCancellable *cancellable,
156 GAsyncReadyCallback callback,
158 static GFileEnumerator * g_file_real_enumerate_children_finish (GFile *file,
161 static void g_file_real_read_async (GFile *file,
163 GCancellable *cancellable,
164 GAsyncReadyCallback callback,
166 static GFileInputStream * g_file_real_read_finish (GFile *file,
169 static void g_file_real_append_to_async (GFile *file,
170 GFileCreateFlags flags,
172 GCancellable *cancellable,
173 GAsyncReadyCallback callback,
175 static GFileOutputStream *g_file_real_append_to_finish (GFile *file,
178 static void g_file_real_create_async (GFile *file,
179 GFileCreateFlags flags,
181 GCancellable *cancellable,
182 GAsyncReadyCallback callback,
184 static GFileOutputStream *g_file_real_create_finish (GFile *file,
187 static void g_file_real_replace_async (GFile *file,
189 gboolean make_backup,
190 GFileCreateFlags flags,
192 GCancellable *cancellable,
193 GAsyncReadyCallback callback,
195 static GFileOutputStream *g_file_real_replace_finish (GFile *file,
198 static void g_file_real_open_readwrite_async (GFile *file,
200 GCancellable *cancellable,
201 GAsyncReadyCallback callback,
203 static GFileIOStream * g_file_real_open_readwrite_finish (GFile *file,
206 static void g_file_real_create_readwrite_async (GFile *file,
207 GFileCreateFlags flags,
209 GCancellable *cancellable,
210 GAsyncReadyCallback callback,
212 static GFileIOStream * g_file_real_create_readwrite_finish (GFile *file,
215 static void g_file_real_replace_readwrite_async (GFile *file,
217 gboolean make_backup,
218 GFileCreateFlags flags,
220 GCancellable *cancellable,
221 GAsyncReadyCallback callback,
223 static GFileIOStream * g_file_real_replace_readwrite_finish (GFile *file,
226 static gboolean g_file_real_set_attributes_from_info (GFile *file,
228 GFileQueryInfoFlags flags,
229 GCancellable *cancellable,
231 static void g_file_real_set_display_name_async (GFile *file,
232 const char *display_name,
234 GCancellable *cancellable,
235 GAsyncReadyCallback callback,
237 static GFile * g_file_real_set_display_name_finish (GFile *file,
240 static void g_file_real_set_attributes_async (GFile *file,
242 GFileQueryInfoFlags flags,
244 GCancellable *cancellable,
245 GAsyncReadyCallback callback,
247 static gboolean g_file_real_set_attributes_finish (GFile *file,
251 static void g_file_real_find_enclosing_mount_async (GFile *file,
253 GCancellable *cancellable,
254 GAsyncReadyCallback callback,
256 static GMount * g_file_real_find_enclosing_mount_finish (GFile *file,
259 static void g_file_real_copy_async (GFile *source,
261 GFileCopyFlags flags,
263 GCancellable *cancellable,
264 GFileProgressCallback progress_callback,
265 gpointer progress_callback_data,
266 GAsyncReadyCallback callback,
268 static gboolean g_file_real_copy_finish (GFile *file,
272 typedef GFileIface GFileInterface;
273 G_DEFINE_INTERFACE (GFile, g_file, G_TYPE_OBJECT)
276 g_file_default_init (GFileIface *iface)
278 iface->enumerate_children_async = g_file_real_enumerate_children_async;
279 iface->enumerate_children_finish = g_file_real_enumerate_children_finish;
280 iface->set_display_name_async = g_file_real_set_display_name_async;
281 iface->set_display_name_finish = g_file_real_set_display_name_finish;
282 iface->query_info_async = g_file_real_query_info_async;
283 iface->query_info_finish = g_file_real_query_info_finish;
284 iface->query_filesystem_info_async = g_file_real_query_filesystem_info_async;
285 iface->query_filesystem_info_finish = g_file_real_query_filesystem_info_finish;
286 iface->set_attributes_async = g_file_real_set_attributes_async;
287 iface->set_attributes_finish = g_file_real_set_attributes_finish;
288 iface->read_async = g_file_real_read_async;
289 iface->read_finish = g_file_real_read_finish;
290 iface->append_to_async = g_file_real_append_to_async;
291 iface->append_to_finish = g_file_real_append_to_finish;
292 iface->create_async = g_file_real_create_async;
293 iface->create_finish = g_file_real_create_finish;
294 iface->replace_async = g_file_real_replace_async;
295 iface->replace_finish = g_file_real_replace_finish;
296 iface->open_readwrite_async = g_file_real_open_readwrite_async;
297 iface->open_readwrite_finish = g_file_real_open_readwrite_finish;
298 iface->create_readwrite_async = g_file_real_create_readwrite_async;
299 iface->create_readwrite_finish = g_file_real_create_readwrite_finish;
300 iface->replace_readwrite_async = g_file_real_replace_readwrite_async;
301 iface->replace_readwrite_finish = g_file_real_replace_readwrite_finish;
302 iface->find_enclosing_mount_async = g_file_real_find_enclosing_mount_async;
303 iface->find_enclosing_mount_finish = g_file_real_find_enclosing_mount_finish;
304 iface->set_attributes_from_info = g_file_real_set_attributes_from_info;
305 iface->copy_async = g_file_real_copy_async;
306 iface->copy_finish = g_file_real_copy_finish;
312 * @file: input #GFile.
314 * Checks to see if a file is native to the platform.
316 * A native file s one expressed in the platform-native filename format,
317 * e.g. "C:\Windows" or "/usr/bin/". This does not mean the file is local,
318 * as it might be on a locally mounted remote filesystem.
320 * On some systems non-native files may be available using
321 * the native filesystem via a userspace filesystem (FUSE), in
322 * these cases this call will return %FALSE, but g_file_get_path()
323 * will still return a native path.
325 * This call does no blocking i/o.
327 * Returns: %TRUE if file is native.
330 g_file_is_native (GFile *file)
334 g_return_val_if_fail (G_IS_FILE (file), FALSE);
336 iface = G_FILE_GET_IFACE (file);
338 return (* iface->is_native) (file);
343 * g_file_has_uri_scheme:
344 * @file: input #GFile.
345 * @uri_scheme: a string containing a URI scheme.
347 * Checks to see if a #GFile has a given URI scheme.
349 * This call does no blocking i/o.
351 * Returns: %TRUE if #GFile's backend supports the
352 * given URI scheme, %FALSE if URI scheme is %NULL,
353 * not supported, or #GFile is invalid.
356 g_file_has_uri_scheme (GFile *file,
357 const char *uri_scheme)
361 g_return_val_if_fail (G_IS_FILE (file), FALSE);
362 g_return_val_if_fail (uri_scheme != NULL, FALSE);
364 iface = G_FILE_GET_IFACE (file);
366 return (* iface->has_uri_scheme) (file, uri_scheme);
371 * g_file_get_uri_scheme:
372 * @file: input #GFile.
374 * Gets the URI scheme for a #GFile.
375 * RFC 3986 decodes the scheme as:
377 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
379 * Common schemes include "file", "http", "ftp", etc.
381 * This call does no blocking i/o.
383 * Returns: a string containing the URI scheme for the given
384 * #GFile. The returned string should be freed with g_free()
385 * when no longer needed.
388 g_file_get_uri_scheme (GFile *file)
392 g_return_val_if_fail (G_IS_FILE (file), NULL);
394 iface = G_FILE_GET_IFACE (file);
396 return (* iface->get_uri_scheme) (file);
401 * g_file_get_basename:
402 * @file: input #GFile.
404 * Gets the base name (the last component of the path) for a given #GFile.
406 * If called for the top level of a system (such as the filesystem root
407 * or a uri like sftp://host/) it will return a single directory separator
408 * (and on Windows, possibly a drive letter).
410 * The base name is a byte string (*not* UTF-8). It has no defined encoding
411 * or rules other than it may not contain zero bytes. If you want to use
412 * filenames in a user interface you should use the display name that you
413 * can get by requesting the %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
414 * attribute with g_file_query_info().
416 * This call does no blocking i/o.
418 * Returns: string containing the #GFile's base name, or %NULL
419 * if given #GFile is invalid. The returned string should be
420 * freed with g_free() when no longer needed.
423 g_file_get_basename (GFile *file)
427 g_return_val_if_fail (G_IS_FILE (file), NULL);
429 iface = G_FILE_GET_IFACE (file);
431 return (* iface->get_basename) (file);
436 * @file: input #GFile.
438 * Gets the local pathname for #GFile, if one exists.
440 * This call does no blocking i/o.
442 * Returns: string containing the #GFile's path, or %NULL if
443 * no such path exists. The returned string should be
444 * freed with g_free() when no longer needed.
447 g_file_get_path (GFile *file)
451 g_return_val_if_fail (G_IS_FILE (file), NULL);
453 iface = G_FILE_GET_IFACE (file);
455 return (* iface->get_path) (file);
460 * @file: input #GFile.
462 * Gets the URI for the @file.
464 * This call does no blocking i/o.
466 * Returns: a string containing the #GFile's URI.
467 * The returned string should be freed with g_free() when no longer needed.
470 g_file_get_uri (GFile *file)
474 g_return_val_if_fail (G_IS_FILE (file), NULL);
476 iface = G_FILE_GET_IFACE (file);
478 return (* iface->get_uri) (file);
482 * g_file_get_parse_name:
483 * @file: input #GFile.
485 * Gets the parse name of the @file.
486 * A parse name is a UTF-8 string that describes the
487 * file such that one can get the #GFile back using
488 * g_file_parse_name().
490 * This is generally used to show the #GFile as a nice
491 * full-pathname kind of string in a user interface,
492 * like in a location entry.
494 * For local files with names that can safely be converted
495 * to UTF8 the pathname is used, otherwise the IRI is used
496 * (a form of URI that allows UTF8 characters unescaped).
498 * This call does no blocking i/o.
500 * Returns: a string containing the #GFile's parse name. The returned
501 * string should be freed with g_free() when no longer needed.
504 g_file_get_parse_name (GFile *file)
508 g_return_val_if_fail (G_IS_FILE (file), NULL);
510 iface = G_FILE_GET_IFACE (file);
512 return (* iface->get_parse_name) (file);
517 * @file: input #GFile.
519 * Duplicates a #GFile handle. This operation does not duplicate
520 * the actual file or directory represented by the #GFile; see
521 * g_file_copy() if attempting to copy a file.
523 * This call does no blocking i/o.
525 * Returns: a new #GFile that is a duplicate of the given #GFile.
528 g_file_dup (GFile *file)
532 g_return_val_if_fail (G_IS_FILE (file), NULL);
534 iface = G_FILE_GET_IFACE (file);
536 return (* iface->dup) (file);
541 * @file: #gconstpointer to a #GFile.
543 * Creates a hash value for a #GFile.
545 * This call does no blocking i/o.
547 * Returns: 0 if @file is not a valid #GFile, otherwise an
548 * integer that can be used as hash value for the #GFile.
549 * This function is intended for easily hashing a #GFile to
550 * add to a #GHashTable or similar data structure.
553 g_file_hash (gconstpointer file)
557 g_return_val_if_fail (G_IS_FILE (file), 0);
559 iface = G_FILE_GET_IFACE (file);
561 return (* iface->hash) ((GFile *)file);
566 * @file1: the first #GFile.
567 * @file2: the second #GFile.
569 * Checks equality of two given #GFile<!-- -->s. Note that two
570 * #GFile<!-- -->s that differ can still refer to the same
571 * file on the filesystem due to various forms of filename
574 * This call does no blocking i/o.
576 * Returns: %TRUE if @file1 and @file2 are equal.
577 * %FALSE if either is not a #GFile.
580 g_file_equal (GFile *file1,
585 g_return_val_if_fail (G_IS_FILE (file1), FALSE);
586 g_return_val_if_fail (G_IS_FILE (file2), FALSE);
588 if (G_TYPE_FROM_INSTANCE (file1) != G_TYPE_FROM_INSTANCE (file2))
591 iface = G_FILE_GET_IFACE (file1);
593 return (* iface->equal) (file1, file2);
599 * @file: input #GFile.
601 * Gets the parent directory for the @file.
602 * If the @file represents the root directory of the
603 * file system, then %NULL will be returned.
605 * This call does no blocking i/o.
607 * Returns: a #GFile structure to the parent of the given
608 * #GFile or %NULL if there is no parent.
609 * Free the returned object with g_object_unref().
612 g_file_get_parent (GFile *file)
616 g_return_val_if_fail (G_IS_FILE (file), NULL);
618 iface = G_FILE_GET_IFACE (file);
620 return (* iface->get_parent) (file);
625 * @file: input #GFile
626 * @parent: the parent to check for, or %NULL
628 * Checks if @file has a parent, and optionally, if it is @parent.
630 * If @parent is %NULL then this function returns %TRUE if @file has any
631 * parent at all. If @parent is non-%NULL then %TRUE is only returned
632 * if @file is a child of @parent.
634 * Returns: %TRUE if @file is a child of @parent (or any parent in the
635 * case that @parent is %NULL).
640 g_file_has_parent (GFile *file,
643 GFile *actual_parent;
646 g_return_val_if_fail (G_IS_FILE (file), FALSE);
647 g_return_val_if_fail (parent == NULL || G_IS_FILE (parent), FALSE);
649 actual_parent = g_file_get_parent (file);
651 if (actual_parent != NULL)
654 result = g_file_equal (parent, actual_parent);
658 g_object_unref (actual_parent);
668 * @file: input #GFile.
669 * @name: string containing the child's basename.
671 * Gets a child of @file with basename equal to @name.
673 * Note that the file with that specific name might not exist, but
674 * you can still have a #GFile that points to it. You can use this
675 * for instance to create that file.
677 * This call does no blocking i/o.
679 * Returns: a #GFile to a child specified by @name.
680 * Free the returned object with g_object_unref().
683 g_file_get_child (GFile *file,
686 g_return_val_if_fail (G_IS_FILE (file), NULL);
687 g_return_val_if_fail (name != NULL, NULL);
689 return g_file_resolve_relative_path (file, name);
693 * g_file_get_child_for_display_name:
694 * @file: input #GFile.
695 * @display_name: string to a possible child.
698 * Gets the child of @file for a given @display_name (i.e. a UTF8
699 * version of the name). If this function fails, it returns %NULL and @error will be
700 * set. This is very useful when constructing a GFile for a new file
701 * and the user entered the filename in the user interface, for instance
702 * when you select a directory and type a filename in the file selector.
704 * This call does no blocking i/o.
706 * Returns: a #GFile to the specified child, or
707 * %NULL if the display name couldn't be converted.
708 * Free the returned object with g_object_unref().
711 g_file_get_child_for_display_name (GFile *file,
712 const char *display_name,
717 g_return_val_if_fail (G_IS_FILE (file), NULL);
718 g_return_val_if_fail (display_name != NULL, NULL);
720 iface = G_FILE_GET_IFACE (file);
722 return (* iface->get_child_for_display_name) (file, display_name, error);
727 * @file: input #GFile.
728 * @prefix: input #GFile.
730 * Checks whether @file has the prefix specified by @prefix. In other word,
731 * if the names of inital elements of @file<!-- -->s pathname match @prefix.
732 * Only full pathname elements are matched, so a path like /foo is not
733 * considered a prefix of /foobar, only of /foo/bar.
735 * This call does no i/o, as it works purely on names. As such it can
736 * sometimes return %FALSE even if @file is inside a @prefix (from a
737 * filesystem point of view), because the prefix of @file is an alias
740 * Returns: %TRUE if the @files's parent, grandparent, etc is @prefix.
744 g_file_has_prefix (GFile *file,
749 g_return_val_if_fail (G_IS_FILE (file), FALSE);
750 g_return_val_if_fail (G_IS_FILE (prefix), FALSE);
752 if (G_TYPE_FROM_INSTANCE (file) != G_TYPE_FROM_INSTANCE (prefix))
755 iface = G_FILE_GET_IFACE (file);
757 /* The vtable function differs in arg order since we're
758 using the old contains_file call */
759 return (* iface->prefix_matches) (prefix, file);
763 * g_file_get_relative_path:
764 * @parent: input #GFile.
765 * @descendant: input #GFile.
767 * Gets the path for @descendant relative to @parent.
769 * This call does no blocking i/o.
771 * Returns: string with the relative path from @descendant
772 * to @parent, or %NULL if @descendant doesn't have @parent as prefix.
773 * The returned string should be freed with g_free() when no longer needed.
776 g_file_get_relative_path (GFile *parent,
781 g_return_val_if_fail (G_IS_FILE (parent), NULL);
782 g_return_val_if_fail (G_IS_FILE (descendant), NULL);
784 if (G_TYPE_FROM_INSTANCE (parent) != G_TYPE_FROM_INSTANCE (descendant))
787 iface = G_FILE_GET_IFACE (parent);
789 return (* iface->get_relative_path) (parent, descendant);
793 * g_file_resolve_relative_path:
794 * @file: input #GFile.
795 * @relative_path: a given relative path string.
797 * Resolves a relative path for @file to an absolute path.
799 * This call does no blocking i/o.
801 * Returns: #GFile to the resolved path. %NULL if @relative_path
802 * is %NULL or if @file is invalid.
803 * Free the returned object with g_object_unref().
806 g_file_resolve_relative_path (GFile *file,
807 const char *relative_path)
811 g_return_val_if_fail (G_IS_FILE (file), NULL);
812 g_return_val_if_fail (relative_path != NULL, NULL);
814 iface = G_FILE_GET_IFACE (file);
816 return (* iface->resolve_relative_path) (file, relative_path);
820 * g_file_enumerate_children:
821 * @file: input #GFile.
822 * @attributes: an attribute query string.
823 * @flags: a set of #GFileQueryInfoFlags.
824 * @cancellable: optional #GCancellable object, %NULL to ignore.
825 * @error: #GError for error reporting.
827 * Gets the requested information about the files in a directory. The result
828 * is a #GFileEnumerator object that will give out #GFileInfo objects for
829 * all the files in the directory.
831 * The @attribute value is a string that specifies the file attributes that
832 * should be gathered. It is not an error if it's not possible to read a particular
833 * requested attribute from a file - it just won't be set. @attribute should
834 * be a comma-separated list of attribute or attribute wildcards. The wildcard "*"
835 * means all attributes, and a wildcard like "standard::*" means all attributes in the standard
836 * namespace. An example attribute query be "standard::*,owner::user".
837 * The standard attributes are available as defines, like #G_FILE_ATTRIBUTE_STANDARD_NAME.
839 * If @cancellable is not %NULL, then the operation can be cancelled by
840 * triggering the cancellable object from another thread. If the operation
841 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
843 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
844 * If the file is not a directory, the G_FILE_ERROR_NOTDIR error will be returned.
845 * Other errors are possible too.
847 * Returns: A #GFileEnumerator if successful, %NULL on error.
848 * Free the returned object with g_object_unref().
851 g_file_enumerate_children (GFile *file,
852 const char *attributes,
853 GFileQueryInfoFlags flags,
854 GCancellable *cancellable,
860 g_return_val_if_fail (G_IS_FILE (file), NULL);
862 if (g_cancellable_set_error_if_cancelled (cancellable, error))
865 iface = G_FILE_GET_IFACE (file);
867 if (iface->enumerate_children == NULL)
869 g_set_error_literal (error, G_IO_ERROR,
870 G_IO_ERROR_NOT_SUPPORTED,
871 _("Operation not supported"));
875 return (* iface->enumerate_children) (file, attributes, flags,
880 * g_file_enumerate_children_async:
881 * @file: input #GFile.
882 * @attributes: an attribute query string.
883 * @flags: a set of #GFileQueryInfoFlags.
884 * @io_priority: the <link linkend="io-priority">I/O priority</link>
886 * @cancellable: optional #GCancellable object, %NULL to ignore.
887 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
888 * @user_data: the data to pass to callback function
890 * Asynchronously gets the requested information about the files in a directory. The result
891 * is a #GFileEnumerator object that will give out #GFileInfo objects for
892 * all the files in the directory.
894 * For more details, see g_file_enumerate_children() which is
895 * the synchronous version of this call.
897 * When the operation is finished, @callback will be called. You can then call
898 * g_file_enumerate_children_finish() to get the result of the operation.
901 g_file_enumerate_children_async (GFile *file,
902 const char *attributes,
903 GFileQueryInfoFlags flags,
905 GCancellable *cancellable,
906 GAsyncReadyCallback callback,
911 g_return_if_fail (G_IS_FILE (file));
913 iface = G_FILE_GET_IFACE (file);
914 (* iface->enumerate_children_async) (file,
924 * g_file_enumerate_children_finish:
925 * @file: input #GFile.
926 * @res: a #GAsyncResult.
929 * Finishes an async enumerate children operation.
930 * See g_file_enumerate_children_async().
932 * Returns: a #GFileEnumerator or %NULL if an error occurred.
933 * Free the returned object with g_object_unref().
936 g_file_enumerate_children_finish (GFile *file,
942 g_return_val_if_fail (G_IS_FILE (file), NULL);
943 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
945 if (G_IS_SIMPLE_ASYNC_RESULT (res))
947 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
948 if (g_simple_async_result_propagate_error (simple, error))
952 iface = G_FILE_GET_IFACE (file);
953 return (* iface->enumerate_children_finish) (file, res, error);
957 * g_file_query_exists:
958 * @file: input #GFile.
959 * @cancellable: optional #GCancellable object, %NULL to ignore.
961 * Utility function to check if a particular file exists. This is
962 * implemented using g_file_query_info() and as such does blocking I/O.
964 * Note that in many cases it is racy to first check for file existence
965 * and then execute something based on the outcome of that, because the
966 * file might have been created or removed in between the operations. The
967 * general approach to handling that is to not check, but just do the
968 * operation and handle the errors as they come.
970 * As an example of race-free checking, take the case of reading a file, and
971 * if it doesn't exist, creating it. There are two racy versions: read it, and
972 * on error create it; and: check if it exists, if not create it. These
973 * can both result in two processes creating the file (with perhaps a partially
974 * written file as the result). The correct approach is to always try to create
975 * the file with g_file_create() which will either atomically create the file
976 * or fail with a G_IO_ERROR_EXISTS error.
978 * However, in many cases an existence check is useful in a user
979 * interface, for instance to make a menu item sensitive/insensitive, so that
980 * you don't have to fool users that something is possible and then just show
981 * and error dialog. If you do this, you should make sure to also handle the
982 * errors that can happen due to races when you execute the operation.
984 * Returns: %TRUE if the file exists (and can be detected without error), %FALSE otherwise (or if cancelled).
987 g_file_query_exists (GFile *file,
988 GCancellable *cancellable)
992 g_return_val_if_fail (G_IS_FILE(file), FALSE);
994 info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE,
995 G_FILE_QUERY_INFO_NONE, cancellable, NULL);
998 g_object_unref (info);
1006 * g_file_query_file_type:
1007 * @file: input #GFile.
1008 * @flags: a set of #GFileQueryInfoFlags passed to g_file_query_info().
1009 * @cancellable: optional #GCancellable object, %NULL to ignore.
1011 * Utility function to inspect the #GFileType of a file. This is
1012 * implemented using g_file_query_info() and as such does blocking I/O.
1014 * The primary use case of this method is to check if a file is a regular file,
1015 * directory, or symlink.
1017 * Returns: The #GFileType of the file and #G_FILE_TYPE_UNKNOWN if the file
1023 g_file_query_file_type (GFile *file,
1024 GFileQueryInfoFlags flags,
1025 GCancellable *cancellable)
1028 GFileType file_type;
1030 g_return_val_if_fail (G_IS_FILE(file), G_FILE_TYPE_UNKNOWN);
1031 info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, flags,
1035 file_type = g_file_info_get_file_type (info);
1036 g_object_unref (info);
1039 file_type = G_FILE_TYPE_UNKNOWN;
1045 * g_file_query_info:
1046 * @file: input #GFile.
1047 * @attributes: an attribute query string.
1048 * @flags: a set of #GFileQueryInfoFlags.
1049 * @cancellable: optional #GCancellable object, %NULL to ignore.
1050 * @error: a #GError.
1052 * Gets the requested information about specified @file. The result
1053 * is a #GFileInfo object that contains key-value attributes (such as
1054 * the type or size of the file).
1056 * The @attribute value is a string that specifies the file attributes that
1057 * should be gathered. It is not an error if it's not possible to read a particular
1058 * requested attribute from a file - it just won't be set. @attribute should
1059 * be a comma-separated list of attribute or attribute wildcards. The wildcard "*"
1060 * means all attributes, and a wildcard like "standard::*" means all attributes in the standard
1061 * namespace. An example attribute query be "standard::*,owner::user".
1062 * The standard attributes are available as defines, like #G_FILE_ATTRIBUTE_STANDARD_NAME.
1064 * If @cancellable is not %NULL, then the operation can be cancelled by
1065 * triggering the cancellable object from another thread. If the operation
1066 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1068 * For symlinks, normally the information about the target of the
1069 * symlink is returned, rather than information about the symlink itself.
1070 * However if you pass #G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS in @flags the
1071 * information about the symlink itself will be returned. Also, for symlinks
1072 * that point to non-existing files the information about the symlink itself
1075 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1076 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1078 * Returns: a #GFileInfo for the given @file, or %NULL on error.
1079 * Free the returned object with g_object_unref().
1082 g_file_query_info (GFile *file,
1083 const char *attributes,
1084 GFileQueryInfoFlags flags,
1085 GCancellable *cancellable,
1090 g_return_val_if_fail (G_IS_FILE (file), NULL);
1092 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1095 iface = G_FILE_GET_IFACE (file);
1097 if (iface->query_info == NULL)
1099 g_set_error_literal (error, G_IO_ERROR,
1100 G_IO_ERROR_NOT_SUPPORTED,
1101 _("Operation not supported"));
1105 return (* iface->query_info) (file, attributes, flags, cancellable, error);
1109 * g_file_query_info_async:
1110 * @file: input #GFile.
1111 * @attributes: an attribute query string.
1112 * @flags: a set of #GFileQueryInfoFlags.
1113 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1115 * @cancellable: optional #GCancellable object, %NULL to ignore.
1116 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1117 * @user_data: the data to pass to callback function
1119 * Asynchronously gets the requested information about specified @file. The result
1120 * is a #GFileInfo object that contains key-value attributes (such as type or size
1123 * For more details, see g_file_query_info() which is
1124 * the synchronous version of this call.
1126 * When the operation is finished, @callback will be called. You can then call
1127 * g_file_query_info_finish() to get the result of the operation.
1130 g_file_query_info_async (GFile *file,
1131 const char *attributes,
1132 GFileQueryInfoFlags flags,
1134 GCancellable *cancellable,
1135 GAsyncReadyCallback callback,
1140 g_return_if_fail (G_IS_FILE (file));
1142 iface = G_FILE_GET_IFACE (file);
1143 (* iface->query_info_async) (file,
1153 * g_file_query_info_finish:
1154 * @file: input #GFile.
1155 * @res: a #GAsyncResult.
1156 * @error: a #GError.
1158 * Finishes an asynchronous file info query.
1159 * See g_file_query_info_async().
1161 * Returns: #GFileInfo for given @file or %NULL on error.
1162 * Free the returned object with g_object_unref().
1165 g_file_query_info_finish (GFile *file,
1171 g_return_val_if_fail (G_IS_FILE (file), NULL);
1172 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1174 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1176 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1177 if (g_simple_async_result_propagate_error (simple, error))
1181 iface = G_FILE_GET_IFACE (file);
1182 return (* iface->query_info_finish) (file, res, error);
1186 * g_file_query_filesystem_info:
1187 * @file: input #GFile.
1188 * @attributes: an attribute query string.
1189 * @cancellable: optional #GCancellable object, %NULL to ignore.
1190 * @error: a #GError.
1192 * Similar to g_file_query_info(), but obtains information
1193 * about the filesystem the @file is on, rather than the file itself.
1194 * For instance the amount of space available and the type of
1197 * The @attribute value is a string that specifies the file attributes that
1198 * should be gathered. It is not an error if it's not possible to read a particular
1199 * requested attribute from a file - it just won't be set. @attribute should
1200 * be a comma-separated list of attribute or attribute wildcards. The wildcard "*"
1201 * means all attributes, and a wildcard like "fs:*" means all attributes in the fs
1202 * namespace. The standard namespace for filesystem attributes is "fs".
1203 * Common attributes of interest are #G_FILE_ATTRIBUTE_FILESYSTEM_SIZE
1204 * (the total size of the filesystem in bytes), #G_FILE_ATTRIBUTE_FILESYSTEM_FREE (number of
1205 * bytes available), and #G_FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).
1207 * If @cancellable is not %NULL, then the operation can be cancelled by
1208 * triggering the cancellable object from another thread. If the operation
1209 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1211 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1212 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1214 * Returns: a #GFileInfo or %NULL if there was an error.
1215 * Free the returned object with g_object_unref().
1218 g_file_query_filesystem_info (GFile *file,
1219 const char *attributes,
1220 GCancellable *cancellable,
1225 g_return_val_if_fail (G_IS_FILE (file), NULL);
1227 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1230 iface = G_FILE_GET_IFACE (file);
1232 if (iface->query_filesystem_info == NULL)
1234 g_set_error_literal (error, G_IO_ERROR,
1235 G_IO_ERROR_NOT_SUPPORTED,
1236 _("Operation not supported"));
1240 return (* iface->query_filesystem_info) (file, attributes, cancellable, error);
1244 * g_file_query_filesystem_info_async:
1245 * @file: input #GFile.
1246 * @attributes: an attribute query string.
1247 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1249 * @cancellable: optional #GCancellable object, %NULL to ignore.
1250 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1251 * @user_data: the data to pass to callback function
1253 * Asynchronously gets the requested information about the filesystem
1254 * that the specified @file is on. The result is a #GFileInfo object
1255 * that contains key-value attributes (such as type or size for the
1258 * For more details, see g_file_query_filesystem_info() which is the
1259 * synchronous version of this call.
1261 * When the operation is finished, @callback will be called. You can
1262 * then call g_file_query_info_finish() to get the result of the
1266 g_file_query_filesystem_info_async (GFile *file,
1267 const char *attributes,
1269 GCancellable *cancellable,
1270 GAsyncReadyCallback callback,
1275 g_return_if_fail (G_IS_FILE (file));
1277 iface = G_FILE_GET_IFACE (file);
1278 (* iface->query_filesystem_info_async) (file,
1287 * g_file_query_filesystem_info_finish:
1288 * @file: input #GFile.
1289 * @res: a #GAsyncResult.
1290 * @error: a #GError.
1292 * Finishes an asynchronous filesystem info query. See
1293 * g_file_query_filesystem_info_async().
1295 * Returns: #GFileInfo for given @file or %NULL on error.
1296 * Free the returned object with g_object_unref().
1299 g_file_query_filesystem_info_finish (GFile *file,
1305 g_return_val_if_fail (G_IS_FILE (file), NULL);
1306 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1308 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1310 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1311 if (g_simple_async_result_propagate_error (simple, error))
1315 iface = G_FILE_GET_IFACE (file);
1316 return (* iface->query_filesystem_info_finish) (file, res, error);
1320 * g_file_find_enclosing_mount:
1321 * @file: input #GFile.
1322 * @cancellable: optional #GCancellable object, %NULL to ignore.
1323 * @error: a #GError.
1325 * Gets a #GMount for the #GFile.
1327 * If the #GFileIface for @file does not have a mount (e.g. possibly a
1328 * remote share), @error will be set to %G_IO_ERROR_NOT_FOUND and %NULL
1331 * If @cancellable is not %NULL, then the operation can be cancelled by
1332 * triggering the cancellable object from another thread. If the operation
1333 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1335 * Returns: a #GMount where the @file is located or %NULL on error.
1336 * Free the returned object with g_object_unref().
1339 g_file_find_enclosing_mount (GFile *file,
1340 GCancellable *cancellable,
1345 g_return_val_if_fail (G_IS_FILE (file), NULL);
1347 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1350 iface = G_FILE_GET_IFACE (file);
1351 if (iface->find_enclosing_mount == NULL)
1354 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1355 /* Translators: This is an error message when trying to find the
1356 * enclosing (user visible) mount of a file, but none exists. */
1357 _("Containing mount does not exist"));
1361 return (* iface->find_enclosing_mount) (file, cancellable, error);
1365 * g_file_find_enclosing_mount_async:
1367 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1369 * @cancellable: optional #GCancellable object, %NULL to ignore.
1370 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1371 * @user_data: the data to pass to callback function
1373 * Asynchronously gets the mount for the file.
1375 * For more details, see g_file_find_enclosing_mount() which is
1376 * the synchronous version of this call.
1378 * When the operation is finished, @callback will be called. You can then call
1379 * g_file_find_enclosing_mount_finish() to get the result of the operation.
1382 g_file_find_enclosing_mount_async (GFile *file,
1384 GCancellable *cancellable,
1385 GAsyncReadyCallback callback,
1390 g_return_if_fail (G_IS_FILE (file));
1392 iface = G_FILE_GET_IFACE (file);
1393 (* iface->find_enclosing_mount_async) (file,
1401 * g_file_find_enclosing_mount_finish:
1403 * @res: a #GAsyncResult
1406 * Finishes an asynchronous find mount request.
1407 * See g_file_find_enclosing_mount_async().
1409 * Returns: #GMount for given @file or %NULL on error.
1410 * Free the returned object with g_object_unref().
1413 g_file_find_enclosing_mount_finish (GFile *file,
1419 g_return_val_if_fail (G_IS_FILE (file), NULL);
1420 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1422 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1424 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1425 if (g_simple_async_result_propagate_error (simple, error))
1429 iface = G_FILE_GET_IFACE (file);
1430 return (* iface->find_enclosing_mount_finish) (file, res, error);
1436 * @file: #GFile to read.
1437 * @cancellable: a #GCancellable
1438 * @error: a #GError, or %NULL
1440 * Opens a file for reading. The result is a #GFileInputStream that
1441 * can be used to read the contents of the file.
1443 * If @cancellable is not %NULL, then the operation can be cancelled by
1444 * triggering the cancellable object from another thread. If the operation
1445 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1447 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1448 * If the file is a directory, the G_IO_ERROR_IS_DIRECTORY error will be returned.
1449 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1451 * Returns: #GFileInputStream or %NULL on error.
1452 * Free the returned object with g_object_unref().
1455 g_file_read (GFile *file,
1456 GCancellable *cancellable,
1461 g_return_val_if_fail (G_IS_FILE (file), NULL);
1463 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1466 iface = G_FILE_GET_IFACE (file);
1468 if (iface->read_fn == NULL)
1470 g_set_error_literal (error, G_IO_ERROR,
1471 G_IO_ERROR_NOT_SUPPORTED,
1472 _("Operation not supported"));
1476 return (* iface->read_fn) (file, cancellable, error);
1481 * @file: input #GFile.
1482 * @flags: a set of #GFileCreateFlags.
1483 * @cancellable: optional #GCancellable object, %NULL to ignore.
1484 * @error: a #GError, or %NULL
1486 * Gets an output stream for appending data to the file. If
1487 * the file doesn't already exist it is created.
1489 * By default files created are generally readable by everyone,
1490 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1491 * will be made readable only to the current user, to the level that
1492 * is supported on the target filesystem.
1494 * If @cancellable is not %NULL, then the operation can be cancelled by
1495 * triggering the cancellable object from another thread. If the operation
1496 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1498 * Some file systems don't allow all file names, and may
1499 * return an %G_IO_ERROR_INVALID_FILENAME error.
1500 * If the file is a directory the %G_IO_ERROR_IS_DIRECTORY error will be
1501 * returned. Other errors are possible too, and depend on what kind of
1502 * filesystem the file is on.
1504 * Returns: a #GFileOutputStream, or %NULL on error.
1505 * Free the returned object with g_object_unref().
1508 g_file_append_to (GFile *file,
1509 GFileCreateFlags flags,
1510 GCancellable *cancellable,
1515 g_return_val_if_fail (G_IS_FILE (file), NULL);
1517 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1520 iface = G_FILE_GET_IFACE (file);
1522 if (iface->append_to == NULL)
1524 g_set_error_literal (error, G_IO_ERROR,
1525 G_IO_ERROR_NOT_SUPPORTED,
1526 _("Operation not supported"));
1530 return (* iface->append_to) (file, flags, cancellable, error);
1535 * @file: input #GFile.
1536 * @flags: a set of #GFileCreateFlags.
1537 * @cancellable: optional #GCancellable object, %NULL to ignore.
1538 * @error: a #GError, or %NULL
1540 * Creates a new file and returns an output stream for writing to it.
1541 * The file must not already exist.
1543 * By default files created are generally readable by everyone,
1544 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1545 * will be made readable only to the current user, to the level that
1546 * is supported on the target filesystem.
1548 * If @cancellable is not %NULL, then the operation can be cancelled by
1549 * triggering the cancellable object from another thread. If the operation
1550 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1552 * If a file or directory with this name already exists the G_IO_ERROR_EXISTS
1553 * error will be returned.
1554 * Some file systems don't allow all file names, and may
1555 * return an G_IO_ERROR_INVALID_FILENAME error, and if the name
1556 * is to long G_IO_ERROR_FILENAME_TOO_LONG will be returned.
1557 * Other errors are possible too, and depend on what kind of
1558 * filesystem the file is on.
1560 * Returns: a #GFileOutputStream for the newly created file, or
1562 * Free the returned object with g_object_unref().
1565 g_file_create (GFile *file,
1566 GFileCreateFlags flags,
1567 GCancellable *cancellable,
1572 g_return_val_if_fail (G_IS_FILE (file), NULL);
1574 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1577 iface = G_FILE_GET_IFACE (file);
1579 if (iface->create == NULL)
1581 g_set_error_literal (error, G_IO_ERROR,
1582 G_IO_ERROR_NOT_SUPPORTED,
1583 _("Operation not supported"));
1587 return (* iface->create) (file, flags, cancellable, error);
1592 * @file: input #GFile.
1593 * @etag: an optional <link linkend="gfile-etag">entity tag</link> for the
1594 * current #GFile, or #NULL to ignore.
1595 * @make_backup: %TRUE if a backup should be created.
1596 * @flags: a set of #GFileCreateFlags.
1597 * @cancellable: optional #GCancellable object, %NULL to ignore.
1598 * @error: a #GError, or %NULL
1600 * Returns an output stream for overwriting the file, possibly
1601 * creating a backup copy of the file first. If the file doesn't exist,
1602 * it will be created.
1604 * This will try to replace the file in the safest way possible so
1605 * that any errors during the writing will not affect an already
1606 * existing copy of the file. For instance, for local files it
1607 * may write to a temporary file and then atomically rename over
1608 * the destination when the stream is closed.
1610 * By default files created are generally readable by everyone,
1611 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1612 * will be made readable only to the current user, to the level that
1613 * is supported on the target filesystem.
1615 * If @cancellable is not %NULL, then the operation can be cancelled by
1616 * triggering the cancellable object from another thread. If the operation
1617 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1619 * If you pass in a non-#NULL @etag value, then this value is
1620 * compared to the current entity tag of the file, and if they differ
1621 * an G_IO_ERROR_WRONG_ETAG error is returned. This generally means
1622 * that the file has been changed since you last read it. You can get
1623 * the new etag from g_file_output_stream_get_etag() after you've
1624 * finished writing and closed the #GFileOutputStream. When you load
1625 * a new file you can use g_file_input_stream_query_info() to get
1626 * the etag of the file.
1628 * If @make_backup is %TRUE, this function will attempt to make a backup
1629 * of the current file before overwriting it. If this fails a G_IO_ERROR_CANT_CREATE_BACKUP
1630 * error will be returned. If you want to replace anyway, try again with
1631 * @make_backup set to %FALSE.
1633 * If the file is a directory the G_IO_ERROR_IS_DIRECTORY error will be returned,
1634 * and if the file is some other form of non-regular file then a
1635 * G_IO_ERROR_NOT_REGULAR_FILE error will be returned.
1636 * Some file systems don't allow all file names, and may
1637 * return an G_IO_ERROR_INVALID_FILENAME error, and if the name
1638 * is to long G_IO_ERROR_FILENAME_TOO_LONG will be returned.
1639 * Other errors are possible too, and depend on what kind of
1640 * filesystem the file is on.
1642 * Returns: a #GFileOutputStream or %NULL on error.
1643 * Free the returned object with g_object_unref().
1646 g_file_replace (GFile *file,
1648 gboolean make_backup,
1649 GFileCreateFlags flags,
1650 GCancellable *cancellable,
1655 g_return_val_if_fail (G_IS_FILE (file), NULL);
1657 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1660 iface = G_FILE_GET_IFACE (file);
1662 if (iface->replace == NULL)
1664 g_set_error_literal (error, G_IO_ERROR,
1665 G_IO_ERROR_NOT_SUPPORTED,
1666 _("Operation not supported"));
1671 /* Handle empty tag string as NULL in consistent way. */
1672 if (etag && *etag == 0)
1675 return (* iface->replace) (file, etag, make_backup, flags, cancellable, error);
1679 * g_file_open_readwrite:
1680 * @file: #GFile to open
1681 * @cancellable: a #GCancellable
1682 * @error: a #GError, or %NULL
1684 * Opens an existing file for reading and writing. The result is
1685 * a #GFileIOStream that can be used to read and write the contents of the file.
1687 * If @cancellable is not %NULL, then the operation can be cancelled by
1688 * triggering the cancellable object from another thread. If the operation
1689 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1691 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1692 * If the file is a directory, the G_IO_ERROR_IS_DIRECTORY error will be returned.
1693 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1694 * Note that in many non-local file cases read and write streams are not supported,
1695 * so make sure you really need to do read and write streaming, rather than
1696 * just opening for reading or writing.
1698 * Returns: #GFileIOStream or %NULL on error.
1699 * Free the returned object with g_object_unref().
1704 g_file_open_readwrite (GFile *file,
1705 GCancellable *cancellable,
1710 g_return_val_if_fail (G_IS_FILE (file), NULL);
1712 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1715 iface = G_FILE_GET_IFACE (file);
1717 if (iface->open_readwrite == NULL)
1719 g_set_error_literal (error, G_IO_ERROR,
1720 G_IO_ERROR_NOT_SUPPORTED,
1721 _("Operation not supported"));
1725 return (* iface->open_readwrite) (file, cancellable, error);
1729 * g_file_create_readwrite:
1731 * @flags: a set of #GFileCreateFlags
1732 * @cancellable: optional #GCancellable object, %NULL to ignore
1733 * @error: return location for a #GError, or %NULL
1735 * Creates a new file and returns a stream for reading and writing to it.
1736 * The file must not already exist.
1738 * By default files created are generally readable by everyone,
1739 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1740 * will be made readable only to the current user, to the level that
1741 * is supported on the target filesystem.
1743 * If @cancellable is not %NULL, then the operation can be cancelled by
1744 * triggering the cancellable object from another thread. If the operation
1745 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1747 * If a file or directory with this name already exists the %G_IO_ERROR_EXISTS
1748 * error will be returned. Some file systems don't allow all file names,
1749 * and may return an %G_IO_ERROR_INVALID_FILENAME error, and if the name
1750 * is too long, %G_IO_ERROR_FILENAME_TOO_LONG will be returned. Other errors
1751 * are possible too, and depend on what kind of filesystem the file is on.
1753 * Note that in many non-local file cases read and write streams are not
1754 * supported, so make sure you really need to do read and write streaming,
1755 * rather than just opening for reading or writing.
1757 * Returns: a #GFileIOStream for the newly created file, or %NULL on error.
1758 * Free the returned object with g_object_unref().
1763 g_file_create_readwrite (GFile *file,
1764 GFileCreateFlags flags,
1765 GCancellable *cancellable,
1770 g_return_val_if_fail (G_IS_FILE (file), NULL);
1772 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1775 iface = G_FILE_GET_IFACE (file);
1777 if (iface->create_readwrite == NULL)
1779 g_set_error_literal (error, G_IO_ERROR,
1780 G_IO_ERROR_NOT_SUPPORTED,
1781 _("Operation not supported"));
1785 return (* iface->create_readwrite) (file, flags, cancellable, error);
1789 * g_file_replace_readwrite:
1791 * @etag: an optional <link linkend="gfile-etag">entity tag</link> for the
1792 * current #GFile, or #NULL to ignore
1793 * @make_backup: %TRUE if a backup should be created
1794 * @flags: a set of #GFileCreateFlags
1795 * @cancellable: optional #GCancellable object, %NULL to ignore
1796 * @error: return location for a #GError, or %NULL
1798 * Returns an output stream for overwriting the file in readwrite mode,
1799 * possibly creating a backup copy of the file first. If the file doesn't
1800 * exist, it will be created.
1802 * For details about the behaviour, see g_file_replace() which does the same
1803 * thing but returns an output stream only.
1805 * Note that in many non-local file cases read and write streams are not
1806 * supported, so make sure you really need to do read and write streaming,
1807 * rather than just opening for reading or writing.
1809 * Returns: a #GFileIOStream or %NULL on error.
1810 * Free the returned object with g_object_unref().
1815 g_file_replace_readwrite (GFile *file,
1817 gboolean make_backup,
1818 GFileCreateFlags flags,
1819 GCancellable *cancellable,
1824 g_return_val_if_fail (G_IS_FILE (file), NULL);
1826 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1829 iface = G_FILE_GET_IFACE (file);
1831 if (iface->replace_readwrite == NULL)
1833 g_set_error_literal (error, G_IO_ERROR,
1834 G_IO_ERROR_NOT_SUPPORTED,
1835 _("Operation not supported"));
1839 return (* iface->replace_readwrite) (file, etag, make_backup, flags, cancellable, error);
1843 * g_file_read_async:
1844 * @file: input #GFile
1845 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1847 * @cancellable: optional #GCancellable object, %NULL to ignore.
1848 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1849 * @user_data: the data to pass to callback function
1851 * Asynchronously opens @file for reading.
1853 * For more details, see g_file_read() which is
1854 * the synchronous version of this call.
1856 * When the operation is finished, @callback will be called. You can then call
1857 * g_file_read_finish() to get the result of the operation.
1860 g_file_read_async (GFile *file,
1862 GCancellable *cancellable,
1863 GAsyncReadyCallback callback,
1868 g_return_if_fail (G_IS_FILE (file));
1870 iface = G_FILE_GET_IFACE (file);
1871 (* iface->read_async) (file,
1879 * g_file_read_finish:
1880 * @file: input #GFile.
1881 * @res: a #GAsyncResult.
1882 * @error: a #GError, or %NULL
1884 * Finishes an asynchronous file read operation started with
1885 * g_file_read_async().
1887 * Returns: a #GFileInputStream or %NULL on error.
1888 * Free the returned object with g_object_unref().
1891 g_file_read_finish (GFile *file,
1897 g_return_val_if_fail (G_IS_FILE (file), NULL);
1898 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1900 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1902 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1903 if (g_simple_async_result_propagate_error (simple, error))
1907 iface = G_FILE_GET_IFACE (file);
1908 return (* iface->read_finish) (file, res, error);
1912 * g_file_append_to_async:
1913 * @file: input #GFile.
1914 * @flags: a set of #GFileCreateFlags.
1915 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1917 * @cancellable: optional #GCancellable object, %NULL to ignore.
1918 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1919 * @user_data: the data to pass to callback function
1921 * Asynchronously opens @file for appending.
1923 * For more details, see g_file_append_to() which is
1924 * the synchronous version of this call.
1926 * When the operation is finished, @callback will be called. You can then call
1927 * g_file_append_to_finish() to get the result of the operation.
1930 g_file_append_to_async (GFile *file,
1931 GFileCreateFlags flags,
1933 GCancellable *cancellable,
1934 GAsyncReadyCallback callback,
1939 g_return_if_fail (G_IS_FILE (file));
1941 iface = G_FILE_GET_IFACE (file);
1942 (* iface->append_to_async) (file,
1951 * g_file_append_to_finish:
1952 * @file: input #GFile.
1953 * @res: #GAsyncResult
1954 * @error: a #GError, or %NULL
1956 * Finishes an asynchronous file append operation started with
1957 * g_file_append_to_async().
1959 * Returns: a valid #GFileOutputStream or %NULL on error.
1960 * Free the returned object with g_object_unref().
1963 g_file_append_to_finish (GFile *file,
1969 g_return_val_if_fail (G_IS_FILE (file), NULL);
1970 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1972 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1974 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1975 if (g_simple_async_result_propagate_error (simple, error))
1979 iface = G_FILE_GET_IFACE (file);
1980 return (* iface->append_to_finish) (file, res, error);
1984 * g_file_create_async:
1985 * @file: input #GFile.
1986 * @flags: a set of #GFileCreateFlags.
1987 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1989 * @cancellable: optional #GCancellable object, %NULL to ignore.
1990 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1991 * @user_data: the data to pass to callback function
1993 * Asynchronously creates a new file and returns an output stream for writing to it.
1994 * The file must not already exist.
1996 * For more details, see g_file_create() which is
1997 * the synchronous version of this call.
1999 * When the operation is finished, @callback will be called. You can then call
2000 * g_file_create_finish() to get the result of the operation.
2003 g_file_create_async (GFile *file,
2004 GFileCreateFlags flags,
2006 GCancellable *cancellable,
2007 GAsyncReadyCallback callback,
2012 g_return_if_fail (G_IS_FILE (file));
2014 iface = G_FILE_GET_IFACE (file);
2015 (* iface->create_async) (file,
2024 * g_file_create_finish:
2025 * @file: input #GFile.
2026 * @res: a #GAsyncResult.
2027 * @error: a #GError, or %NULL
2029 * Finishes an asynchronous file create operation started with
2030 * g_file_create_async().
2032 * Returns: a #GFileOutputStream or %NULL on error.
2033 * Free the returned object with g_object_unref().
2036 g_file_create_finish (GFile *file,
2042 g_return_val_if_fail (G_IS_FILE (file), NULL);
2043 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2045 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2047 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2048 if (g_simple_async_result_propagate_error (simple, error))
2052 iface = G_FILE_GET_IFACE (file);
2053 return (* iface->create_finish) (file, res, error);
2057 * g_file_replace_async:
2058 * @file: input #GFile.
2059 * @etag: an <link linkend="gfile-etag">entity tag</link> for the
2060 * current #GFile, or NULL to ignore.
2061 * @make_backup: %TRUE if a backup should be created.
2062 * @flags: a set of #GFileCreateFlags.
2063 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2065 * @cancellable: optional #GCancellable object, %NULL to ignore.
2066 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
2067 * @user_data: the data to pass to callback function
2069 * Asynchronously overwrites the file, replacing the contents, possibly
2070 * creating a backup copy of the file first.
2072 * For more details, see g_file_replace() which is
2073 * the synchronous version of this call.
2075 * When the operation is finished, @callback will be called. You can then call
2076 * g_file_replace_finish() to get the result of the operation.
2079 g_file_replace_async (GFile *file,
2081 gboolean make_backup,
2082 GFileCreateFlags flags,
2084 GCancellable *cancellable,
2085 GAsyncReadyCallback callback,
2090 g_return_if_fail (G_IS_FILE (file));
2092 iface = G_FILE_GET_IFACE (file);
2093 (* iface->replace_async) (file,
2104 * g_file_replace_finish:
2105 * @file: input #GFile.
2106 * @res: a #GAsyncResult.
2107 * @error: a #GError, or %NULL
2109 * Finishes an asynchronous file replace operation started with
2110 * g_file_replace_async().
2112 * Returns: a #GFileOutputStream, or %NULL on error.
2113 * Free the returned object with g_object_unref().
2116 g_file_replace_finish (GFile *file,
2122 g_return_val_if_fail (G_IS_FILE (file), NULL);
2123 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2125 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2127 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2128 if (g_simple_async_result_propagate_error (simple, error))
2132 iface = G_FILE_GET_IFACE (file);
2133 return (* iface->replace_finish) (file, res, error);
2138 * g_file_open_readwrite_async:
2139 * @file: input #GFile.
2140 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2142 * @cancellable: optional #GCancellable object, %NULL to ignore.
2143 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
2144 * @user_data: the data to pass to callback function
2146 * Asynchronously opens @file for reading and writing.
2148 * For more details, see g_file_open_readwrite() which is
2149 * the synchronous version of this call.
2151 * When the operation is finished, @callback will be called. You can then call
2152 * g_file_open_readwrite_finish() to get the result of the operation.
2157 g_file_open_readwrite_async (GFile *file,
2159 GCancellable *cancellable,
2160 GAsyncReadyCallback callback,
2165 g_return_if_fail (G_IS_FILE (file));
2167 iface = G_FILE_GET_IFACE (file);
2168 (* iface->open_readwrite_async) (file,
2176 * g_file_open_readwrite_finish:
2177 * @file: input #GFile.
2178 * @res: a #GAsyncResult.
2179 * @error: a #GError, or %NULL
2181 * Finishes an asynchronous file read operation started with
2182 * g_file_open_readwrite_async().
2184 * Returns: a #GFileIOStream or %NULL on error.
2185 * Free the returned object with g_object_unref().
2190 g_file_open_readwrite_finish (GFile *file,
2196 g_return_val_if_fail (G_IS_FILE (file), NULL);
2197 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2199 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2201 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2202 if (g_simple_async_result_propagate_error (simple, error))
2206 iface = G_FILE_GET_IFACE (file);
2207 return (* iface->open_readwrite_finish) (file, res, error);
2212 * g_file_create_readwrite_async:
2213 * @file: input #GFile
2214 * @flags: a set of #GFileCreateFlags
2215 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2217 * @cancellable: optional #GCancellable object, %NULL to ignore
2218 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
2219 * @user_data: the data to pass to callback function
2221 * Asynchronously creates a new file and returns a stream for reading and
2222 * writing to it. The file must not already exist.
2224 * For more details, see g_file_create_readwrite() which is
2225 * the synchronous version of this call.
2227 * When the operation is finished, @callback will be called. You can then
2228 * call g_file_create_readwrite_finish() to get the result of the operation.
2233 g_file_create_readwrite_async (GFile *file,
2234 GFileCreateFlags flags,
2236 GCancellable *cancellable,
2237 GAsyncReadyCallback callback,
2242 g_return_if_fail (G_IS_FILE (file));
2244 iface = G_FILE_GET_IFACE (file);
2245 (* iface->create_readwrite_async) (file,
2254 * g_file_create_readwrite_finish:
2255 * @file: input #GFile
2256 * @res: a #GAsyncResult
2257 * @error: a #GError, or %NULL
2259 * Finishes an asynchronous file create operation started with
2260 * g_file_create_readwrite_async().
2262 * Returns: a #GFileIOStream or %NULL on error.
2263 * Free the returned object with g_object_unref().
2268 g_file_create_readwrite_finish (GFile *file,
2274 g_return_val_if_fail (G_IS_FILE (file), NULL);
2275 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2277 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2279 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2280 if (g_simple_async_result_propagate_error (simple, error))
2284 iface = G_FILE_GET_IFACE (file);
2285 return (* iface->create_readwrite_finish) (file, res, error);
2289 * g_file_replace_readwrite_async:
2290 * @file: input #GFile.
2291 * @etag: an <link linkend="gfile-etag">entity tag</link> for the
2292 * current #GFile, or NULL to ignore.
2293 * @make_backup: %TRUE if a backup should be created.
2294 * @flags: a set of #GFileCreateFlags.
2295 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2297 * @cancellable: optional #GCancellable object, %NULL to ignore.
2298 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
2299 * @user_data: the data to pass to callback function
2301 * Asynchronously overwrites the file in read-write mode, replacing the
2302 * contents, possibly creating a backup copy of the file first.
2304 * For more details, see g_file_replace_readwrite() which is
2305 * the synchronous version of this call.
2307 * When the operation is finished, @callback will be called. You can then
2308 * call g_file_replace_readwrite_finish() to get the result of the operation.
2313 g_file_replace_readwrite_async (GFile *file,
2315 gboolean make_backup,
2316 GFileCreateFlags flags,
2318 GCancellable *cancellable,
2319 GAsyncReadyCallback callback,
2324 g_return_if_fail (G_IS_FILE (file));
2326 iface = G_FILE_GET_IFACE (file);
2327 (* iface->replace_readwrite_async) (file,
2338 * g_file_replace_readwrite_finish:
2339 * @file: input #GFile.
2340 * @res: a #GAsyncResult.
2341 * @error: a #GError, or %NULL
2343 * Finishes an asynchronous file replace operation started with
2344 * g_file_replace_readwrite_async().
2346 * Returns: a #GFileIOStream, or %NULL on error.
2347 * Free the returned object with g_object_unref().
2352 g_file_replace_readwrite_finish (GFile *file,
2358 g_return_val_if_fail (G_IS_FILE (file), NULL);
2359 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2361 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2363 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2364 if (g_simple_async_result_propagate_error (simple, error))
2368 iface = G_FILE_GET_IFACE (file);
2369 return (* iface->replace_readwrite_finish) (file, res, error);
2373 copy_symlink (GFile *destination,
2374 GFileCopyFlags flags,
2375 GCancellable *cancellable,
2380 gboolean tried_delete;
2382 GFileType file_type;
2384 tried_delete = FALSE;
2388 if (!g_file_make_symbolic_link (destination, target, cancellable, &my_error))
2390 /* Maybe it already existed, and we want to overwrite? */
2391 if (!tried_delete && (flags & G_FILE_COPY_OVERWRITE) &&
2392 my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_EXISTS)
2394 g_error_free (my_error);
2397 /* Don't overwrite if the destination is a directory */
2398 info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
2399 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2400 cancellable, &my_error);
2403 file_type = g_file_info_get_file_type (info);
2404 g_object_unref (info);
2406 if (file_type == G_FILE_TYPE_DIRECTORY)
2408 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY,
2409 _("Can't copy over directory"));
2414 if (!g_file_delete (destination, cancellable, error))
2417 tried_delete = TRUE;
2421 g_propagate_error (error, my_error);
2428 static GInputStream *
2429 open_source_for_copy (GFile *source,
2431 GFileCopyFlags flags,
2432 GCancellable *cancellable,
2438 GFileType file_type;
2441 in = (GInputStream *)g_file_read (source, cancellable, &my_error);
2445 /* There was an error opening the source, try to set a good error for it: */
2447 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_IS_DIRECTORY)
2449 /* The source is a directory, don't fail with WOULD_RECURSE immediately,
2450 * as that is less useful to the app. Better check for errors on the
2453 g_error_free (my_error);
2456 info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
2457 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2458 cancellable, &my_error);
2461 file_type = g_file_info_get_file_type (info);
2462 g_object_unref (info);
2464 if (flags & G_FILE_COPY_OVERWRITE)
2466 if (file_type == G_FILE_TYPE_DIRECTORY)
2468 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_MERGE,
2469 _("Can't copy directory over directory"));
2472 /* continue to would_recurse error */
2476 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
2477 _("Target file exists"));
2483 /* Error getting info from target, return that error
2484 * (except for NOT_FOUND, which is no error here)
2486 if (my_error->domain != G_IO_ERROR && my_error->code != G_IO_ERROR_NOT_FOUND)
2488 g_propagate_error (error, my_error);
2491 g_error_free (my_error);
2494 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_RECURSE,
2495 _("Can't recursively copy directory"));
2499 g_propagate_error (error, my_error);
2504 should_copy (GFileAttributeInfo *info,
2506 gboolean skip_perms)
2508 if (skip_perms && strcmp(info->name, "unix::mode") == 0)
2512 return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED;
2513 return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE;
2517 build_attribute_list_for_copy (GFileAttributeInfoList *attributes,
2518 GFileAttributeInfoList *namespaces,
2520 gboolean skip_perms)
2527 s = g_string_new ("");
2531 for (i = 0; i < attributes->n_infos; i++)
2533 if (should_copy (&attributes->infos[i], as_move, skip_perms))
2538 g_string_append_c (s, ',');
2540 g_string_append (s, attributes->infos[i].name);
2547 for (i = 0; i < namespaces->n_infos; i++)
2549 if (should_copy (&namespaces->infos[i], as_move, FALSE))
2554 g_string_append_c (s, ',');
2556 g_string_append (s, namespaces->infos[i].name);
2557 g_string_append (s, "::*");
2562 return g_string_free (s, FALSE);
2566 * g_file_copy_attributes:
2567 * @source: a #GFile with attributes.
2568 * @destination: a #GFile to copy attributes to.
2569 * @flags: a set of #GFileCopyFlags.
2570 * @cancellable: optional #GCancellable object, %NULL to ignore.
2571 * @error: a #GError, %NULL to ignore.
2573 * Copies the file attributes from @source to @destination.
2575 * Normally only a subset of the file attributes are copied,
2576 * those that are copies in a normal file copy operation
2577 * (which for instance does not include e.g. owner). However
2578 * if #G_FILE_COPY_ALL_METADATA is specified in @flags, then
2579 * all the metadata that is possible to copy is copied. This
2580 * is useful when implementing move by copy + delete source.
2582 * Returns: %TRUE if the attributes were copied successfully, %FALSE otherwise.
2585 g_file_copy_attributes (GFile *source,
2587 GFileCopyFlags flags,
2588 GCancellable *cancellable,
2591 GFileAttributeInfoList *attributes, *namespaces;
2592 char *attrs_to_read;
2596 gboolean source_nofollow_symlinks;
2597 gboolean skip_perms;
2599 as_move = flags & G_FILE_COPY_ALL_METADATA;
2600 source_nofollow_symlinks = flags & G_FILE_COPY_NOFOLLOW_SYMLINKS;
2601 skip_perms = (flags & G_FILE_COPY_TARGET_DEFAULT_PERMS) != 0;
2603 /* Ignore errors here, if the target supports no attributes there is nothing to copy */
2604 attributes = g_file_query_settable_attributes (destination, cancellable, NULL);
2605 namespaces = g_file_query_writable_namespaces (destination, cancellable, NULL);
2607 if (attributes == NULL && namespaces == NULL)
2610 attrs_to_read = build_attribute_list_for_copy (attributes, namespaces, as_move, skip_perms);
2612 /* Ignore errors here, if we can't read some info (e.g. if it doesn't exist)
2613 * we just don't copy it.
2615 info = g_file_query_info (source, attrs_to_read,
2616 source_nofollow_symlinks ? G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS:0,
2620 g_free (attrs_to_read);
2625 res = g_file_set_attributes_from_info (destination,
2627 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2630 g_object_unref (info);
2633 g_file_attribute_info_list_unref (attributes);
2634 g_file_attribute_info_list_unref (namespaces);
2640 copy_stream_with_progress (GInputStream *in,
2643 GCancellable *cancellable,
2644 GFileProgressCallback progress_callback,
2645 gpointer progress_callback_data,
2648 gssize n_read, n_written;
2649 goffset current_size;
2650 char buffer[1024*64], *p;
2656 /* avoid performance impact of querying total size when it's not needed */
2657 if (progress_callback)
2659 info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (in),
2660 G_FILE_ATTRIBUTE_STANDARD_SIZE,
2664 if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
2665 total_size = g_file_info_get_size (info);
2666 g_object_unref (info);
2669 if (total_size == -1)
2671 info = g_file_query_info (source,
2672 G_FILE_ATTRIBUTE_STANDARD_SIZE,
2673 G_FILE_QUERY_INFO_NONE,
2677 if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
2678 total_size = g_file_info_get_size (info);
2679 g_object_unref (info);
2684 if (total_size == -1)
2691 n_read = g_input_stream_read (in, buffer, sizeof (buffer), cancellable, error);
2701 current_size += n_read;
2706 n_written = g_output_stream_write (out, p, n_read, cancellable, error);
2707 if (n_written == -1)
2714 n_read -= n_written;
2720 if (progress_callback)
2721 progress_callback (current_size, total_size, progress_callback_data);
2724 /* Make sure we send full copied size */
2725 if (progress_callback)
2726 progress_callback (current_size, total_size, progress_callback_data);
2734 do_splice (int fd_in,
2739 long *bytes_transferd,
2745 result = splice (fd_in, off_in, fd_out, off_out, len, SPLICE_F_MORE);
2753 else if (errsv == ENOSYS || errsv == EINVAL)
2754 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2755 _("Splice not supported"));
2757 g_set_error (error, G_IO_ERROR,
2758 g_io_error_from_errno (errsv),
2759 _("Error splicing file: %s"),
2760 g_strerror (errsv));
2765 *bytes_transferd = result;
2770 splice_stream_with_progress (GInputStream *in,
2772 GCancellable *cancellable,
2773 GFileProgressCallback progress_callback,
2774 gpointer progress_callback_data,
2784 fd_in = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (in));
2785 fd_out = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (out));
2787 if (pipe (buffer) != 0)
2789 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2790 "Pipe creation failed");
2795 /* avoid performance impact of querying total size when it's not needed */
2796 if (progress_callback)
2800 if (fstat (fd_in, &sbuf) == 0)
2801 total_size = sbuf.st_size;
2804 if (total_size == -1)
2807 offset_in = offset_out = 0;
2814 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2817 if (!do_splice (fd_in, &offset_in, buffer[1], NULL, 1024*64, &n_read, error))
2828 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2831 if (!do_splice (buffer[0], NULL, fd_out, &offset_out, n_read, &n_written, error))
2834 n_read -= n_written;
2837 if (progress_callback)
2838 progress_callback (offset_in, total_size, progress_callback_data);
2841 /* Make sure we send full copied size */
2842 if (progress_callback)
2843 progress_callback (offset_in, total_size, progress_callback_data);
2854 file_copy_fallback (GFile *source,
2856 GFileCopyFlags flags,
2857 GCancellable *cancellable,
2858 GFileProgressCallback progress_callback,
2859 gpointer progress_callback_data,
2868 gboolean fallback = TRUE;
2871 /* need to know the file type */
2872 info = g_file_query_info (source,
2873 G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
2874 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2881 /* Maybe copy the symlink? */
2882 if ((flags & G_FILE_COPY_NOFOLLOW_SYMLINKS) &&
2883 g_file_info_get_file_type (info) == G_FILE_TYPE_SYMBOLIC_LINK)
2885 target = g_file_info_get_symlink_target (info);
2888 if (!copy_symlink (destination, flags, cancellable, target, error))
2890 g_object_unref (info);
2894 g_object_unref (info);
2897 /* ... else fall back on a regular file copy */
2898 g_object_unref (info);
2900 /* Handle "special" files (pipes, device nodes, ...)? */
2901 else if (g_file_info_get_file_type (info) == G_FILE_TYPE_SPECIAL)
2903 /* FIXME: could try to recreate device nodes and others? */
2905 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2906 _("Can't copy special file"));
2907 g_object_unref (info);
2910 /* Everything else should just fall back on a regular copy. */
2912 g_object_unref (info);
2914 in = open_source_for_copy (source, destination, flags, cancellable, error);
2918 if (flags & G_FILE_COPY_OVERWRITE)
2920 out = (GOutputStream *)g_file_replace (destination,
2922 flags & G_FILE_COPY_BACKUP,
2923 G_FILE_CREATE_REPLACE_DESTINATION,
2924 cancellable, error);
2928 out = (GOutputStream *)g_file_create (destination, 0, cancellable, error);
2933 g_object_unref (in);
2938 if (G_IS_FILE_DESCRIPTOR_BASED (in) && G_IS_FILE_DESCRIPTOR_BASED (out))
2940 GError *splice_err = NULL;
2942 result = splice_stream_with_progress (in, out, cancellable,
2943 progress_callback, progress_callback_data,
2946 if (result || !g_error_matches (splice_err, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
2950 g_propagate_error (error, splice_err);
2953 g_clear_error (&splice_err);
2958 result = copy_stream_with_progress (in, out, source, cancellable,
2959 progress_callback, progress_callback_data,
2962 /* Don't care about errors in source here */
2963 g_input_stream_close (in, cancellable, NULL);
2965 /* But write errors on close are bad! */
2966 if (!g_output_stream_close (out, cancellable, result ? error : NULL))
2969 g_object_unref (in);
2970 g_object_unref (out);
2972 if (result == FALSE)
2976 /* Ignore errors here. Failure to copy metadata is not a hard error */
2977 g_file_copy_attributes (source, destination,
2978 flags, cancellable, NULL);
2985 * @source: input #GFile.
2986 * @destination: destination #GFile
2987 * @flags: set of #GFileCopyFlags
2988 * @cancellable: optional #GCancellable object, %NULL to ignore.
2989 * @progress_callback: function to callback with progress information
2990 * @progress_callback_data: user data to pass to @progress_callback
2991 * @error: #GError to set on error, or %NULL
2993 * Copies the file @source to the location specified by @destination.
2994 * Can not handle recursive copies of directories.
2996 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
2997 * existing @destination file is overwritten.
2999 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
3000 * will be copied as symlinks, otherwise the target of the
3001 * @source symlink will be copied.
3003 * If @cancellable is not %NULL, then the operation can be cancelled by
3004 * triggering the cancellable object from another thread. If the operation
3005 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3007 * If @progress_callback is not %NULL, then the operation can be monitored by
3008 * setting this to a #GFileProgressCallback function. @progress_callback_data
3009 * will be passed to this function. It is guaranteed that this callback will
3010 * be called after all data has been transferred with the total number of bytes
3011 * copied during the operation.
3013 * If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
3014 * error is returned, independent on the status of the @destination.
3016 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then the
3017 * error G_IO_ERROR_EXISTS is returned.
3019 * If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY
3020 * error is returned. If trying to overwrite a directory with a directory the
3021 * G_IO_ERROR_WOULD_MERGE error is returned.
3023 * If the source is a directory and the target does not exist, or #G_FILE_COPY_OVERWRITE is
3024 * specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error
3027 * If you are interested in copying the #GFile object itself (not the on-disk
3028 * file), see g_file_dup().
3030 * Returns: %TRUE on success, %FALSE otherwise.
3033 g_file_copy (GFile *source,
3035 GFileCopyFlags flags,
3036 GCancellable *cancellable,
3037 GFileProgressCallback progress_callback,
3038 gpointer progress_callback_data,
3045 g_return_val_if_fail (G_IS_FILE (source), FALSE);
3046 g_return_val_if_fail (G_IS_FILE (destination), FALSE);
3048 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3051 iface = G_FILE_GET_IFACE (destination);
3055 res = (* iface->copy) (source, destination,
3057 progress_callback, progress_callback_data,
3063 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3065 g_propagate_error (error, my_error);
3069 g_clear_error (&my_error);
3072 /* If the types are different, and the destination method failed
3073 also try the source method */
3074 if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
3076 iface = G_FILE_GET_IFACE (source);
3081 res = (* iface->copy) (source, destination,
3083 progress_callback, progress_callback_data,
3089 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3091 g_propagate_error (error, my_error);
3095 g_clear_error (&my_error);
3099 return file_copy_fallback (source, destination, flags, cancellable,
3100 progress_callback, progress_callback_data,
3105 * g_file_copy_async:
3106 * @source: input #GFile.
3107 * @destination: destination #GFile
3108 * @flags: set of #GFileCopyFlags
3109 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3111 * @cancellable: optional #GCancellable object, %NULL to ignore.
3112 * @progress_callback: function to callback with progress information
3113 * @progress_callback_data: user data to pass to @progress_callback
3114 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
3115 * @user_data: the data to pass to callback function
3117 * Copies the file @source to the location specified by @destination
3118 * asynchronously. For details of the behaviour, see g_file_copy().
3120 * If @progress_callback is not %NULL, then that function that will be called
3121 * just like in g_file_copy(), however the callback will run in the main loop,
3122 * not in the thread that is doing the I/O operation.
3124 * When the operation is finished, @callback will be called. You can then call
3125 * g_file_copy_finish() to get the result of the operation.
3128 g_file_copy_async (GFile *source,
3130 GFileCopyFlags flags,
3132 GCancellable *cancellable,
3133 GFileProgressCallback progress_callback,
3134 gpointer progress_callback_data,
3135 GAsyncReadyCallback callback,
3140 g_return_if_fail (G_IS_FILE (source));
3141 g_return_if_fail (G_IS_FILE (destination));
3143 iface = G_FILE_GET_IFACE (source);
3144 (* iface->copy_async) (source,
3150 progress_callback_data,
3156 * g_file_copy_finish:
3157 * @file: input #GFile.
3158 * @res: a #GAsyncResult.
3159 * @error: a #GError, or %NULL
3161 * Finishes copying the file started with
3162 * g_file_copy_async().
3164 * Returns: a %TRUE on success, %FALSE on error.
3167 g_file_copy_finish (GFile *file,
3173 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3174 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
3176 if (G_IS_SIMPLE_ASYNC_RESULT (res))
3178 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
3180 if (g_simple_async_result_propagate_error (simple, error))
3184 iface = G_FILE_GET_IFACE (file);
3185 return (* iface->copy_finish) (file, res, error);
3190 * @source: #GFile pointing to the source location.
3191 * @destination: #GFile pointing to the destination location.
3192 * @flags: set of #GFileCopyFlags.
3193 * @cancellable: optional #GCancellable object, %NULL to ignore.
3194 * @progress_callback: #GFileProgressCallback function for updates.
3195 * @progress_callback_data: gpointer to user data for the callback function.
3196 * @error: #GError for returning error conditions, or %NULL
3199 * Tries to move the file or directory @source to the location specified by @destination.
3200 * If native move operations are supported then this is used, otherwise a copy + delete
3201 * fallback is used. The native implementation may support moving directories (for instance
3202 * on moves inside the same filesystem), but the fallback code does not.
3204 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
3205 * existing @destination file is overwritten.
3207 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
3208 * will be copied as symlinks, otherwise the target of the
3209 * @source symlink will be copied.
3211 * If @cancellable is not %NULL, then the operation can be cancelled by
3212 * triggering the cancellable object from another thread. If the operation
3213 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3215 * If @progress_callback is not %NULL, then the operation can be monitored by
3216 * setting this to a #GFileProgressCallback function. @progress_callback_data
3217 * will be passed to this function. It is guaranteed that this callback will
3218 * be called after all data has been transferred with the total number of bytes
3219 * copied during the operation.
3221 * If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
3222 * error is returned, independent on the status of the @destination.
3224 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then the
3225 * error G_IO_ERROR_EXISTS is returned.
3227 * If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY
3228 * error is returned. If trying to overwrite a directory with a directory the
3229 * G_IO_ERROR_WOULD_MERGE error is returned.
3231 * If the source is a directory and the target does not exist, or #G_FILE_COPY_OVERWRITE is
3232 * specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error
3233 * may be returned (if the native move operation isn't available).
3235 * Returns: %TRUE on successful move, %FALSE otherwise.
3238 g_file_move (GFile *source,
3240 GFileCopyFlags flags,
3241 GCancellable *cancellable,
3242 GFileProgressCallback progress_callback,
3243 gpointer progress_callback_data,
3250 g_return_val_if_fail (G_IS_FILE (source), FALSE);
3251 g_return_val_if_fail (G_IS_FILE (destination), FALSE);
3253 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3256 iface = G_FILE_GET_IFACE (destination);
3260 res = (* iface->move) (source, destination,
3262 progress_callback, progress_callback_data,
3268 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3270 g_propagate_error (error, my_error);
3275 /* If the types are different, and the destination method failed
3276 also try the source method */
3277 if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
3279 iface = G_FILE_GET_IFACE (source);
3284 res = (* iface->move) (source, destination,
3286 progress_callback, progress_callback_data,
3292 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3294 g_propagate_error (error, my_error);
3300 if (flags & G_FILE_COPY_NO_FALLBACK_FOR_MOVE)
3302 g_set_error_literal (error, G_IO_ERROR,
3303 G_IO_ERROR_NOT_SUPPORTED,
3304 _("Operation not supported"));
3308 flags |= G_FILE_COPY_ALL_METADATA;
3309 if (!g_file_copy (source, destination, flags, cancellable,
3310 progress_callback, progress_callback_data,
3314 return g_file_delete (source, cancellable, error);
3318 * g_file_make_directory
3319 * @file: input #GFile.
3320 * @cancellable: optional #GCancellable object, %NULL to ignore.
3321 * @error: a #GError, or %NULL
3323 * Creates a directory. Note that this will only create a child directory of
3324 * the immediate parent directory of the path or URI given by the #GFile. To
3325 * recursively create directories, see g_file_make_directory_with_parents().
3326 * This function will fail if the parent directory does not exist, setting
3327 * @error to %G_IO_ERROR_NOT_FOUND. If the file system doesn't support creating
3328 * directories, this function will fail, setting @error to
3329 * %G_IO_ERROR_NOT_SUPPORTED.
3331 * For a local #GFile the newly created directory will have the default
3332 * (current) ownership and permissions of the current process.
3334 * If @cancellable is not %NULL, then the operation can be cancelled by
3335 * triggering the cancellable object from another thread. If the operation
3336 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3338 * Returns: %TRUE on successful creation, %FALSE otherwise.
3341 g_file_make_directory (GFile *file,
3342 GCancellable *cancellable,
3347 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3349 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3352 iface = G_FILE_GET_IFACE (file);
3354 if (iface->make_directory == NULL)
3356 g_set_error_literal (error, G_IO_ERROR,
3357 G_IO_ERROR_NOT_SUPPORTED,
3358 _("Operation not supported"));
3362 return (* iface->make_directory) (file, cancellable, error);
3366 * g_file_make_directory_with_parents:
3367 * @file: input #GFile.
3368 * @cancellable: optional #GCancellable object, %NULL to ignore.
3369 * @error: a #GError, or %NULL
3371 * Creates a directory and any parent directories that may not exist similar to
3372 * 'mkdir -p'. If the file system does not support creating directories, this
3373 * function will fail, setting @error to %G_IO_ERROR_NOT_SUPPORTED.
3375 * For a local #GFile the newly created directories will have the default
3376 * (current) ownership and permissions of the current process.
3378 * If @cancellable is not %NULL, then the operation can be cancelled by
3379 * triggering the cancellable object from another thread. If the operation
3380 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3382 * Returns: %TRUE if all directories have been successfully created, %FALSE
3388 g_file_make_directory_with_parents (GFile *file,
3389 GCancellable *cancellable,
3393 GFile *parent_file, *work_file;
3394 GList *list = NULL, *l;
3395 GError *my_error = NULL;
3397 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3400 result = g_file_make_directory (file, cancellable, &my_error);
3401 if (result || my_error->code != G_IO_ERROR_NOT_FOUND)
3404 g_propagate_error (error, my_error);
3410 while (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
3412 g_clear_error (&my_error);
3414 parent_file = g_file_get_parent (work_file);
3415 if (parent_file == NULL)
3417 result = g_file_make_directory (parent_file, cancellable, &my_error);
3419 if (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
3420 list = g_list_prepend (list, parent_file);
3422 work_file = parent_file;
3425 for (l = list; result && l; l = l->next)
3427 result = g_file_make_directory ((GFile *) l->data, cancellable, &my_error);
3431 while (list != NULL)
3433 g_object_unref ((GFile *) list->data);
3434 list = g_list_remove (list, list->data);
3439 g_propagate_error (error, my_error);
3443 return g_file_make_directory (file, cancellable, error);
3447 * g_file_make_symbolic_link:
3448 * @file: input #GFile.
3449 * @symlink_value: a string with the value of the new symlink.
3450 * @cancellable: optional #GCancellable object, %NULL to ignore.
3451 * @error: a #GError.
3453 * Creates a symbolic link.
3455 * If @cancellable is not %NULL, then the operation can be cancelled by
3456 * triggering the cancellable object from another thread. If the operation
3457 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3459 * Returns: %TRUE on the creation of a new symlink, %FALSE otherwise.
3462 g_file_make_symbolic_link (GFile *file,
3463 const char *symlink_value,
3464 GCancellable *cancellable,
3469 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3470 g_return_val_if_fail (symlink_value != NULL, FALSE);
3472 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3475 if (*symlink_value == '\0')
3477 g_set_error_literal (error, G_IO_ERROR,
3478 G_IO_ERROR_INVALID_ARGUMENT,
3479 _("Invalid symlink value given"));
3483 iface = G_FILE_GET_IFACE (file);
3485 if (iface->make_symbolic_link == NULL)
3487 g_set_error_literal (error, G_IO_ERROR,
3488 G_IO_ERROR_NOT_SUPPORTED,
3489 _("Operation not supported"));
3493 return (* iface->make_symbolic_link) (file, symlink_value, cancellable, error);
3498 * @file: input #GFile.
3499 * @cancellable: optional #GCancellable object, %NULL to ignore.
3500 * @error: a #GError, or %NULL
3502 * Deletes a file. If the @file is a directory, it will only be deleted if it
3505 * If @cancellable is not %NULL, then the operation can be cancelled by
3506 * triggering the cancellable object from another thread. If the operation
3507 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3509 * Returns: %TRUE if the file was deleted. %FALSE otherwise.
3512 g_file_delete (GFile *file,
3513 GCancellable *cancellable,
3518 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3520 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3523 iface = G_FILE_GET_IFACE (file);
3525 if (iface->delete_file == NULL)
3527 g_set_error_literal (error, G_IO_ERROR,
3528 G_IO_ERROR_NOT_SUPPORTED,
3529 _("Operation not supported"));
3533 return (* iface->delete_file) (file, cancellable, error);
3538 * @file: #GFile to send to trash.
3539 * @cancellable: optional #GCancellable object, %NULL to ignore.
3540 * @error: a #GError, or %NULL
3542 * Sends @file to the "Trashcan", if possible. This is similar to
3543 * deleting it, but the user can recover it before emptying the trashcan.
3544 * Not all file systems support trashing, so this call can return the
3545 * %G_IO_ERROR_NOT_SUPPORTED error.
3548 * If @cancellable is not %NULL, then the operation can be cancelled by
3549 * triggering the cancellable object from another thread. If the operation
3550 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3552 * Returns: %TRUE on successful trash, %FALSE otherwise.
3555 g_file_trash (GFile *file,
3556 GCancellable *cancellable,
3561 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3563 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3566 iface = G_FILE_GET_IFACE (file);
3568 if (iface->trash == NULL)
3570 g_set_error_literal (error,
3571 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
3572 _("Trash not supported"));
3576 return (* iface->trash) (file, cancellable, error);
3580 * g_file_set_display_name:
3581 * @file: input #GFile.
3582 * @display_name: a string.
3583 * @cancellable: optional #GCancellable object, %NULL to ignore.
3584 * @error: a #GError, or %NULL
3586 * Renames @file to the specified display name.
3588 * The display name is converted from UTF8 to the correct encoding for the target
3589 * filesystem if possible and the @file is renamed to this.
3591 * If you want to implement a rename operation in the user interface the edit name
3592 * (#G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the initial value in the rename
3593 * widget, and then the result after editing should be passed to g_file_set_display_name().
3595 * On success the resulting converted filename is returned.
3597 * If @cancellable is not %NULL, then the operation can be cancelled by
3598 * triggering the cancellable object from another thread. If the operation
3599 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3601 * Returns: a #GFile specifying what @file was renamed to, or %NULL
3602 * if there was an error.
3603 * Free the returned object with g_object_unref().
3606 g_file_set_display_name (GFile *file,
3607 const char *display_name,
3608 GCancellable *cancellable,
3613 g_return_val_if_fail (G_IS_FILE (file), NULL);
3614 g_return_val_if_fail (display_name != NULL, NULL);
3616 if (strchr (display_name, G_DIR_SEPARATOR) != NULL)
3620 G_IO_ERROR_INVALID_ARGUMENT,
3621 _("File names cannot contain '%c'"), G_DIR_SEPARATOR);
3625 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3628 iface = G_FILE_GET_IFACE (file);
3630 return (* iface->set_display_name) (file, display_name, cancellable, error);
3634 * g_file_set_display_name_async:
3635 * @file: input #GFile.
3636 * @display_name: a string.
3637 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3639 * @cancellable: optional #GCancellable object, %NULL to ignore.
3640 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
3641 * @user_data: the data to pass to callback function
3643 * Asynchronously sets the display name for a given #GFile.
3645 * For more details, see g_file_set_display_name() which is
3646 * the synchronous version of this call.
3648 * When the operation is finished, @callback will be called. You can then call
3649 * g_file_set_display_name_finish() to get the result of the operation.
3652 g_file_set_display_name_async (GFile *file,
3653 const char *display_name,
3655 GCancellable *cancellable,
3656 GAsyncReadyCallback callback,
3661 g_return_if_fail (G_IS_FILE (file));
3662 g_return_if_fail (display_name != NULL);
3664 iface = G_FILE_GET_IFACE (file);
3665 (* iface->set_display_name_async) (file,
3674 * g_file_set_display_name_finish:
3675 * @file: input #GFile.
3676 * @res: a #GAsyncResult.
3677 * @error: a #GError, or %NULL
3679 * Finishes setting a display name started with
3680 * g_file_set_display_name_async().
3682 * Returns: a #GFile or %NULL on error.
3683 * Free the returned object with g_object_unref().
3686 g_file_set_display_name_finish (GFile *file,
3692 g_return_val_if_fail (G_IS_FILE (file), NULL);
3693 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
3695 if (G_IS_SIMPLE_ASYNC_RESULT (res))
3697 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
3698 if (g_simple_async_result_propagate_error (simple, error))
3702 iface = G_FILE_GET_IFACE (file);
3703 return (* iface->set_display_name_finish) (file, res, error);
3707 * g_file_query_settable_attributes:
3708 * @file: input #GFile.
3709 * @cancellable: optional #GCancellable object, %NULL to ignore.
3710 * @error: a #GError, or %NULL
3712 * Obtain the list of settable attributes for the file.
3714 * Returns the type and full attribute name of all the attributes
3715 * that can be set on this file. This doesn't mean setting it will always
3716 * succeed though, you might get an access failure, or some specific
3717 * file may not support a specific attribute.
3719 * If @cancellable is not %NULL, then the operation can be cancelled by
3720 * triggering the cancellable object from another thread. If the operation
3721 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3723 * Returns: a #GFileAttributeInfoList describing the settable attributes.
3724 * When you are done with it, release it with g_file_attribute_info_list_unref()
3726 GFileAttributeInfoList *
3727 g_file_query_settable_attributes (GFile *file,
3728 GCancellable *cancellable,
3733 GFileAttributeInfoList *list;
3735 g_return_val_if_fail (G_IS_FILE (file), NULL);
3737 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3740 iface = G_FILE_GET_IFACE (file);
3742 if (iface->query_settable_attributes == NULL)
3743 return g_file_attribute_info_list_new ();
3746 list = (* iface->query_settable_attributes) (file, cancellable, &my_error);
3750 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
3752 list = g_file_attribute_info_list_new ();
3753 g_error_free (my_error);
3756 g_propagate_error (error, my_error);
3763 * g_file_query_writable_namespaces:
3764 * @file: input #GFile.
3765 * @cancellable: optional #GCancellable object, %NULL to ignore.
3766 * @error: a #GError, or %NULL
3768 * Obtain the list of attribute namespaces where new attributes
3769 * can be created by a user. An example of this is extended
3770 * attributes (in the "xattr" namespace).
3772 * If @cancellable is not %NULL, then the operation can be cancelled by
3773 * triggering the cancellable object from another thread. If the operation
3774 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3776 * Returns: a #GFileAttributeInfoList describing the writable namespaces.
3777 * When you are done with it, release it with g_file_attribute_info_list_unref()
3779 GFileAttributeInfoList *
3780 g_file_query_writable_namespaces (GFile *file,
3781 GCancellable *cancellable,
3786 GFileAttributeInfoList *list;
3788 g_return_val_if_fail (G_IS_FILE (file), NULL);
3790 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3793 iface = G_FILE_GET_IFACE (file);
3795 if (iface->query_writable_namespaces == NULL)
3796 return g_file_attribute_info_list_new ();
3799 list = (* iface->query_writable_namespaces) (file, cancellable, &my_error);
3803 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
3805 list = g_file_attribute_info_list_new ();
3806 g_error_free (my_error);
3809 g_propagate_error (error, my_error);
3816 * g_file_set_attribute:
3817 * @file: input #GFile.
3818 * @attribute: a string containing the attribute's name.
3819 * @type: The type of the attribute
3820 * @value_p: a pointer to the value (or the pointer itself if the type is a pointer type)
3821 * @flags: a set of #GFileQueryInfoFlags.
3822 * @cancellable: optional #GCancellable object, %NULL to ignore.
3823 * @error: a #GError, or %NULL
3825 * Sets an attribute in the file with attribute name @attribute to @value.
3827 * If @cancellable is not %NULL, then the operation can be cancelled by
3828 * triggering the cancellable object from another thread. If the operation
3829 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3831 * Returns: %TRUE if the attribute was set, %FALSE otherwise.
3834 g_file_set_attribute (GFile *file,
3835 const char *attribute,
3836 GFileAttributeType type,
3838 GFileQueryInfoFlags flags,
3839 GCancellable *cancellable,
3844 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3845 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
3847 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3850 iface = G_FILE_GET_IFACE (file);
3852 if (iface->set_attribute == NULL)
3854 g_set_error_literal (error, G_IO_ERROR,
3855 G_IO_ERROR_NOT_SUPPORTED,
3856 _("Operation not supported"));
3860 return (* iface->set_attribute) (file, attribute, type, value_p, flags, cancellable, error);
3864 * g_file_set_attributes_from_info:
3865 * @file: input #GFile.
3866 * @info: a #GFileInfo.
3867 * @flags: #GFileQueryInfoFlags
3868 * @cancellable: optional #GCancellable object, %NULL to ignore.
3869 * @error: a #GError, or %NULL
3871 * Tries to set all attributes in the #GFileInfo on the target values,
3872 * not stopping on the first error.
3874 * If there is any error during this operation then @error will be set to
3875 * the first error. Error on particular fields are flagged by setting
3876 * the "status" field in the attribute value to
3877 * %G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can also detect
3880 * If @cancellable is not %NULL, then the operation can be cancelled by
3881 * triggering the cancellable object from another thread. If the operation
3882 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3884 * Returns: %TRUE if there was any error, %FALSE otherwise.
3887 g_file_set_attributes_from_info (GFile *file,
3889 GFileQueryInfoFlags flags,
3890 GCancellable *cancellable,
3895 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3896 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
3898 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3901 g_file_info_clear_status (info);
3903 iface = G_FILE_GET_IFACE (file);
3905 return (* iface->set_attributes_from_info) (file,
3914 g_file_real_set_attributes_from_info (GFile *file,
3916 GFileQueryInfoFlags flags,
3917 GCancellable *cancellable,
3923 GFileAttributeValue *value;
3927 attributes = g_file_info_list_attributes (info, NULL);
3929 for (i = 0; attributes[i] != NULL; i++)
3931 value = _g_file_info_get_attribute_value (info, attributes[i]);
3933 if (value->status != G_FILE_ATTRIBUTE_STATUS_UNSET)
3936 if (!g_file_set_attribute (file, attributes[i],
3937 value->type, _g_file_attribute_value_peek_as_pointer (value),
3938 flags, cancellable, error))
3940 value->status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
3942 /* Don't set error multiple times */
3946 value->status = G_FILE_ATTRIBUTE_STATUS_SET;
3949 g_strfreev (attributes);
3955 * g_file_set_attributes_async:
3956 * @file: input #GFile.
3957 * @info: a #GFileInfo.
3958 * @flags: a #GFileQueryInfoFlags.
3959 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3961 * @cancellable: optional #GCancellable object, %NULL to ignore.
3962 * @callback: a #GAsyncReadyCallback.
3963 * @user_data: a #gpointer.
3965 * Asynchronously sets the attributes of @file with @info.
3967 * For more details, see g_file_set_attributes_from_info() which is
3968 * the synchronous version of this call.
3970 * When the operation is finished, @callback will be called. You can then call
3971 * g_file_set_attributes_finish() to get the result of the operation.
3974 g_file_set_attributes_async (GFile *file,
3976 GFileQueryInfoFlags flags,
3978 GCancellable *cancellable,
3979 GAsyncReadyCallback callback,
3984 g_return_if_fail (G_IS_FILE (file));
3985 g_return_if_fail (G_IS_FILE_INFO (info));
3987 iface = G_FILE_GET_IFACE (file);
3988 (* iface->set_attributes_async) (file,
3998 * g_file_set_attributes_finish:
3999 * @file: input #GFile.
4000 * @result: a #GAsyncResult.
4001 * @info: a #GFileInfo.
4002 * @error: a #GError, or %NULL
4004 * Finishes setting an attribute started in g_file_set_attributes_async().
4006 * Returns: %TRUE if the attributes were set correctly, %FALSE otherwise.
4009 g_file_set_attributes_finish (GFile *file,
4010 GAsyncResult *result,
4016 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4017 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4019 /* No standard handling of errors here, as we must set info even
4022 iface = G_FILE_GET_IFACE (file);
4023 return (* iface->set_attributes_finish) (file, result, info, error);
4027 * g_file_set_attribute_string:
4028 * @file: input #GFile.
4029 * @attribute: a string containing the attribute's name.
4030 * @value: a string containing the attribute's value.
4031 * @flags: #GFileQueryInfoFlags.
4032 * @cancellable: optional #GCancellable object, %NULL to ignore.
4033 * @error: a #GError, or %NULL
4035 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value.
4036 * If @attribute is of a different type, this operation will fail.
4038 * If @cancellable is not %NULL, then the operation can be cancelled by
4039 * triggering the cancellable object from another thread. If the operation
4040 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4042 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
4045 g_file_set_attribute_string (GFile *file,
4046 const char *attribute,
4048 GFileQueryInfoFlags flags,
4049 GCancellable *cancellable,
4052 return g_file_set_attribute (file, attribute,
4053 G_FILE_ATTRIBUTE_TYPE_STRING, (gpointer)value,
4054 flags, cancellable, error);
4058 * g_file_set_attribute_byte_string:
4059 * @file: input #GFile.
4060 * @attribute: a string containing the attribute's name.
4061 * @value: a string containing the attribute's new value.
4062 * @flags: a #GFileQueryInfoFlags.
4063 * @cancellable: optional #GCancellable object, %NULL to ignore.
4064 * @error: a #GError, or %NULL
4066 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value.
4067 * If @attribute is of a different type, this operation will fail,
4070 * If @cancellable is not %NULL, then the operation can be cancelled by
4071 * triggering the cancellable object from another thread. If the operation
4072 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4074 * Returns: %TRUE if the @attribute was successfully set to @value
4075 * in the @file, %FALSE otherwise.
4078 g_file_set_attribute_byte_string (GFile *file,
4079 const char *attribute,
4081 GFileQueryInfoFlags flags,
4082 GCancellable *cancellable,
4085 return g_file_set_attribute (file, attribute,
4086 G_FILE_ATTRIBUTE_TYPE_BYTE_STRING, (gpointer)value,
4087 flags, cancellable, error);
4091 * g_file_set_attribute_uint32:
4092 * @file: input #GFile.
4093 * @attribute: a string containing the attribute's name.
4094 * @value: a #guint32 containing the attribute's new value.
4095 * @flags: a #GFileQueryInfoFlags.
4096 * @cancellable: optional #GCancellable object, %NULL to ignore.
4097 * @error: a #GError, or %NULL
4099 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value.
4100 * If @attribute is of a different type, this operation will fail.
4102 * If @cancellable is not %NULL, then the operation can be cancelled by
4103 * triggering the cancellable object from another thread. If the operation
4104 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4106 * Returns: %TRUE if the @attribute was successfully set to @value
4107 * in the @file, %FALSE otherwise.
4110 g_file_set_attribute_uint32 (GFile *file,
4111 const char *attribute,
4113 GFileQueryInfoFlags flags,
4114 GCancellable *cancellable,
4117 return g_file_set_attribute (file, attribute,
4118 G_FILE_ATTRIBUTE_TYPE_UINT32, &value,
4119 flags, cancellable, error);
4123 * g_file_set_attribute_int32:
4124 * @file: input #GFile.
4125 * @attribute: a string containing the attribute's name.
4126 * @value: a #gint32 containing the attribute's new value.
4127 * @flags: a #GFileQueryInfoFlags.
4128 * @cancellable: optional #GCancellable object, %NULL to ignore.
4129 * @error: a #GError, or %NULL
4131 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value.
4132 * If @attribute is of a different type, this operation will fail.
4134 * If @cancellable is not %NULL, then the operation can be cancelled by
4135 * triggering the cancellable object from another thread. If the operation
4136 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4138 * Returns: %TRUE if the @attribute was successfully set to @value
4139 * in the @file, %FALSE otherwise.
4142 g_file_set_attribute_int32 (GFile *file,
4143 const char *attribute,
4145 GFileQueryInfoFlags flags,
4146 GCancellable *cancellable,
4149 return g_file_set_attribute (file, attribute,
4150 G_FILE_ATTRIBUTE_TYPE_INT32, &value,
4151 flags, cancellable, error);
4155 * g_file_set_attribute_uint64:
4156 * @file: input #GFile.
4157 * @attribute: a string containing the attribute's name.
4158 * @value: a #guint64 containing the attribute's new value.
4159 * @flags: a #GFileQueryInfoFlags.
4160 * @cancellable: optional #GCancellable object, %NULL to ignore.
4161 * @error: a #GError, or %NULL
4163 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value.
4164 * If @attribute is of a different type, this operation will fail.
4166 * If @cancellable is not %NULL, then the operation can be cancelled by
4167 * triggering the cancellable object from another thread. If the operation
4168 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4170 * Returns: %TRUE if the @attribute was successfully set to @value
4171 * in the @file, %FALSE otherwise.
4174 g_file_set_attribute_uint64 (GFile *file,
4175 const char *attribute,
4177 GFileQueryInfoFlags flags,
4178 GCancellable *cancellable,
4181 return g_file_set_attribute (file, attribute,
4182 G_FILE_ATTRIBUTE_TYPE_UINT64, &value,
4183 flags, cancellable, error);
4187 * g_file_set_attribute_int64:
4188 * @file: input #GFile.
4189 * @attribute: a string containing the attribute's name.
4190 * @value: a #guint64 containing the attribute's new value.
4191 * @flags: a #GFileQueryInfoFlags.
4192 * @cancellable: optional #GCancellable object, %NULL to ignore.
4193 * @error: a #GError, or %NULL
4195 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value.
4196 * If @attribute is of a different type, this operation will fail.
4198 * If @cancellable is not %NULL, then the operation can be cancelled by
4199 * triggering the cancellable object from another thread. If the operation
4200 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4202 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
4205 g_file_set_attribute_int64 (GFile *file,
4206 const char *attribute,
4208 GFileQueryInfoFlags flags,
4209 GCancellable *cancellable,
4212 return g_file_set_attribute (file, attribute,
4213 G_FILE_ATTRIBUTE_TYPE_INT64, &value,
4214 flags, cancellable, error);
4218 * g_file_mount_mountable:
4219 * @file: input #GFile.
4220 * @flags: flags affecting the operation
4221 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
4222 * @cancellable: optional #GCancellable object, %NULL to ignore.
4223 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4224 * @user_data: the data to pass to callback function
4226 * Mounts a file of type G_FILE_TYPE_MOUNTABLE.
4227 * Using @mount_operation, you can request callbacks when, for instance,
4228 * passwords are needed during authentication.
4230 * If @cancellable is not %NULL, then the operation can be cancelled by
4231 * triggering the cancellable object from another thread. If the operation
4232 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4234 * When the operation is finished, @callback will be called. You can then call
4235 * g_file_mount_mountable_finish() to get the result of the operation.
4238 g_file_mount_mountable (GFile *file,
4239 GMountMountFlags flags,
4240 GMountOperation *mount_operation,
4241 GCancellable *cancellable,
4242 GAsyncReadyCallback callback,
4247 g_return_if_fail (G_IS_FILE (file));
4249 iface = G_FILE_GET_IFACE (file);
4251 if (iface->mount_mountable == NULL)
4253 g_simple_async_report_error_in_idle (G_OBJECT (file),
4257 G_IO_ERROR_NOT_SUPPORTED,
4258 _("Operation not supported"));
4262 (* iface->mount_mountable) (file,
4271 * g_file_mount_mountable_finish:
4272 * @file: input #GFile.
4273 * @result: a #GAsyncResult.
4274 * @error: a #GError, or %NULL
4276 * Finishes a mount operation. See g_file_mount_mountable() for details.
4278 * Finish an asynchronous mount operation that was started
4279 * with g_file_mount_mountable().
4281 * Returns: a #GFile or %NULL on error.
4282 * Free the returned object with g_object_unref().
4285 g_file_mount_mountable_finish (GFile *file,
4286 GAsyncResult *result,
4291 g_return_val_if_fail (G_IS_FILE (file), NULL);
4292 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
4294 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4296 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4297 if (g_simple_async_result_propagate_error (simple, error))
4301 iface = G_FILE_GET_IFACE (file);
4302 return (* iface->mount_mountable_finish) (file, result, error);
4306 * g_file_unmount_mountable:
4307 * @file: input #GFile.
4308 * @flags: flags affecting the operation
4309 * @cancellable: optional #GCancellable object, %NULL to ignore.
4310 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4311 * @user_data: the data to pass to callback function
4313 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
4315 * If @cancellable is not %NULL, then the operation can be cancelled by
4316 * triggering the cancellable object from another thread. If the operation
4317 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4319 * When the operation is finished, @callback will be called. You can then call
4320 * g_file_unmount_mountable_finish() to get the result of the operation.
4322 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation() instead.
4325 g_file_unmount_mountable (GFile *file,
4326 GMountUnmountFlags flags,
4327 GCancellable *cancellable,
4328 GAsyncReadyCallback callback,
4333 g_return_if_fail (G_IS_FILE (file));
4335 iface = G_FILE_GET_IFACE (file);
4337 if (iface->unmount_mountable == NULL)
4339 g_simple_async_report_error_in_idle (G_OBJECT (file),
4343 G_IO_ERROR_NOT_SUPPORTED,
4344 _("Operation not supported"));
4348 (* iface->unmount_mountable) (file,
4356 * g_file_unmount_mountable_finish:
4357 * @file: input #GFile.
4358 * @result: a #GAsyncResult.
4359 * @error: a #GError, or %NULL
4361 * Finishes an unmount operation, see g_file_unmount_mountable() for details.
4363 * Finish an asynchronous unmount operation that was started
4364 * with g_file_unmount_mountable().
4366 * Returns: %TRUE if the operation finished successfully. %FALSE
4369 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation_finish() instead.
4372 g_file_unmount_mountable_finish (GFile *file,
4373 GAsyncResult *result,
4378 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4379 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4381 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4383 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4384 if (g_simple_async_result_propagate_error (simple, error))
4388 iface = G_FILE_GET_IFACE (file);
4389 return (* iface->unmount_mountable_finish) (file, result, error);
4393 * g_file_unmount_mountable_with_operation:
4394 * @file: input #GFile.
4395 * @flags: flags affecting the operation
4396 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
4397 * @cancellable: optional #GCancellable object, %NULL to ignore.
4398 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4399 * @user_data: the data to pass to callback function
4401 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
4403 * If @cancellable is not %NULL, then the operation can be cancelled by
4404 * triggering the cancellable object from another thread. If the operation
4405 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4407 * When the operation is finished, @callback will be called. You can then call
4408 * g_file_unmount_mountable_finish() to get the result of the operation.
4413 g_file_unmount_mountable_with_operation (GFile *file,
4414 GMountUnmountFlags flags,
4415 GMountOperation *mount_operation,
4416 GCancellable *cancellable,
4417 GAsyncReadyCallback callback,
4422 g_return_if_fail (G_IS_FILE (file));
4424 iface = G_FILE_GET_IFACE (file);
4426 if (iface->unmount_mountable == NULL && iface->unmount_mountable_with_operation == NULL)
4428 g_simple_async_report_error_in_idle (G_OBJECT (file),
4432 G_IO_ERROR_NOT_SUPPORTED,
4433 _("Operation not supported"));
4437 if (iface->unmount_mountable_with_operation != NULL)
4438 (* iface->unmount_mountable_with_operation) (file,
4445 (* iface->unmount_mountable) (file,
4453 * g_file_unmount_mountable_with_operation_finish:
4454 * @file: input #GFile.
4455 * @result: a #GAsyncResult.
4456 * @error: a #GError, or %NULL
4458 * Finishes an unmount operation, see g_file_unmount_mountable_with_operation() for details.
4460 * Finish an asynchronous unmount operation that was started
4461 * with g_file_unmount_mountable_with_operation().
4463 * Returns: %TRUE if the operation finished successfully. %FALSE
4469 g_file_unmount_mountable_with_operation_finish (GFile *file,
4470 GAsyncResult *result,
4475 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4476 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4478 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4480 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4481 if (g_simple_async_result_propagate_error (simple, error))
4485 iface = G_FILE_GET_IFACE (file);
4486 if (iface->unmount_mountable_with_operation_finish != NULL)
4487 return (* iface->unmount_mountable_with_operation_finish) (file, result, error);
4489 return (* iface->unmount_mountable_finish) (file, result, error);
4493 * g_file_eject_mountable:
4494 * @file: input #GFile.
4495 * @flags: flags affecting the operation
4496 * @cancellable: optional #GCancellable object, %NULL to ignore.
4497 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4498 * @user_data: the data to pass to callback function
4500 * Starts an asynchronous eject on a mountable.
4501 * When this operation has completed, @callback will be called with
4502 * @user_user data, and the operation can be finalized with
4503 * g_file_eject_mountable_finish().
4505 * If @cancellable is not %NULL, then the operation can be cancelled by
4506 * triggering the cancellable object from another thread. If the operation
4507 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4509 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation() instead.
4512 g_file_eject_mountable (GFile *file,
4513 GMountUnmountFlags flags,
4514 GCancellable *cancellable,
4515 GAsyncReadyCallback callback,
4520 g_return_if_fail (G_IS_FILE (file));
4522 iface = G_FILE_GET_IFACE (file);
4524 if (iface->eject_mountable == NULL)
4526 g_simple_async_report_error_in_idle (G_OBJECT (file),
4530 G_IO_ERROR_NOT_SUPPORTED,
4531 _("Operation not supported"));
4535 (* iface->eject_mountable) (file,
4543 * g_file_eject_mountable_finish:
4544 * @file: input #GFile.
4545 * @result: a #GAsyncResult.
4546 * @error: a #GError, or %NULL
4548 * Finishes an asynchronous eject operation started by
4549 * g_file_eject_mountable().
4551 * Returns: %TRUE if the @file was ejected successfully. %FALSE
4554 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation_finish() instead.
4557 g_file_eject_mountable_finish (GFile *file,
4558 GAsyncResult *result,
4563 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4564 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4566 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4568 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4569 if (g_simple_async_result_propagate_error (simple, error))
4573 iface = G_FILE_GET_IFACE (file);
4574 return (* iface->eject_mountable_finish) (file, result, error);
4578 * g_file_eject_mountable_with_operation:
4579 * @file: input #GFile.
4580 * @flags: flags affecting the operation
4581 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
4582 * @cancellable: optional #GCancellable object, %NULL to ignore.
4583 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4584 * @user_data: the data to pass to callback function
4586 * Starts an asynchronous eject on a mountable.
4587 * When this operation has completed, @callback will be called with
4588 * @user_user data, and the operation can be finalized with
4589 * g_file_eject_mountable_with_operation_finish().
4591 * If @cancellable is not %NULL, then the operation can be cancelled by
4592 * triggering the cancellable object from another thread. If the operation
4593 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4598 g_file_eject_mountable_with_operation (GFile *file,
4599 GMountUnmountFlags flags,
4600 GMountOperation *mount_operation,
4601 GCancellable *cancellable,
4602 GAsyncReadyCallback callback,
4607 g_return_if_fail (G_IS_FILE (file));
4609 iface = G_FILE_GET_IFACE (file);
4611 if (iface->eject_mountable == NULL && iface->eject_mountable_with_operation == NULL)
4613 g_simple_async_report_error_in_idle (G_OBJECT (file),
4617 G_IO_ERROR_NOT_SUPPORTED,
4618 _("Operation not supported"));
4622 if (iface->eject_mountable_with_operation != NULL)
4623 (* iface->eject_mountable_with_operation) (file,
4630 (* iface->eject_mountable) (file,
4638 * g_file_eject_mountable_with_operation_finish:
4639 * @file: input #GFile.
4640 * @result: a #GAsyncResult.
4641 * @error: a #GError, or %NULL
4643 * Finishes an asynchronous eject operation started by
4644 * g_file_eject_mountable_with_operation().
4646 * Returns: %TRUE if the @file was ejected successfully. %FALSE
4652 g_file_eject_mountable_with_operation_finish (GFile *file,
4653 GAsyncResult *result,
4658 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4659 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4661 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4663 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4664 if (g_simple_async_result_propagate_error (simple, error))
4668 iface = G_FILE_GET_IFACE (file);
4669 if (iface->eject_mountable_with_operation_finish != NULL)
4670 return (* iface->eject_mountable_with_operation_finish) (file, result, error);
4672 return (* iface->eject_mountable_finish) (file, result, error);
4676 * g_file_monitor_directory:
4677 * @file: input #GFile.
4678 * @flags: a set of #GFileMonitorFlags.
4679 * @cancellable: optional #GCancellable object, %NULL to ignore.
4680 * @error: a #GError, or %NULL.
4682 * Obtains a directory monitor for the given file.
4683 * This may fail if directory monitoring is not supported.
4685 * If @cancellable is not %NULL, then the operation can be cancelled by
4686 * triggering the cancellable object from another thread. If the operation
4687 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4689 * Returns: a #GFileMonitor for the given @file, or %NULL on error.
4690 * Free the returned object with g_object_unref().
4693 g_file_monitor_directory (GFile *file,
4694 GFileMonitorFlags flags,
4695 GCancellable *cancellable,
4700 g_return_val_if_fail (G_IS_FILE (file), NULL);
4702 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4705 iface = G_FILE_GET_IFACE (file);
4707 if (iface->monitor_dir == NULL)
4709 g_set_error_literal (error, G_IO_ERROR,
4710 G_IO_ERROR_NOT_SUPPORTED,
4711 _("Operation not supported"));
4715 return (* iface->monitor_dir) (file, flags, cancellable, error);
4719 * g_file_monitor_file:
4720 * @file: input #GFile.
4721 * @flags: a set of #GFileMonitorFlags.
4722 * @cancellable: optional #GCancellable object, %NULL to ignore.
4723 * @error: a #GError, or %NULL.
4725 * Obtains a file monitor for the given file. If no file notification
4726 * mechanism exists, then regular polling of the file is used.
4728 * If @cancellable is not %NULL, then the operation can be cancelled by
4729 * triggering the cancellable object from another thread. If the operation
4730 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4732 * Returns: a #GFileMonitor for the given @file, or %NULL on error.
4733 * Free the returned object with g_object_unref().
4736 g_file_monitor_file (GFile *file,
4737 GFileMonitorFlags flags,
4738 GCancellable *cancellable,
4742 GFileMonitor *monitor;
4744 g_return_val_if_fail (G_IS_FILE (file), NULL);
4746 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4749 iface = G_FILE_GET_IFACE (file);
4753 if (iface->monitor_file)
4754 monitor = (* iface->monitor_file) (file, flags, cancellable, NULL);
4756 /* Fallback to polling */
4757 if (monitor == NULL)
4758 monitor = _g_poll_file_monitor_new (file);
4765 * @file: input #GFile
4766 * @flags: a set of #GFileMonitorFlags
4767 * @cancellable: optional #GCancellable object, %NULL to ignore
4768 * @error: a #GError, or %NULL
4770 * Obtains a file or directory monitor for the given file, depending
4771 * on the type of the file.
4773 * If @cancellable is not %NULL, then the operation can be cancelled by
4774 * triggering the cancellable object from another thread. If the operation
4775 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4777 * Returns: a #GFileMonitor for the given @file, or %NULL on error.
4778 * Free the returned object with g_object_unref().
4783 g_file_monitor (GFile *file,
4784 GFileMonitorFlags flags,
4785 GCancellable *cancellable,
4788 if (g_file_query_file_type (file, 0, cancellable) == G_FILE_TYPE_DIRECTORY)
4789 return g_file_monitor_directory (file, flags, cancellable, error);
4791 return g_file_monitor_file (file, flags, cancellable, error);
4794 /********************************************
4795 * Default implementation of async ops *
4796 ********************************************/
4800 GFileQueryInfoFlags flags;
4802 } QueryInfoAsyncData;
4805 query_info_data_free (QueryInfoAsyncData *data)
4808 g_object_unref (data->info);
4809 g_free (data->attributes);
4814 query_info_async_thread (GSimpleAsyncResult *res,
4816 GCancellable *cancellable)
4818 GError *error = NULL;
4819 QueryInfoAsyncData *data;
4822 data = g_simple_async_result_get_op_res_gpointer (res);
4824 info = g_file_query_info (G_FILE (object), data->attributes, data->flags, cancellable, &error);
4828 g_simple_async_result_set_from_error (res, error);
4829 g_error_free (error);
4836 g_file_real_query_info_async (GFile *file,
4837 const char *attributes,
4838 GFileQueryInfoFlags flags,
4840 GCancellable *cancellable,
4841 GAsyncReadyCallback callback,
4844 GSimpleAsyncResult *res;
4845 QueryInfoAsyncData *data;
4847 data = g_new0 (QueryInfoAsyncData, 1);
4848 data->attributes = g_strdup (attributes);
4849 data->flags = flags;
4851 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_query_info_async);
4852 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_info_data_free);
4854 g_simple_async_result_run_in_thread (res, query_info_async_thread, io_priority, cancellable);
4855 g_object_unref (res);
4859 g_file_real_query_info_finish (GFile *file,
4863 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4864 QueryInfoAsyncData *data;
4866 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_info_async);
4868 data = g_simple_async_result_get_op_res_gpointer (simple);
4870 return g_object_ref (data->info);
4878 } QueryFilesystemInfoAsyncData;
4881 query_filesystem_info_data_free (QueryFilesystemInfoAsyncData *data)
4884 g_object_unref (data->info);
4885 g_free (data->attributes);
4890 query_filesystem_info_async_thread (GSimpleAsyncResult *res,
4892 GCancellable *cancellable)
4894 GError *error = NULL;
4895 QueryFilesystemInfoAsyncData *data;
4898 data = g_simple_async_result_get_op_res_gpointer (res);
4900 info = g_file_query_filesystem_info (G_FILE (object), data->attributes, cancellable, &error);
4904 g_simple_async_result_set_from_error (res, error);
4905 g_error_free (error);
4912 g_file_real_query_filesystem_info_async (GFile *file,
4913 const char *attributes,
4915 GCancellable *cancellable,
4916 GAsyncReadyCallback callback,
4919 GSimpleAsyncResult *res;
4920 QueryFilesystemInfoAsyncData *data;
4922 data = g_new0 (QueryFilesystemInfoAsyncData, 1);
4923 data->attributes = g_strdup (attributes);
4925 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_query_filesystem_info_async);
4926 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_filesystem_info_data_free);
4928 g_simple_async_result_run_in_thread (res, query_filesystem_info_async_thread, io_priority, cancellable);
4929 g_object_unref (res);
4933 g_file_real_query_filesystem_info_finish (GFile *file,
4937 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4938 QueryFilesystemInfoAsyncData *data;
4940 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_filesystem_info_async);
4942 data = g_simple_async_result_get_op_res_gpointer (simple);
4944 return g_object_ref (data->info);
4951 GFileQueryInfoFlags flags;
4952 GFileEnumerator *enumerator;
4953 } EnumerateChildrenAsyncData;
4956 enumerate_children_data_free (EnumerateChildrenAsyncData *data)
4958 if (data->enumerator)
4959 g_object_unref (data->enumerator);
4960 g_free (data->attributes);
4965 enumerate_children_async_thread (GSimpleAsyncResult *res,
4967 GCancellable *cancellable)
4969 GError *error = NULL;
4970 EnumerateChildrenAsyncData *data;
4971 GFileEnumerator *enumerator;
4973 data = g_simple_async_result_get_op_res_gpointer (res);
4975 enumerator = g_file_enumerate_children (G_FILE (object), data->attributes, data->flags, cancellable, &error);
4977 if (enumerator == NULL)
4979 g_simple_async_result_set_from_error (res, error);
4980 g_error_free (error);
4983 data->enumerator = enumerator;
4987 g_file_real_enumerate_children_async (GFile *file,
4988 const char *attributes,
4989 GFileQueryInfoFlags flags,
4991 GCancellable *cancellable,
4992 GAsyncReadyCallback callback,
4995 GSimpleAsyncResult *res;
4996 EnumerateChildrenAsyncData *data;
4998 data = g_new0 (EnumerateChildrenAsyncData, 1);
4999 data->attributes = g_strdup (attributes);
5000 data->flags = flags;
5002 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_enumerate_children_async);
5003 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)enumerate_children_data_free);
5005 g_simple_async_result_run_in_thread (res, enumerate_children_async_thread, io_priority, cancellable);
5006 g_object_unref (res);
5009 static GFileEnumerator *
5010 g_file_real_enumerate_children_finish (GFile *file,
5014 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5015 EnumerateChildrenAsyncData *data;
5017 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_enumerate_children_async);
5019 data = g_simple_async_result_get_op_res_gpointer (simple);
5020 if (data->enumerator)
5021 return g_object_ref (data->enumerator);
5027 open_read_async_thread (GSimpleAsyncResult *res,
5029 GCancellable *cancellable)
5032 GFileInputStream *stream;
5033 GError *error = NULL;
5035 iface = G_FILE_GET_IFACE (object);
5037 if (iface->read_fn == NULL)
5039 g_set_error_literal (&error, G_IO_ERROR,
5040 G_IO_ERROR_NOT_SUPPORTED,
5041 _("Operation not supported"));
5043 g_simple_async_result_set_from_error (res, error);
5044 g_error_free (error);
5049 stream = iface->read_fn (G_FILE (object), cancellable, &error);
5053 g_simple_async_result_set_from_error (res, error);
5054 g_error_free (error);
5057 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5061 g_file_real_read_async (GFile *file,
5063 GCancellable *cancellable,
5064 GAsyncReadyCallback callback,
5067 GSimpleAsyncResult *res;
5069 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_read_async);
5071 g_simple_async_result_run_in_thread (res, open_read_async_thread, io_priority, cancellable);
5072 g_object_unref (res);
5075 static GFileInputStream *
5076 g_file_real_read_finish (GFile *file,
5080 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5083 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_read_async);
5085 op = g_simple_async_result_get_op_res_gpointer (simple);
5087 return g_object_ref (op);
5093 append_to_async_thread (GSimpleAsyncResult *res,
5095 GCancellable *cancellable)
5098 GFileCreateFlags *data;
5099 GFileOutputStream *stream;
5100 GError *error = NULL;
5102 iface = G_FILE_GET_IFACE (object);
5104 data = g_simple_async_result_get_op_res_gpointer (res);
5106 stream = iface->append_to (G_FILE (object), *data, cancellable, &error);
5110 g_simple_async_result_set_from_error (res, error);
5111 g_error_free (error);
5114 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5118 g_file_real_append_to_async (GFile *file,
5119 GFileCreateFlags flags,
5121 GCancellable *cancellable,
5122 GAsyncReadyCallback callback,
5125 GFileCreateFlags *data;
5126 GSimpleAsyncResult *res;
5128 data = g_new0 (GFileCreateFlags, 1);
5131 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_append_to_async);
5132 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
5134 g_simple_async_result_run_in_thread (res, append_to_async_thread, io_priority, cancellable);
5135 g_object_unref (res);
5138 static GFileOutputStream *
5139 g_file_real_append_to_finish (GFile *file,
5143 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5146 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_append_to_async);
5148 op = g_simple_async_result_get_op_res_gpointer (simple);
5150 return g_object_ref (op);
5156 create_async_thread (GSimpleAsyncResult *res,
5158 GCancellable *cancellable)
5161 GFileCreateFlags *data;
5162 GFileOutputStream *stream;
5163 GError *error = NULL;
5165 iface = G_FILE_GET_IFACE (object);
5167 data = g_simple_async_result_get_op_res_gpointer (res);
5169 stream = iface->create (G_FILE (object), *data, cancellable, &error);
5173 g_simple_async_result_set_from_error (res, error);
5174 g_error_free (error);
5177 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5181 g_file_real_create_async (GFile *file,
5182 GFileCreateFlags flags,
5184 GCancellable *cancellable,
5185 GAsyncReadyCallback callback,
5188 GFileCreateFlags *data;
5189 GSimpleAsyncResult *res;
5191 data = g_new0 (GFileCreateFlags, 1);
5194 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_create_async);
5195 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
5197 g_simple_async_result_run_in_thread (res, create_async_thread, io_priority, cancellable);
5198 g_object_unref (res);
5201 static GFileOutputStream *
5202 g_file_real_create_finish (GFile *file,
5206 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5209 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_async);
5211 op = g_simple_async_result_get_op_res_gpointer (simple);
5213 return g_object_ref (op);
5219 GFileOutputStream *stream;
5221 gboolean make_backup;
5222 GFileCreateFlags flags;
5226 replace_async_data_free (ReplaceAsyncData *data)
5229 g_object_unref (data->stream);
5230 g_free (data->etag);
5235 replace_async_thread (GSimpleAsyncResult *res,
5237 GCancellable *cancellable)
5240 GFileOutputStream *stream;
5241 GError *error = NULL;
5242 ReplaceAsyncData *data;
5244 iface = G_FILE_GET_IFACE (object);
5246 data = g_simple_async_result_get_op_res_gpointer (res);
5248 stream = iface->replace (G_FILE (object),
5257 g_simple_async_result_set_from_error (res, error);
5258 g_error_free (error);
5261 data->stream = stream;
5265 g_file_real_replace_async (GFile *file,
5267 gboolean make_backup,
5268 GFileCreateFlags flags,
5270 GCancellable *cancellable,
5271 GAsyncReadyCallback callback,
5274 GSimpleAsyncResult *res;
5275 ReplaceAsyncData *data;
5277 data = g_new0 (ReplaceAsyncData, 1);
5278 data->etag = g_strdup (etag);
5279 data->make_backup = make_backup;
5280 data->flags = flags;
5282 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_replace_async);
5283 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_async_data_free);
5285 g_simple_async_result_run_in_thread (res, replace_async_thread, io_priority, cancellable);
5286 g_object_unref (res);
5289 static GFileOutputStream *
5290 g_file_real_replace_finish (GFile *file,
5294 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5295 ReplaceAsyncData *data;
5297 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_async);
5299 data = g_simple_async_result_get_op_res_gpointer (simple);
5301 return g_object_ref (data->stream);
5307 open_readwrite_async_thread (GSimpleAsyncResult *res,
5309 GCancellable *cancellable)
5312 GFileIOStream *stream;
5313 GError *error = NULL;
5315 iface = G_FILE_GET_IFACE (object);
5317 if (iface->open_readwrite == NULL)
5319 g_set_error_literal (&error, G_IO_ERROR,
5320 G_IO_ERROR_NOT_SUPPORTED,
5321 _("Operation not supported"));
5323 g_simple_async_result_set_from_error (res, error);
5324 g_error_free (error);
5329 stream = iface->open_readwrite (G_FILE (object), cancellable, &error);
5333 g_simple_async_result_set_from_error (res, error);
5334 g_error_free (error);
5337 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5341 g_file_real_open_readwrite_async (GFile *file,
5343 GCancellable *cancellable,
5344 GAsyncReadyCallback callback,
5347 GSimpleAsyncResult *res;
5349 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_open_readwrite_async);
5351 g_simple_async_result_run_in_thread (res, open_readwrite_async_thread, io_priority, cancellable);
5352 g_object_unref (res);
5355 static GFileIOStream *
5356 g_file_real_open_readwrite_finish (GFile *file,
5360 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5363 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_open_readwrite_async);
5365 op = g_simple_async_result_get_op_res_gpointer (simple);
5367 return g_object_ref (op);
5373 create_readwrite_async_thread (GSimpleAsyncResult *res,
5375 GCancellable *cancellable)
5378 GFileCreateFlags *data;
5379 GFileIOStream *stream;
5380 GError *error = NULL;
5382 iface = G_FILE_GET_IFACE (object);
5384 data = g_simple_async_result_get_op_res_gpointer (res);
5386 if (iface->create_readwrite == NULL)
5388 g_set_error_literal (&error, G_IO_ERROR,
5389 G_IO_ERROR_NOT_SUPPORTED,
5390 _("Operation not supported"));
5392 g_simple_async_result_set_from_error (res, error);
5393 g_error_free (error);
5398 stream = iface->create_readwrite (G_FILE (object), *data, cancellable, &error);
5402 g_simple_async_result_set_from_error (res, error);
5403 g_error_free (error);
5406 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5410 g_file_real_create_readwrite_async (GFile *file,
5411 GFileCreateFlags flags,
5413 GCancellable *cancellable,
5414 GAsyncReadyCallback callback,
5417 GFileCreateFlags *data;
5418 GSimpleAsyncResult *res;
5420 data = g_new0 (GFileCreateFlags, 1);
5423 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_create_readwrite_async);
5424 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
5426 g_simple_async_result_run_in_thread (res, create_readwrite_async_thread, io_priority, cancellable);
5427 g_object_unref (res);
5430 static GFileIOStream *
5431 g_file_real_create_readwrite_finish (GFile *file,
5435 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5438 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_readwrite_async);
5440 op = g_simple_async_result_get_op_res_gpointer (simple);
5442 return g_object_ref (op);
5448 GFileIOStream *stream;
5450 gboolean make_backup;
5451 GFileCreateFlags flags;
5452 } ReplaceRWAsyncData;
5455 replace_rw_async_data_free (ReplaceRWAsyncData *data)
5458 g_object_unref (data->stream);
5459 g_free (data->etag);
5464 replace_readwrite_async_thread (GSimpleAsyncResult *res,
5466 GCancellable *cancellable)
5469 GFileIOStream *stream;
5470 GError *error = NULL;
5471 ReplaceRWAsyncData *data;
5473 iface = G_FILE_GET_IFACE (object);
5475 data = g_simple_async_result_get_op_res_gpointer (res);
5477 stream = iface->replace_readwrite (G_FILE (object),
5486 g_simple_async_result_set_from_error (res, error);
5487 g_error_free (error);
5490 data->stream = stream;
5494 g_file_real_replace_readwrite_async (GFile *file,
5496 gboolean make_backup,
5497 GFileCreateFlags flags,
5499 GCancellable *cancellable,
5500 GAsyncReadyCallback callback,
5503 GSimpleAsyncResult *res;
5504 ReplaceRWAsyncData *data;
5506 data = g_new0 (ReplaceRWAsyncData, 1);
5507 data->etag = g_strdup (etag);
5508 data->make_backup = make_backup;
5509 data->flags = flags;
5511 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_replace_readwrite_async);
5512 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_rw_async_data_free);
5514 g_simple_async_result_run_in_thread (res, replace_readwrite_async_thread, io_priority, cancellable);
5515 g_object_unref (res);
5518 static GFileIOStream *
5519 g_file_real_replace_readwrite_finish (GFile *file,
5523 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5524 ReplaceRWAsyncData *data;
5526 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_readwrite_async);
5528 data = g_simple_async_result_get_op_res_gpointer (simple);
5530 return g_object_ref (data->stream);
5538 } SetDisplayNameAsyncData;
5541 set_display_name_data_free (SetDisplayNameAsyncData *data)
5543 g_free (data->name);
5545 g_object_unref (data->file);
5550 set_display_name_async_thread (GSimpleAsyncResult *res,
5552 GCancellable *cancellable)
5554 GError *error = NULL;
5555 SetDisplayNameAsyncData *data;
5558 data = g_simple_async_result_get_op_res_gpointer (res);
5560 file = g_file_set_display_name (G_FILE (object), data->name, cancellable, &error);
5564 g_simple_async_result_set_from_error (res, error);
5565 g_error_free (error);
5572 g_file_real_set_display_name_async (GFile *file,
5573 const char *display_name,
5575 GCancellable *cancellable,
5576 GAsyncReadyCallback callback,
5579 GSimpleAsyncResult *res;
5580 SetDisplayNameAsyncData *data;
5582 data = g_new0 (SetDisplayNameAsyncData, 1);
5583 data->name = g_strdup (display_name);
5585 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_set_display_name_async);
5586 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)set_display_name_data_free);
5588 g_simple_async_result_run_in_thread (res, set_display_name_async_thread, io_priority, cancellable);
5589 g_object_unref (res);
5593 g_file_real_set_display_name_finish (GFile *file,
5597 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5598 SetDisplayNameAsyncData *data;
5600 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_display_name_async);
5602 data = g_simple_async_result_get_op_res_gpointer (simple);
5604 return g_object_ref (data->file);
5610 GFileQueryInfoFlags flags;
5617 set_info_data_free (SetInfoAsyncData *data)
5620 g_object_unref (data->info);
5622 g_error_free (data->error);
5627 set_info_async_thread (GSimpleAsyncResult *res,
5629 GCancellable *cancellable)
5631 SetInfoAsyncData *data;
5633 data = g_simple_async_result_get_op_res_gpointer (res);
5636 data->res = g_file_set_attributes_from_info (G_FILE (object),
5644 g_file_real_set_attributes_async (GFile *file,
5646 GFileQueryInfoFlags flags,
5648 GCancellable *cancellable,
5649 GAsyncReadyCallback callback,
5652 GSimpleAsyncResult *res;
5653 SetInfoAsyncData *data;
5655 data = g_new0 (SetInfoAsyncData, 1);
5656 data->info = g_file_info_dup (info);
5657 data->flags = flags;
5659 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_set_attributes_async);
5660 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)set_info_data_free);
5662 g_simple_async_result_run_in_thread (res, set_info_async_thread, io_priority, cancellable);
5663 g_object_unref (res);
5667 g_file_real_set_attributes_finish (GFile *file,
5672 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5673 SetInfoAsyncData *data;
5675 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_attributes_async);
5677 data = g_simple_async_result_get_op_res_gpointer (simple);
5680 *info = g_object_ref (data->info);
5682 if (error != NULL && data->error)
5683 *error = g_error_copy (data->error);
5689 find_enclosing_mount_async_thread (GSimpleAsyncResult *res,
5691 GCancellable *cancellable)
5693 GError *error = NULL;
5696 mount = g_file_find_enclosing_mount (G_FILE (object), cancellable, &error);
5700 g_simple_async_result_set_from_error (res, error);
5701 g_error_free (error);
5704 g_simple_async_result_set_op_res_gpointer (res, mount, (GDestroyNotify)g_object_unref);
5708 g_file_real_find_enclosing_mount_async (GFile *file,
5710 GCancellable *cancellable,
5711 GAsyncReadyCallback callback,
5714 GSimpleAsyncResult *res;
5716 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_find_enclosing_mount_async);
5718 g_simple_async_result_run_in_thread (res, find_enclosing_mount_async_thread, io_priority, cancellable);
5719 g_object_unref (res);
5723 g_file_real_find_enclosing_mount_finish (GFile *file,
5727 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5730 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_find_enclosing_mount_async);
5732 mount = g_simple_async_result_get_op_res_gpointer (simple);
5733 return g_object_ref (mount);
5740 GFileCopyFlags flags;
5741 GFileProgressCallback progress_cb;
5742 gpointer progress_cb_data;
5743 GIOSchedulerJob *job;
5747 copy_async_data_free (CopyAsyncData *data)
5749 g_object_unref (data->source);
5750 g_object_unref (data->destination);
5755 CopyAsyncData *data;
5756 goffset current_num_bytes;
5757 goffset total_num_bytes;
5761 copy_async_progress_in_main (gpointer user_data)
5763 ProgressData *progress = user_data;
5764 CopyAsyncData *data = progress->data;
5766 data->progress_cb (progress->current_num_bytes,
5767 progress->total_num_bytes,
5768 data->progress_cb_data);
5774 mainloop_barrier (gpointer user_data)
5776 /* Does nothing, but ensures all queued idles before
5783 copy_async_progress_callback (goffset current_num_bytes,
5784 goffset total_num_bytes,
5787 CopyAsyncData *data = user_data;
5788 ProgressData *progress;
5790 progress = g_new (ProgressData, 1);
5791 progress->data = data;
5792 progress->current_num_bytes = current_num_bytes;
5793 progress->total_num_bytes = total_num_bytes;
5795 g_io_scheduler_job_send_to_mainloop_async (data->job,
5796 copy_async_progress_in_main,
5802 copy_async_thread (GIOSchedulerJob *job,
5803 GCancellable *cancellable,
5806 GSimpleAsyncResult *res;
5807 CopyAsyncData *data;
5812 data = g_simple_async_result_get_op_res_gpointer (res);
5816 result = g_file_copy (data->source,
5820 (data->progress_cb != NULL) ? copy_async_progress_callback : NULL,
5824 /* Ensure all progress callbacks are done running in main thread */
5825 if (data->progress_cb != NULL)
5826 g_io_scheduler_job_send_to_mainloop (job,
5832 g_simple_async_result_set_from_error (res, error);
5833 g_error_free (error);
5836 g_simple_async_result_complete_in_idle (res);
5842 g_file_real_copy_async (GFile *source,
5844 GFileCopyFlags flags,
5846 GCancellable *cancellable,
5847 GFileProgressCallback progress_callback,
5848 gpointer progress_callback_data,
5849 GAsyncReadyCallback callback,
5852 GSimpleAsyncResult *res;
5853 CopyAsyncData *data;
5855 data = g_new0 (CopyAsyncData, 1);
5856 data->source = g_object_ref (source);
5857 data->destination = g_object_ref (destination);
5858 data->flags = flags;
5859 data->progress_cb = progress_callback;
5860 data->progress_cb_data = progress_callback_data;
5862 res = g_simple_async_result_new (G_OBJECT (source), callback, user_data, g_file_real_copy_async);
5863 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)copy_async_data_free);
5865 g_io_scheduler_push_job (copy_async_thread, res, g_object_unref, io_priority, cancellable);
5869 g_file_real_copy_finish (GFile *file,
5873 /* Error handled in g_file_copy_finish() */
5878 /********************************************
5879 * Default VFS operations *
5880 ********************************************/
5883 * g_file_new_for_path:
5884 * @path: a string containing a relative or absolute path.
5886 * Constructs a #GFile for a given path. This operation never
5887 * fails, but the returned object might not support any I/O
5888 * operation if @path is malformed.
5890 * Returns: a new #GFile for the given @path.
5893 g_file_new_for_path (const char *path)
5895 g_return_val_if_fail (path != NULL, NULL);
5897 return g_vfs_get_file_for_path (g_vfs_get_default (), path);
5901 * g_file_new_for_uri:
5902 * @uri: a string containing a URI.
5904 * Constructs a #GFile for a given URI. This operation never
5905 * fails, but the returned object might not support any I/O
5906 * operation if @uri is malformed or if the uri type is
5909 * Returns: a #GFile for the given @uri.
5912 g_file_new_for_uri (const char *uri)
5914 g_return_val_if_fail (uri != NULL, NULL);
5916 return g_vfs_get_file_for_uri (g_vfs_get_default (), uri);
5920 * g_file_parse_name:
5921 * @parse_name: a file name or path to be parsed.
5923 * Constructs a #GFile with the given @parse_name (i.e. something given by g_file_get_parse_name()).
5924 * This operation never fails, but the returned object might not support any I/O
5925 * operation if the @parse_name cannot be parsed.
5927 * Returns: a new #GFile.
5930 g_file_parse_name (const char *parse_name)
5932 g_return_val_if_fail (parse_name != NULL, NULL);
5934 return g_vfs_parse_name (g_vfs_get_default (), parse_name);
5938 is_valid_scheme_character (char c)
5940 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
5943 /* Following RFC 2396, valid schemes are built like:
5944 * scheme = alpha *( alpha | digit | "+" | "-" | "." )
5947 has_valid_scheme (const char *uri)
5953 if (!g_ascii_isalpha (*p))
5958 } while (is_valid_scheme_character (*p));
5964 * g_file_new_for_commandline_arg:
5965 * @arg: a command line string.
5967 * Creates a #GFile with the given argument from the command line. The value of
5968 * @arg can be either a URI, an absolute path or a relative path resolved
5969 * relative to the current working directory.
5970 * This operation never fails, but the returned object might not support any
5971 * I/O operation if @arg points to a malformed path.
5973 * Returns: a new #GFile.
5976 g_file_new_for_commandline_arg (const char *arg)
5982 g_return_val_if_fail (arg != NULL, NULL);
5984 if (g_path_is_absolute (arg))
5985 return g_file_new_for_path (arg);
5987 if (has_valid_scheme (arg))
5988 return g_file_new_for_uri (arg);
5990 current_dir = g_get_current_dir ();
5991 filename = g_build_filename (current_dir, arg, NULL);
5992 g_free (current_dir);
5994 file = g_file_new_for_path (filename);
6001 * g_file_mount_enclosing_volume:
6002 * @location: input #GFile.
6003 * @flags: flags affecting the operation
6004 * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
6005 * @cancellable: optional #GCancellable object, %NULL to ignore.
6006 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
6007 * @user_data: the data to pass to callback function
6009 * Starts a @mount_operation, mounting the volume that contains the file @location.
6011 * When this operation has completed, @callback will be called with
6012 * @user_user data, and the operation can be finalized with
6013 * g_file_mount_enclosing_volume_finish().
6015 * If @cancellable is not %NULL, then the operation can be cancelled by
6016 * triggering the cancellable object from another thread. If the operation
6017 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6020 g_file_mount_enclosing_volume (GFile *location,
6021 GMountMountFlags flags,
6022 GMountOperation *mount_operation,
6023 GCancellable *cancellable,
6024 GAsyncReadyCallback callback,
6029 g_return_if_fail (G_IS_FILE (location));
6031 iface = G_FILE_GET_IFACE (location);
6033 if (iface->mount_enclosing_volume == NULL)
6035 g_simple_async_report_error_in_idle (G_OBJECT (location),
6036 callback, user_data,
6037 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
6038 _("volume doesn't implement mount"));
6043 (* iface->mount_enclosing_volume) (location, flags, mount_operation, cancellable, callback, user_data);
6048 * g_file_mount_enclosing_volume_finish:
6049 * @location: input #GFile.
6050 * @result: a #GAsyncResult.
6051 * @error: a #GError, or %NULL
6053 * Finishes a mount operation started by g_file_mount_enclosing_volume().
6055 * Returns: %TRUE if successful. If an error
6056 * has occurred, this function will return %FALSE and set @error
6057 * appropriately if present.
6060 g_file_mount_enclosing_volume_finish (GFile *location,
6061 GAsyncResult *result,
6066 g_return_val_if_fail (G_IS_FILE (location), FALSE);
6067 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
6069 if (G_IS_SIMPLE_ASYNC_RESULT (result))
6071 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
6072 if (g_simple_async_result_propagate_error (simple, error))
6076 iface = G_FILE_GET_IFACE (location);
6078 return (* iface->mount_enclosing_volume_finish) (location, result, error);
6081 /********************************************
6082 * Utility functions *
6083 ********************************************/
6086 * g_file_query_default_handler:
6087 * @file: a #GFile to open.
6088 * @cancellable: optional #GCancellable object, %NULL to ignore.
6089 * @error: a #GError, or %NULL
6091 * Returns the #GAppInfo that is registered as the default
6092 * application to handle the file specified by @file.
6094 * If @cancellable is not %NULL, then the operation can be cancelled by
6095 * triggering the cancellable object from another thread. If the operation
6096 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6098 * Returns: a #GAppInfo if the handle was found, %NULL if there were errors.
6099 * When you are done with it, release it with g_object_unref()
6102 g_file_query_default_handler (GFile *file,
6103 GCancellable *cancellable,
6107 const char *content_type;
6112 uri_scheme = g_file_get_uri_scheme (file);
6113 if (uri_scheme && uri_scheme[0] != '\0')
6115 appinfo = g_app_info_get_default_for_uri_scheme (uri_scheme);
6116 g_free (uri_scheme);
6118 if (appinfo != NULL)
6122 info = g_file_query_info (file,
6123 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
6132 content_type = g_file_info_get_content_type (info);
6135 /* Don't use is_native(), as we want to support fuse paths if availible */
6136 path = g_file_get_path (file);
6137 appinfo = g_app_info_get_default_for_type (content_type,
6142 g_object_unref (info);
6144 if (appinfo != NULL)
6147 g_set_error_literal (error, G_IO_ERROR,
6148 G_IO_ERROR_NOT_SUPPORTED,
6149 _("No application is registered as handling this file"));
6155 #define GET_CONTENT_BLOCK_SIZE 8192
6158 * g_file_load_contents:
6159 * @file: input #GFile.
6160 * @cancellable: optional #GCancellable object, %NULL to ignore.
6161 * @contents: a location to place the contents of the file.
6162 * @length: a location to place the length of the contents of the file,
6163 * or %NULL if the length is not needed
6164 * @etag_out: a location to place the current entity tag for the file,
6165 * or %NULL if the entity tag is not needed
6166 * @error: a #GError, or %NULL
6168 * Loads the content of the file into memory. The data is always
6169 * zero-terminated, but this is not included in the resultant @length.
6170 * The returned @content should be freed with g_free() when no longer
6173 * If @cancellable is not %NULL, then the operation can be cancelled by
6174 * triggering the cancellable object from another thread. If the operation
6175 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6177 * Returns: %TRUE if the @file's contents were successfully loaded.
6178 * %FALSE if there were errors.
6181 g_file_load_contents (GFile *file,
6182 GCancellable *cancellable,
6188 GFileInputStream *in;
6189 GByteArray *content;
6194 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6195 g_return_val_if_fail (contents != NULL, FALSE);
6197 in = g_file_read (file, cancellable, error);
6201 content = g_byte_array_new ();
6204 g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
6205 while ((res = g_input_stream_read (G_INPUT_STREAM (in),
6206 content->data + pos,
6207 GET_CONTENT_BLOCK_SIZE,
6208 cancellable, error)) > 0)
6211 g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
6218 info = g_file_input_stream_query_info (in,
6219 G_FILE_ATTRIBUTE_ETAG_VALUE,
6224 *etag_out = g_strdup (g_file_info_get_etag (info));
6225 g_object_unref (info);
6229 /* Ignore errors on close */
6230 g_input_stream_close (G_INPUT_STREAM (in), cancellable, NULL);
6231 g_object_unref (in);
6235 /* error is set already */
6236 g_byte_array_free (content, TRUE);
6243 /* Zero terminate (we got an extra byte allocated for this */
6244 content->data[pos] = 0;
6246 *contents = (char *)g_byte_array_free (content, FALSE);
6254 GCancellable *cancellable;
6255 GFileReadMoreCallback read_more_callback;
6256 GAsyncReadyCallback callback;
6258 GByteArray *content;
6265 load_contents_data_free (LoadContentsData *data)
6268 g_error_free (data->error);
6269 if (data->cancellable)
6270 g_object_unref (data->cancellable);
6272 g_byte_array_free (data->content, TRUE);
6273 g_free (data->etag);
6274 g_object_unref (data->file);
6279 load_contents_close_callback (GObject *obj,
6280 GAsyncResult *close_res,
6283 GInputStream *stream = G_INPUT_STREAM (obj);
6284 LoadContentsData *data = user_data;
6285 GSimpleAsyncResult *res;
6287 /* Ignore errors here, we're only reading anyway */
6288 g_input_stream_close_finish (stream, close_res, NULL);
6289 g_object_unref (stream);
6291 res = g_simple_async_result_new (G_OBJECT (data->file),
6294 g_file_load_contents_async);
6295 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)load_contents_data_free);
6296 g_simple_async_result_complete (res);
6297 g_object_unref (res);
6301 load_contents_fstat_callback (GObject *obj,
6302 GAsyncResult *stat_res,
6305 GInputStream *stream = G_INPUT_STREAM (obj);
6306 LoadContentsData *data = user_data;
6309 info = g_file_input_stream_query_info_finish (G_FILE_INPUT_STREAM (stream),
6313 data->etag = g_strdup (g_file_info_get_etag (info));
6314 g_object_unref (info);
6317 g_input_stream_close_async (stream, 0,
6319 load_contents_close_callback, data);
6323 load_contents_read_callback (GObject *obj,
6324 GAsyncResult *read_res,
6327 GInputStream *stream = G_INPUT_STREAM (obj);
6328 LoadContentsData *data = user_data;
6329 GError *error = NULL;
6332 read_size = g_input_stream_read_finish (stream, read_res, &error);
6336 /* Error or EOF, close the file */
6337 data->error = error;
6338 g_input_stream_close_async (stream, 0,
6340 load_contents_close_callback, data);
6342 else if (read_size == 0)
6344 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
6345 G_FILE_ATTRIBUTE_ETAG_VALUE,
6348 load_contents_fstat_callback,
6351 else if (read_size > 0)
6353 data->pos += read_size;
6355 g_byte_array_set_size (data->content,
6356 data->pos + GET_CONTENT_BLOCK_SIZE);
6359 if (data->read_more_callback &&
6360 !data->read_more_callback ((char *)data->content->data, data->pos, data->user_data))
6361 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
6362 G_FILE_ATTRIBUTE_ETAG_VALUE,
6365 load_contents_fstat_callback,
6368 g_input_stream_read_async (stream,
6369 data->content->data + data->pos,
6370 GET_CONTENT_BLOCK_SIZE,
6373 load_contents_read_callback,
6379 load_contents_open_callback (GObject *obj,
6380 GAsyncResult *open_res,
6383 GFile *file = G_FILE (obj);
6384 GFileInputStream *stream;
6385 LoadContentsData *data = user_data;
6386 GError *error = NULL;
6387 GSimpleAsyncResult *res;
6389 stream = g_file_read_finish (file, open_res, &error);
6393 g_byte_array_set_size (data->content,
6394 data->pos + GET_CONTENT_BLOCK_SIZE);
6395 g_input_stream_read_async (G_INPUT_STREAM (stream),
6396 data->content->data + data->pos,
6397 GET_CONTENT_BLOCK_SIZE,
6400 load_contents_read_callback,
6406 res = g_simple_async_result_new_from_error (G_OBJECT (data->file),
6410 g_simple_async_result_complete (res);
6411 g_error_free (error);
6412 load_contents_data_free (data);
6413 g_object_unref (res);
6418 * g_file_load_partial_contents_async:
6419 * @file: input #GFile.
6420 * @cancellable: optional #GCancellable object, %NULL to ignore.
6421 * @read_more_callback: a #GFileReadMoreCallback to receive partial data and to specify whether further data should be read.
6422 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6423 * @user_data: the data to pass to the callback functions.
6425 * Reads the partial contents of a file. A #GFileReadMoreCallback should be
6426 * used to stop reading from the file when appropriate, else this function
6427 * will behave exactly as g_file_load_contents_async(). This operation
6428 * can be finished by g_file_load_partial_contents_finish().
6430 * Users of this function should be aware that @user_data is passed to
6431 * both the @read_more_callback and the @callback.
6433 * If @cancellable is not %NULL, then the operation can be cancelled by
6434 * triggering the cancellable object from another thread. If the operation
6435 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6438 g_file_load_partial_contents_async (GFile *file,
6439 GCancellable *cancellable,
6440 GFileReadMoreCallback read_more_callback,
6441 GAsyncReadyCallback callback,
6444 LoadContentsData *data;
6446 g_return_if_fail (G_IS_FILE (file));
6448 data = g_new0 (LoadContentsData, 1);
6451 data->cancellable = g_object_ref (cancellable);
6452 data->read_more_callback = read_more_callback;
6453 data->callback = callback;
6454 data->user_data = user_data;
6455 data->content = g_byte_array_new ();
6456 data->file = g_object_ref (file);
6458 g_file_read_async (file,
6461 load_contents_open_callback,
6466 * g_file_load_partial_contents_finish:
6467 * @file: input #GFile.
6468 * @res: a #GAsyncResult.
6469 * @contents: a location to place the contents of the file.
6470 * @length: a location to place the length of the contents of the file,
6471 * or %NULL if the length is not needed
6472 * @etag_out: a location to place the current entity tag for the file,
6473 * or %NULL if the entity tag is not needed
6474 * @error: a #GError, or %NULL
6476 * Finishes an asynchronous partial load operation that was started
6477 * with g_file_load_partial_contents_async(). The data is always
6478 * zero-terminated, but this is not included in the resultant @length.
6479 * The returned @content should be freed with g_free() when no longer
6482 * Returns: %TRUE if the load was successful. If %FALSE and @error is
6483 * present, it will be set appropriately.
6486 g_file_load_partial_contents_finish (GFile *file,
6493 GSimpleAsyncResult *simple;
6494 LoadContentsData *data;
6496 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6497 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE);
6498 g_return_val_if_fail (contents != NULL, FALSE);
6500 simple = G_SIMPLE_ASYNC_RESULT (res);
6502 if (g_simple_async_result_propagate_error (simple, error))
6505 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_load_contents_async);
6507 data = g_simple_async_result_get_op_res_gpointer (simple);
6511 g_propagate_error (error, data->error);
6520 *length = data->pos;
6524 *etag_out = data->etag;
6528 /* Zero terminate */
6529 g_byte_array_set_size (data->content, data->pos + 1);
6530 data->content->data[data->pos] = 0;
6532 *contents = (char *)g_byte_array_free (data->content, FALSE);
6533 data->content = NULL;
6539 * g_file_load_contents_async:
6540 * @file: input #GFile.
6541 * @cancellable: optional #GCancellable object, %NULL to ignore.
6542 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6543 * @user_data: the data to pass to callback function
6545 * Starts an asynchronous load of the @file's contents.
6547 * For more details, see g_file_load_contents() which is
6548 * the synchronous version of this call.
6550 * When the load operation has completed, @callback will be called
6551 * with @user data. To finish the operation, call
6552 * g_file_load_contents_finish() with the #GAsyncResult returned by
6555 * If @cancellable is not %NULL, then the operation can be cancelled by
6556 * triggering the cancellable object from another thread. If the operation
6557 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6560 g_file_load_contents_async (GFile *file,
6561 GCancellable *cancellable,
6562 GAsyncReadyCallback callback,
6565 g_file_load_partial_contents_async (file,
6568 callback, user_data);
6572 * g_file_load_contents_finish:
6573 * @file: input #GFile.
6574 * @res: a #GAsyncResult.
6575 * @contents: a location to place the contents of the file.
6576 * @length: a location to place the length of the contents of the file,
6577 * or %NULL if the length is not needed
6578 * @etag_out: a location to place the current entity tag for the file,
6579 * or %NULL if the entity tag is not needed
6580 * @error: a #GError, or %NULL
6582 * Finishes an asynchronous load of the @file's contents.
6583 * The contents are placed in @contents, and @length is set to the
6584 * size of the @contents string. The @content should be freed with
6585 * g_free() when no longer needed. If @etag_out is present, it will be
6586 * set to the new entity tag for the @file.
6588 * Returns: %TRUE if the load was successful. If %FALSE and @error is
6589 * present, it will be set appropriately.
6592 g_file_load_contents_finish (GFile *file,
6599 return g_file_load_partial_contents_finish (file,
6608 * g_file_replace_contents:
6609 * @file: input #GFile.
6610 * @contents: a string containing the new contents for @file.
6611 * @length: the length of @contents in bytes.
6612 * @etag: the old <link linkend="gfile-etag">entity tag</link>
6613 * for the document, or %NULL
6614 * @make_backup: %TRUE if a backup should be created.
6615 * @flags: a set of #GFileCreateFlags.
6616 * @new_etag: a location to a new <link linkend="gfile-etag">entity tag</link>
6617 * for the document. This should be freed with g_free() when no longer
6619 * @cancellable: optional #GCancellable object, %NULL to ignore.
6620 * @error: a #GError, or %NULL
6622 * Replaces the contents of @file with @contents of @length bytes.
6624 * If @etag is specified (not %NULL) any existing file must have that etag, or
6625 * the error %G_IO_ERROR_WRONG_ETAG will be returned.
6627 * If @make_backup is %TRUE, this function will attempt to make a backup of @file.
6629 * If @cancellable is not %NULL, then the operation can be cancelled by
6630 * triggering the cancellable object from another thread. If the operation
6631 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6633 * The returned @new_etag can be used to verify that the file hasn't changed the
6634 * next time it is saved over.
6636 * Returns: %TRUE if successful. If an error
6637 * has occurred, this function will return %FALSE and set @error
6638 * appropriately if present.
6641 g_file_replace_contents (GFile *file,
6642 const char *contents,
6645 gboolean make_backup,
6646 GFileCreateFlags flags,
6648 GCancellable *cancellable,
6651 GFileOutputStream *out;
6652 gsize pos, remainder;
6656 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6657 g_return_val_if_fail (contents != NULL, FALSE);
6659 out = g_file_replace (file, etag, make_backup, flags, cancellable, error);
6665 while (remainder > 0 &&
6666 (res = g_output_stream_write (G_OUTPUT_STREAM (out),
6668 MIN (remainder, GET_CONTENT_BLOCK_SIZE),
6676 if (remainder > 0 && res < 0)
6678 /* Ignore errors on close */
6679 g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, NULL);
6680 g_object_unref (out);
6682 /* error is set already */
6686 ret = g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, error);
6689 *new_etag = g_file_output_stream_get_etag (out);
6691 g_object_unref (out);
6699 GCancellable *cancellable;
6700 GAsyncReadyCallback callback;
6702 const char *content;
6706 } ReplaceContentsData;
6709 replace_contents_data_free (ReplaceContentsData *data)
6712 g_error_free (data->error);
6713 if (data->cancellable)
6714 g_object_unref (data->cancellable);
6715 g_object_unref (data->file);
6716 g_free (data->etag);
6721 replace_contents_close_callback (GObject *obj,
6722 GAsyncResult *close_res,
6725 GOutputStream *stream = G_OUTPUT_STREAM (obj);
6726 ReplaceContentsData *data = user_data;
6727 GSimpleAsyncResult *res;
6729 /* Ignore errors here, we're only reading anyway */
6730 g_output_stream_close_finish (stream, close_res, NULL);
6731 g_object_unref (stream);
6733 data->etag = g_file_output_stream_get_etag (G_FILE_OUTPUT_STREAM (stream));
6735 res = g_simple_async_result_new (G_OBJECT (data->file),
6738 g_file_replace_contents_async);
6739 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_contents_data_free);
6740 g_simple_async_result_complete (res);
6741 g_object_unref (res);
6745 replace_contents_write_callback (GObject *obj,
6746 GAsyncResult *read_res,
6749 GOutputStream *stream = G_OUTPUT_STREAM (obj);
6750 ReplaceContentsData *data = user_data;
6751 GError *error = NULL;
6754 write_size = g_output_stream_write_finish (stream, read_res, &error);
6756 if (write_size <= 0)
6758 /* Error or EOF, close the file */
6760 data->error = error;
6761 g_output_stream_close_async (stream, 0,
6763 replace_contents_close_callback, data);
6765 else if (write_size > 0)
6767 data->pos += write_size;
6769 if (data->pos >= data->length)
6770 g_output_stream_close_async (stream, 0,
6772 replace_contents_close_callback, data);
6774 g_output_stream_write_async (stream,
6775 data->content + data->pos,
6776 data->length - data->pos,
6779 replace_contents_write_callback,
6785 replace_contents_open_callback (GObject *obj,
6786 GAsyncResult *open_res,
6789 GFile *file = G_FILE (obj);
6790 GFileOutputStream *stream;
6791 ReplaceContentsData *data = user_data;
6792 GError *error = NULL;
6793 GSimpleAsyncResult *res;
6795 stream = g_file_replace_finish (file, open_res, &error);
6799 g_output_stream_write_async (G_OUTPUT_STREAM (stream),
6800 data->content + data->pos,
6801 data->length - data->pos,
6804 replace_contents_write_callback,
6810 res = g_simple_async_result_new_from_error (G_OBJECT (data->file),
6814 g_simple_async_result_complete (res);
6815 g_error_free (error);
6816 replace_contents_data_free (data);
6817 g_object_unref (res);
6822 * g_file_replace_contents_async:
6823 * @file: input #GFile.
6824 * @contents: string of contents to replace the file with.
6825 * @length: the length of @contents in bytes.
6826 * @etag: a new <link linkend="gfile-etag">entity tag</link> for the @file, or %NULL
6827 * @make_backup: %TRUE if a backup should be created.
6828 * @flags: a set of #GFileCreateFlags.
6829 * @cancellable: optional #GCancellable object, %NULL to ignore.
6830 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6831 * @user_data: the data to pass to callback function
6833 * Starts an asynchronous replacement of @file with the given
6834 * @contents of @length bytes. @etag will replace the document's
6835 * current entity tag.
6837 * When this operation has completed, @callback will be called with
6838 * @user_user data, and the operation can be finalized with
6839 * g_file_replace_contents_finish().
6841 * If @cancellable is not %NULL, then the operation can be cancelled by
6842 * triggering the cancellable object from another thread. If the operation
6843 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6845 * If @make_backup is %TRUE, this function will attempt to
6846 * make a backup of @file.
6849 g_file_replace_contents_async (GFile *file,
6850 const char *contents,
6853 gboolean make_backup,
6854 GFileCreateFlags flags,
6855 GCancellable *cancellable,
6856 GAsyncReadyCallback callback,
6859 ReplaceContentsData *data;
6861 g_return_if_fail (G_IS_FILE (file));
6862 g_return_if_fail (contents != NULL);
6864 data = g_new0 (ReplaceContentsData, 1);
6867 data->cancellable = g_object_ref (cancellable);
6868 data->callback = callback;
6869 data->user_data = user_data;
6870 data->content = contents;
6871 data->length = length;
6873 data->file = g_object_ref (file);
6875 g_file_replace_async (file,
6881 replace_contents_open_callback,
6886 * g_file_replace_contents_finish:
6887 * @file: input #GFile.
6888 * @res: a #GAsyncResult.
6889 * @new_etag: a location of a new <link linkend="gfile-etag">entity tag</link>
6890 * for the document. This should be freed with g_free() when it is no
6891 * longer needed, or %NULL
6892 * @error: a #GError, or %NULL
6894 * Finishes an asynchronous replace of the given @file. See
6895 * g_file_replace_contents_async(). Sets @new_etag to the new entity
6896 * tag for the document, if present.
6898 * Returns: %TRUE on success, %FALSE on failure.
6901 g_file_replace_contents_finish (GFile *file,
6906 GSimpleAsyncResult *simple;
6907 ReplaceContentsData *data;
6909 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6910 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE);
6912 simple = G_SIMPLE_ASYNC_RESULT (res);
6914 if (g_simple_async_result_propagate_error (simple, error))
6917 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_replace_contents_async);
6919 data = g_simple_async_result_get_op_res_gpointer (simple);
6923 g_propagate_error (error, data->error);
6931 *new_etag = data->etag;
6932 data->etag = NULL; /* Take ownership */
6939 * g_file_start_mountable:
6940 * @file: input #GFile.
6941 * @flags: flags affecting the operation
6942 * @start_operation: a #GMountOperation, or %NULL to avoid user interaction.
6943 * @cancellable: optional #GCancellable object, %NULL to ignore.
6944 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
6945 * @user_data: the data to pass to callback function
6947 * Starts a file of type G_FILE_TYPE_MOUNTABLE.
6948 * Using @start_operation, you can request callbacks when, for instance,
6949 * passwords are needed during authentication.
6951 * If @cancellable is not %NULL, then the operation can be cancelled by
6952 * triggering the cancellable object from another thread. If the operation
6953 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6955 * When the operation is finished, @callback will be called. You can then call
6956 * g_file_mount_mountable_finish() to get the result of the operation.
6961 g_file_start_mountable (GFile *file,
6962 GDriveStartFlags flags,
6963 GMountOperation *start_operation,
6964 GCancellable *cancellable,
6965 GAsyncReadyCallback callback,
6970 g_return_if_fail (G_IS_FILE (file));
6972 iface = G_FILE_GET_IFACE (file);
6974 if (iface->start_mountable == NULL)
6976 g_simple_async_report_error_in_idle (G_OBJECT (file),
6980 G_IO_ERROR_NOT_SUPPORTED,
6981 _("Operation not supported"));
6985 (* iface->start_mountable) (file,
6994 * g_file_start_mountable_finish:
6995 * @file: input #GFile.
6996 * @result: a #GAsyncResult.
6997 * @error: a #GError, or %NULL
6999 * Finishes a start operation. See g_file_start_mountable() for details.
7001 * Finish an asynchronous start operation that was started
7002 * with g_file_start_mountable().
7004 * Returns: %TRUE if the operation finished successfully. %FALSE
7010 g_file_start_mountable_finish (GFile *file,
7011 GAsyncResult *result,
7016 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7017 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7019 if (G_IS_SIMPLE_ASYNC_RESULT (result))
7021 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
7022 if (g_simple_async_result_propagate_error (simple, error))
7026 iface = G_FILE_GET_IFACE (file);
7027 return (* iface->start_mountable_finish) (file, result, error);
7031 * g_file_stop_mountable:
7032 * @file: input #GFile.
7033 * @flags: flags affecting the operation
7034 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
7035 * @cancellable: optional #GCancellable object, %NULL to ignore.
7036 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
7037 * @user_data: the data to pass to callback function
7039 * Stops a file of type G_FILE_TYPE_MOUNTABLE.
7041 * If @cancellable is not %NULL, then the operation can be cancelled by
7042 * triggering the cancellable object from another thread. If the operation
7043 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7045 * When the operation is finished, @callback will be called. You can then call
7046 * g_file_stop_mountable_finish() to get the result of the operation.
7051 g_file_stop_mountable (GFile *file,
7052 GMountUnmountFlags flags,
7053 GMountOperation *mount_operation,
7054 GCancellable *cancellable,
7055 GAsyncReadyCallback callback,
7060 g_return_if_fail (G_IS_FILE (file));
7062 iface = G_FILE_GET_IFACE (file);
7064 if (iface->stop_mountable == NULL)
7066 g_simple_async_report_error_in_idle (G_OBJECT (file),
7070 G_IO_ERROR_NOT_SUPPORTED,
7071 _("Operation not supported"));
7075 (* iface->stop_mountable) (file,
7084 * g_file_stop_mountable_finish:
7085 * @file: input #GFile.
7086 * @result: a #GAsyncResult.
7087 * @error: a #GError, or %NULL
7089 * Finishes an stop operation, see g_file_stop_mountable() for details.
7091 * Finish an asynchronous stop operation that was started
7092 * with g_file_stop_mountable().
7094 * Returns: %TRUE if the operation finished successfully. %FALSE
7100 g_file_stop_mountable_finish (GFile *file,
7101 GAsyncResult *result,
7106 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7107 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7109 if (G_IS_SIMPLE_ASYNC_RESULT (result))
7111 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
7112 if (g_simple_async_result_propagate_error (simple, error))
7116 iface = G_FILE_GET_IFACE (file);
7117 return (* iface->stop_mountable_finish) (file, result, error);
7121 * g_file_poll_mountable:
7122 * @file: input #GFile.
7123 * @cancellable: optional #GCancellable object, %NULL to ignore.
7124 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
7125 * @user_data: the data to pass to callback function
7127 * Polls a file of type G_FILE_TYPE_MOUNTABLE.
7129 * If @cancellable is not %NULL, then the operation can be cancelled by
7130 * triggering the cancellable object from another thread. If the operation
7131 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7133 * When the operation is finished, @callback will be called. You can then call
7134 * g_file_mount_mountable_finish() to get the result of the operation.
7139 g_file_poll_mountable (GFile *file,
7140 GCancellable *cancellable,
7141 GAsyncReadyCallback callback,
7146 g_return_if_fail (G_IS_FILE (file));
7148 iface = G_FILE_GET_IFACE (file);
7150 if (iface->poll_mountable == NULL)
7152 g_simple_async_report_error_in_idle (G_OBJECT (file),
7156 G_IO_ERROR_NOT_SUPPORTED,
7157 _("Operation not supported"));
7161 (* iface->poll_mountable) (file,
7168 * g_file_poll_mountable_finish:
7169 * @file: input #GFile.
7170 * @result: a #GAsyncResult.
7171 * @error: a #GError, or %NULL
7173 * Finishes a poll operation. See g_file_poll_mountable() for details.
7175 * Finish an asynchronous poll operation that was polled
7176 * with g_file_poll_mountable().
7178 * Returns: %TRUE if the operation finished successfully. %FALSE
7184 g_file_poll_mountable_finish (GFile *file,
7185 GAsyncResult *result,
7190 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7191 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7193 if (G_IS_SIMPLE_ASYNC_RESULT (result))
7195 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
7196 if (g_simple_async_result_propagate_error (simple, error))
7200 iface = G_FILE_GET_IFACE (file);
7201 return (* iface->poll_mountable_finish) (file, result, error);
7205 * g_file_supports_thread_contexts:
7208 * Checks if @file supports <link
7209 * linkend="g-main-context-push-thread-default-context">thread-default
7210 * contexts</link>. If this returns %FALSE, you cannot perform
7211 * asynchronous operations on @file in a thread that has a
7212 * thread-default context.
7214 * Returns: Whether or not @file supports thread-default contexts.
7219 g_file_supports_thread_contexts (GFile *file)
7223 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7225 iface = G_FILE_GET_IFACE (file);
7226 return iface->supports_thread_contexts;
7229 #define __G_FILE_C__
7230 #include "gioaliasdef.c"