1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
25 #include <sys/types.h>
31 #include "gioscheduler.h"
32 #include <glocalfile.h>
33 #include "gsimpleasyncresult.h"
34 #include "gfileattribute-priv.h"
35 #include "gpollfilemonitor.h"
42 * @short_description: File and Directory Handling
44 * @see_also: #GFileInfo, #GFileEnumerator
46 * #GFile is a high level abstraction for manipulating files on a
47 * virtual file system. #GFile<!-- -->s are lightweight, immutable
48 * objects that do no I/O upon creation. It is necessary to understand that
49 * #GFile objects do not represent files, merely an identifier for a file. All
50 * file content I/O is implemented as streaming operations (see #GInputStream and
53 * To construct a #GFile, you can use:
54 * g_file_new_for_path() if you have a path.
55 * g_file_new_for_uri() if you have a URI.
56 * g_file_new_for_commandline_arg() for a command line argument.
57 * g_file_parse_name() from a utf8 string gotten from g_file_get_parse_name().
59 * One way to think of a #GFile is as an abstraction of a pathname. For normal
60 * files the system pathname is what is stored interanally, but as #GFile<!-- -->s
61 * are extensible it could also be something else that corresponds to a pathname
62 * in a userspace implementation of a filesystem.
64 * #GFile<!-- -->s make up hierarchies of directories and files that correspond to the
65 * files on a filesystem. You can move through the file system with #GFile using
66 * g_file_get_parent() to get an identifier for the parent directory, g_file_get_child()
67 * to get a child within a directory, g_file_resolve_relative_path() to resolve a relative
68 * path between two #GFile<!-- -->s. There can be multiple hierarchies, so you may not
69 * end up at the same root if you repeatedly call g_file_get_parent() on two different
72 * All #GFile<!-- -->s have a basename (get with g_file_get_basename()). These names
73 * are byte strings that are used to identify the file on the filesystem (relative to
74 * its parent directory) and there is no guarantees that they have any particular charset
75 * encoding or even make any sense at all. If you want to use filenames in a user
76 * interface you should use the display name that you can get by requesting the
77 * %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info().
78 * This is guaranteed to be in utf8 and can be used in a user interface. But always
79 * store the real basename or the #GFile to use to actually access the file, because
80 * there is no way to go from a display name to the actual name.
82 * Using #GFile as an identifier has the same weaknesses as using a path in that
83 * there may be multiple aliases for the same file. For instance, hard or
84 * soft links may cause two different #GFile<!-- -->s to refer to the same file.
85 * Other possible causes for aliases are: case insensitive filesystems, short
86 * and long names on Fat/NTFS, or bind mounts in linux. If you want to check if
87 * two #GFile<!-- -->s point to the same file you can query for the
88 * %G_FILE_ATTRIBUTE_ID_FILE attribute. Note that #GFile does some trivial
89 * canonicalization of pathnames passed in, so that trivial differences in the
90 * path string used at creation (dupplicated slashes, slash at end of path, "."
91 * or ".." path segments, etc) does not create different #GFile<!-- -->s.
93 * Many #GFile operations have both synchronous and asynchronous versions
94 * to suit your application. Asynchronous versions of synchronous functions
95 * simply have _async() appended to their function names. The asynchronous
96 * I/O functions call a #GAsyncReadyCallback which is then used to finalize
97 * the operation, producing a GAsyncResult which is then passed to the
98 * function's matching _finish()
101 * Some #GFile operations do not have synchronous analogs, as they may
102 * take a very long time to finish, and blocking may leave an application
103 * unusable. Notable cases include:
104 * g_file_mount_mountable() to mount a mountable file.
105 * g_file_unmount_mountable() to unmount a mountable file.
106 * g_file_eject_mountable() to eject a mountable file.
108 * <para id="gfile-etag"><indexterm><primary>entity tag</primary></indexterm>
109 * One notable feature of #GFile<!-- -->s are entity tags, or "etags" for
110 * short. Entity tags are somewhat like a more abstract version of the
111 * traditional mtime, and can be used to quickly determine if the file has
112 * been modified from the version on the file system. See the HTTP 1.1
113 * <ulink url="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">specification</ulink>
114 * for HTTP Etag headers, which are a very similar concept.
118 static void g_file_base_init (gpointer g_class);
119 static void g_file_class_init (gpointer g_class,
120 gpointer class_data);
122 static void g_file_real_query_info_async (GFile *file,
123 const char *attributes,
124 GFileQueryInfoFlags flags,
126 GCancellable *cancellable,
127 GAsyncReadyCallback callback,
129 static GFileInfo * g_file_real_query_info_finish (GFile *file,
132 static void g_file_real_enumerate_children_async (GFile *file,
133 const char *attributes,
134 GFileQueryInfoFlags flags,
136 GCancellable *cancellable,
137 GAsyncReadyCallback callback,
139 static GFileEnumerator * g_file_real_enumerate_children_finish (GFile *file,
142 static void g_file_real_read_async (GFile *file,
144 GCancellable *cancellable,
145 GAsyncReadyCallback callback,
147 static GFileInputStream * g_file_real_read_finish (GFile *file,
150 static void g_file_real_append_to_async (GFile *file,
151 GFileCreateFlags flags,
153 GCancellable *cancellable,
154 GAsyncReadyCallback callback,
156 static GFileOutputStream *g_file_real_append_to_finish (GFile *file,
159 static void g_file_real_create_async (GFile *file,
160 GFileCreateFlags flags,
162 GCancellable *cancellable,
163 GAsyncReadyCallback callback,
165 static GFileOutputStream *g_file_real_create_finish (GFile *file,
168 static void g_file_real_replace_async (GFile *file,
170 gboolean make_backup,
171 GFileCreateFlags flags,
173 GCancellable *cancellable,
174 GAsyncReadyCallback callback,
176 static GFileOutputStream *g_file_real_replace_finish (GFile *file,
179 static gboolean g_file_real_set_attributes_from_info (GFile *file,
181 GFileQueryInfoFlags flags,
182 GCancellable *cancellable,
184 static void g_file_real_set_display_name_async (GFile *file,
185 const char *display_name,
187 GCancellable *cancellable,
188 GAsyncReadyCallback callback,
190 static GFile * g_file_real_set_display_name_finish (GFile *file,
193 static void g_file_real_set_attributes_async (GFile *file,
195 GFileQueryInfoFlags flags,
197 GCancellable *cancellable,
198 GAsyncReadyCallback callback,
200 static gboolean g_file_real_set_attributes_finish (GFile *file,
204 static void g_file_real_find_enclosing_mount_async (GFile *file,
206 GCancellable *cancellable,
207 GAsyncReadyCallback callback,
209 static GMount * g_file_real_find_enclosing_mount_finish (GFile *file,
212 static void g_file_real_copy_async (GFile *source,
214 GFileCopyFlags flags,
216 GCancellable *cancellable,
217 GFileProgressCallback progress_callback,
218 gpointer progress_callback_data,
219 GAsyncReadyCallback callback,
221 static gboolean g_file_real_copy_finish (GFile *file,
226 g_file_get_type (void)
228 static GType file_type = 0;
232 static const GTypeInfo file_info =
234 sizeof (GFileIface), /* class_size */
235 g_file_base_init, /* base_init */
236 NULL, /* base_finalize */
238 NULL, /* class_finalize */
239 NULL, /* class_data */
246 g_type_register_static (G_TYPE_INTERFACE, I_("GFile"),
249 g_type_interface_add_prerequisite (file_type, G_TYPE_OBJECT);
256 g_file_class_init (gpointer g_class,
259 GFileIface *iface = g_class;
261 iface->enumerate_children_async = g_file_real_enumerate_children_async;
262 iface->enumerate_children_finish = g_file_real_enumerate_children_finish;
263 iface->set_display_name_async = g_file_real_set_display_name_async;
264 iface->set_display_name_finish = g_file_real_set_display_name_finish;
265 iface->query_info_async = g_file_real_query_info_async;
266 iface->query_info_finish = g_file_real_query_info_finish;
267 iface->set_attributes_async = g_file_real_set_attributes_async;
268 iface->set_attributes_finish = g_file_real_set_attributes_finish;
269 iface->read_async = g_file_real_read_async;
270 iface->read_finish = g_file_real_read_finish;
271 iface->append_to_async = g_file_real_append_to_async;
272 iface->append_to_finish = g_file_real_append_to_finish;
273 iface->create_async = g_file_real_create_async;
274 iface->create_finish = g_file_real_create_finish;
275 iface->replace_async = g_file_real_replace_async;
276 iface->replace_finish = g_file_real_replace_finish;
277 iface->find_enclosing_mount_async = g_file_real_find_enclosing_mount_async;
278 iface->find_enclosing_mount_finish = g_file_real_find_enclosing_mount_finish;
279 iface->set_attributes_from_info = g_file_real_set_attributes_from_info;
280 iface->copy_async = g_file_real_copy_async;
281 iface->copy_finish = g_file_real_copy_finish;
285 g_file_base_init (gpointer g_class)
292 * @file: input #GFile.
294 * Checks to see if a file is native to the platform.
296 * A native file s one expressed in the platform-native filename format,
297 * e.g. "C:\Windows" or "/usr/bin/". This does not mean the file is local,
298 * as it might be on a locally mounted remote filesystem.
300 * On some systems non-native files may be available using
301 * the native filesystem via a userspace filesystem (FUSE), in
302 * these cases this call will return %FALSE, but g_file_get_path()
303 * will still return a native path.
305 * This call does no blocking i/o.
307 * Returns: %TRUE if file is native.
310 g_file_is_native (GFile *file)
314 g_return_val_if_fail (G_IS_FILE (file), FALSE);
316 iface = G_FILE_GET_IFACE (file);
318 return (* iface->is_native) (file);
323 * g_file_has_uri_scheme:
324 * @file: input #GFile.
325 * @uri_scheme: a string containing a URI scheme.
327 * Checks to see if a #GFile has a given URI scheme.
329 * This call does no blocking i/o.
331 * Returns: %TRUE if #GFile's backend supports the
332 * given URI scheme, %FALSE if URI scheme is %NULL,
333 * not supported, or #GFile is invalid.
336 g_file_has_uri_scheme (GFile *file,
337 const char *uri_scheme)
341 g_return_val_if_fail (G_IS_FILE (file), FALSE);
342 g_return_val_if_fail (uri_scheme != NULL, FALSE);
344 iface = G_FILE_GET_IFACE (file);
346 return (* iface->has_uri_scheme) (file, uri_scheme);
351 * g_file_get_uri_scheme:
352 * @file: input #GFile.
354 * Gets the URI scheme for a #GFile.
355 * RFC 3986 decodes the scheme as:
357 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
359 * Common schemes include "file", "http", "ftp", etc.
361 * This call does no blocking i/o.
363 * Returns: a string containing the URI scheme for the given
364 * #GFile. The returned string should be freed with g_free()
365 * when no longer needed.
368 g_file_get_uri_scheme (GFile *file)
372 g_return_val_if_fail (G_IS_FILE (file), NULL);
374 iface = G_FILE_GET_IFACE (file);
376 return (* iface->get_uri_scheme) (file);
381 * g_file_get_basename:
382 * @file: input #GFile.
384 * Gets the base name (the last component of the path) for a given #GFile.
386 * If called for the top level of a system (such as the filesystem root
387 * or a uri like sftp://host/) it will return a single directory separator
388 * (and on Windows, possibly a drive letter).
390 * The base name is a byte string (*not* UTF-8). It has no defined encoding
391 * or rules other than it may not contain zero bytes. If you want to use
392 * filenames in a user interface you should use the display name that you
393 * can get by requesting the %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
394 * attribute with g_file_query_info().
396 * This call does no blocking i/o.
398 * Returns: string containing the #GFile's base name, or %NULL
399 * if given #GFile is invalid. The returned string should be
400 * freed with g_free() when no longer needed.
403 g_file_get_basename (GFile *file)
407 g_return_val_if_fail (G_IS_FILE (file), NULL);
409 iface = G_FILE_GET_IFACE (file);
411 return (* iface->get_basename) (file);
416 * @file: input #GFile.
418 * Gets the local pathname for #GFile, if one exists.
420 * This call does no blocking i/o.
422 * Returns: string containing the #GFile's path, or %NULL if
423 * no such path exists. The returned string should be
424 * freed with g_free() when no longer needed.
427 g_file_get_path (GFile *file)
431 g_return_val_if_fail (G_IS_FILE (file), NULL);
433 iface = G_FILE_GET_IFACE (file);
435 return (* iface->get_path) (file);
440 * @file: input #GFile.
442 * Gets the URI for the @file.
444 * This call does no blocking i/o.
446 * Returns: a string containing the #GFile's URI.
447 * The returned string should be freed with g_free() when no longer needed.
450 g_file_get_uri (GFile *file)
454 g_return_val_if_fail (G_IS_FILE (file), NULL);
456 iface = G_FILE_GET_IFACE (file);
458 return (* iface->get_uri) (file);
462 * g_file_get_parse_name:
463 * @file: input #GFile.
465 * Gets the parse name of the @file.
466 * A parse name is a UTF-8 string that describes the
467 * file such that one can get the #GFile back using
468 * g_file_parse_name().
470 * This is generally used to show the #GFile as a nice
471 * full-pathname kind of string in a user interface,
472 * like in a location entry.
474 * For local files with names that can safely be converted
475 * to UTF8 the pathname is used, otherwise the IRI is used
476 * (a form of URI that allows UTF8 characters unescaped).
478 * This call does no blocking i/o.
480 * Returns: a string containing the #GFile's parse name. The returned
481 * string should be freed with g_free() when no longer needed.
484 g_file_get_parse_name (GFile *file)
488 g_return_val_if_fail (G_IS_FILE (file), NULL);
490 iface = G_FILE_GET_IFACE (file);
492 return (* iface->get_parse_name) (file);
497 * @file: input #GFile.
499 * Duplicates a #GFile handle. This operation does not duplicate
500 * the actual file or directory represented by the #GFile; see
501 * g_file_copy() if attempting to copy a file.
503 * This call does no blocking i/o.
505 * Returns: #GFile that is a duplicate of the given #GFile.
508 g_file_dup (GFile *file)
512 g_return_val_if_fail (G_IS_FILE (file), NULL);
514 iface = G_FILE_GET_IFACE (file);
516 return (* iface->dup) (file);
521 * @file: #gconstpointer to a #GFile.
523 * Creates a hash value for a #GFile.
525 * This call does no blocking i/o.
527 * Returns: 0 if @file is not a valid #GFile, otherwise an
528 * integer that can be used as hash value for the #GFile.
529 * This function is intended for easily hashing a #GFile to
530 * add to a #GHashTable or similar data structure.
533 g_file_hash (gconstpointer file)
537 g_return_val_if_fail (G_IS_FILE (file), 0);
539 iface = G_FILE_GET_IFACE (file);
541 return (* iface->hash) ((GFile *)file);
546 * @file1: the first #GFile.
547 * @file2: the second #GFile.
549 * Checks equality of two given #GFile<!-- -->s. Note that two
550 * #GFile<!-- -->s that differ can still refer to the same
551 * file on the filesystem due to various forms of filename
554 * This call does no blocking i/o.
556 * Returns: %TRUE if @file1 and @file2 are equal.
557 * %FALSE if either is not a #GFile.
560 g_file_equal (GFile *file1,
565 g_return_val_if_fail (G_IS_FILE (file1), FALSE);
566 g_return_val_if_fail (G_IS_FILE (file2), FALSE);
568 if (G_TYPE_FROM_INSTANCE (file1) != G_TYPE_FROM_INSTANCE (file2))
571 iface = G_FILE_GET_IFACE (file1);
573 return (* iface->equal) (file1, file2);
579 * @file: input #GFile.
581 * Gets the parent directory for the @file.
582 * If the @file represents the root directory of the
583 * file system, then %NULL will be returned.
585 * This call does no blocking i/o.
587 * Returns: a #GFile structure to the parent of the given
588 * #GFile or %NULL if there is no parent.
591 g_file_get_parent (GFile *file)
595 g_return_val_if_fail (G_IS_FILE (file), NULL);
597 iface = G_FILE_GET_IFACE (file);
599 return (* iface->get_parent) (file);
604 * @file: input #GFile.
605 * @name: string containing the child's basename.
607 * Gets a child of @file with basename equal to @name.
609 * Note that the file with that specific name might not exist, but
610 * you can still have a #GFile that points to it. You can use this
611 * for instance to create that file.
613 * This call does no blocking i/o.
615 * Returns: a #GFile to a child specified by @name.
618 g_file_get_child (GFile *file,
621 g_return_val_if_fail (G_IS_FILE (file), NULL);
622 g_return_val_if_fail (name != NULL, NULL);
624 return g_file_resolve_relative_path (file, name);
628 * g_file_get_child_for_display_name:
629 * @file: input #GFile.
630 * @display_name: string to a possible child.
633 * Gets the child of @file for a given @display_name (i.e. a UTF8
634 * version of the name). If this function fails, it returns %NULL and @error will be
635 * set. This is very useful when constructing a GFile for a new file
636 * and the user entered the filename in the user interface, for instance
637 * when you select a directory and type a filename in the file selector.
639 * This call does no blocking i/o.
641 * Returns: a #GFile to the specified child, or
642 * %NULL if the display name couldn't be converted.
645 g_file_get_child_for_display_name (GFile *file,
646 const char *display_name,
651 g_return_val_if_fail (G_IS_FILE (file), NULL);
652 g_return_val_if_fail (display_name != NULL, NULL);
654 iface = G_FILE_GET_IFACE (file);
656 return (* iface->get_child_for_display_name) (file, display_name, error);
659 #undef g_file_contains_file
662 * g_file_contains_file:
663 * @parent: input #GFile.
664 * @descendant: input #GFile.
666 * Deprecated version of g_file_has_prefix().
668 * Returns: %TRUE if the @descendant's parent, grandparent, etc is @parent. %FALSE otherwise.
670 * Deprecated:2.16: The initial chosen name was unfortunate, as it
671 * may cause you to think this function did more than just
672 * filename comparisons.
675 g_file_contains_file (GFile *parent,
678 /* This function is not in the header and will not be referenced by newly built code */
679 return g_file_has_prefix (descendant, parent);
684 * @file: input #GFile.
685 * @prefix: input #GFile.
687 * Checks whether @file has the prefix specified by @prefix. In other word, if the
688 * names of inital elements of @file<!-- -->s pathname match @prefix.
690 * This call does no i/o, as it works purely on names. As such it can sometimes
691 * return %FALSE even if @file is inside a @prefix (from a filesystem point of view),
692 * because the prefix of @file is an alias of @prefix.
694 * Returns: %TRUE if the @files's parent, grandparent, etc is @prefix. %FALSE otherwise.
697 g_file_has_prefix (GFile *file,
702 g_return_val_if_fail (G_IS_FILE (file), FALSE);
703 g_return_val_if_fail (G_IS_FILE (prefix), FALSE);
705 if (G_TYPE_FROM_INSTANCE (file) != G_TYPE_FROM_INSTANCE (prefix))
708 iface = G_FILE_GET_IFACE (file);
710 /* The vtable function differs in arg order since we're
711 using the old contains_file call */
712 return (* iface->prefix_matches) (prefix, file);
716 * g_file_get_relative_path:
717 * @parent: input #GFile.
718 * @descendant: input #GFile.
720 * Gets the path for @descendant relative to @parent.
722 * This call does no blocking i/o.
724 * Returns: string with the relative path from @descendant
725 * to @parent, or %NULL if @descendant doesn't have @parent as prefix. The returned string should be freed with
726 * g_free() when no longer needed.
729 g_file_get_relative_path (GFile *parent,
734 g_return_val_if_fail (G_IS_FILE (parent), NULL);
735 g_return_val_if_fail (G_IS_FILE (descendant), NULL);
737 if (G_TYPE_FROM_INSTANCE (parent) != G_TYPE_FROM_INSTANCE (descendant))
740 iface = G_FILE_GET_IFACE (parent);
742 return (* iface->get_relative_path) (parent, descendant);
746 * g_file_resolve_relative_path:
747 * @file: input #GFile.
748 * @relative_path: a given relative path string.
750 * Resolves a relative path for @file to an absolute path.
752 * This call does no blocking i/o.
754 * Returns: #GFile to the resolved path. %NULL if @relative_path
755 * is %NULL or if @file is invalid.
758 g_file_resolve_relative_path (GFile *file,
759 const char *relative_path)
763 g_return_val_if_fail (G_IS_FILE (file), NULL);
764 g_return_val_if_fail (relative_path != NULL, NULL);
766 iface = G_FILE_GET_IFACE (file);
768 return (* iface->resolve_relative_path) (file, relative_path);
772 * g_file_enumerate_children:
773 * @file: input #GFile.
774 * @attributes: an attribute query string.
775 * @flags: a set of #GFileQueryInfoFlags.
776 * @cancellable: optional #GCancellable object, %NULL to ignore.
777 * @error: #GError for error reporting.
779 * Gets the requested information about the files in a directory. The result
780 * is a #GFileEnumerator object that will give out #GFileInfo objects for
781 * all the files in the directory.
783 * The @attribute value is a string that specifies the file attributes that
784 * should be gathered. It is not an error if it's not possible to read a particular
785 * requested attribute from a file - it just won't be set. @attribute should
786 * be a comma-separated list of attribute or attribute wildcards. The wildcard "*"
787 * means all attributes, and a wildcard like "standard::*" means all attributes in the standard
788 * namespace. An example attribute query be "standard::*,owner::user".
789 * The standard attributes are available as defines, like #G_FILE_ATTRIBUTE_STANDARD_NAME.
791 * If @cancellable is not %NULL, then the operation can be cancelled by
792 * triggering the cancellable object from another thread. If the operation
793 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
795 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
796 * If the file is not a directory, the G_FILE_ERROR_NOTDIR error will be returned.
797 * Other errors are possible too.
799 * Returns: A #GFileEnumerator if successful, %NULL on error.
802 g_file_enumerate_children (GFile *file,
803 const char *attributes,
804 GFileQueryInfoFlags flags,
805 GCancellable *cancellable,
811 g_return_val_if_fail (G_IS_FILE (file), NULL);
813 if (g_cancellable_set_error_if_cancelled (cancellable, error))
816 iface = G_FILE_GET_IFACE (file);
818 if (iface->enumerate_children == NULL)
820 g_set_error (error, G_IO_ERROR,
821 G_IO_ERROR_NOT_SUPPORTED,
822 _("Operation not supported"));
826 return (* iface->enumerate_children) (file, attributes, flags,
831 * g_file_enumerate_children_async:
832 * @file: input #GFile.
833 * @attributes: an attribute query string.
834 * @flags: a set of #GFileQueryInfoFlags.
835 * @io_priority: the <link linkend="io-priority">I/O priority</link>
837 * @cancellable: optional #GCancellable object, %NULL to ignore.
838 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
839 * @user_data: the data to pass to callback function
841 * Asynchronously gets the requested information about the files in a directory. The result
842 * is a #GFileEnumerator object that will give out #GFileInfo objects for
843 * all the files in the directory.
845 * For more details, see g_file_enumerate_children() which is
846 * the synchronous version of this call.
848 * When the operation is finished, @callback will be called. You can then call
849 * g_file_enumerate_children_finish() to get the result of the operation.
852 g_file_enumerate_children_async (GFile *file,
853 const char *attributes,
854 GFileQueryInfoFlags flags,
856 GCancellable *cancellable,
857 GAsyncReadyCallback callback,
862 g_return_if_fail (G_IS_FILE (file));
864 iface = G_FILE_GET_IFACE (file);
865 (* iface->enumerate_children_async) (file,
875 * g_file_enumerate_children_finish:
876 * @file: input #GFile.
877 * @res: a #GAsyncResult.
880 * Finishes an async enumerate children operation.
881 * See g_file_enumerate_children_async().
883 * Returns: a #GFileEnumerator or %NULL if an error occurred.
886 g_file_enumerate_children_finish (GFile *file,
892 g_return_val_if_fail (G_IS_FILE (file), NULL);
893 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
895 if (G_IS_SIMPLE_ASYNC_RESULT (res))
897 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
898 if (g_simple_async_result_propagate_error (simple, error))
902 iface = G_FILE_GET_IFACE (file);
903 return (* iface->enumerate_children_finish) (file, res, error);
907 * g_file_query_exists:
908 * @file: input #GFile.
909 * @cancellable: optional #GCancellable object, %NULL to ignore.
911 * Utility function to check if a particular file exists. This is
912 * implemented using g_file_query_info() and as such does blocking I/O.
914 * Note that in many cases it is racy to first check for file existance
915 * and then execute something based on the outcome of that, because the
916 * file might have been created or removed inbetween the operations. The
917 * general approach to handling that is to not check, but just do the
918 * operation and handle the errors as they come.
920 * As an example of race-free checking, take the case of reading a file, and
921 * if it doesn't exist, creating it. There are two racy versions: read it, and
922 * on error create it; and: check if it exists, if not create it. These
923 * can both result in two processes creating the file (with perhaps a partially
924 * written file as the result). The correct approach is to always try to create
925 * the file with g_file_create() which will either atomically create the file
926 * or fail with a G_IO_ERROR_EXISTS error.
928 * However, in many cases an existance check is useful in a user
929 * interface, for instance to make a menu item sensitive/insensitive, so that
930 * you don't have to fool users that something is possible and then just show
931 * and error dialog. If you do this, you should make sure to also handle the
932 * errors that can happen due to races when you execute the operation.
934 * Returns: %TRUE if the file exists (and can be detected without error), %FALSE otherwise (or if cancelled).
937 g_file_query_exists (GFile *file,
938 GCancellable *cancellable)
942 info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE,
943 G_FILE_QUERY_INFO_NONE,
947 g_object_unref (info);
956 * @file: input #GFile.
957 * @attributes: an attribute query string.
958 * @flags: a set of #GFileQueryInfoFlags.
959 * @cancellable: optional #GCancellable object, %NULL to ignore.
962 * Gets the requested information about specified @file. The result
963 * is a #GFileInfo object that contains key-value attributes (such as
964 * the type or size of the file).
966 * The @attribute value is a string that specifies the file attributes that
967 * should be gathered. It is not an error if it's not possible to read a particular
968 * requested attribute from a file - it just won't be set. @attribute should
969 * be a comma-separated list of attribute or attribute wildcards. The wildcard "*"
970 * means all attributes, and a wildcard like "standard::*" means all attributes in the standard
971 * namespace. An example attribute query be "standard::*,owner::user".
972 * The standard attributes are available as defines, like #G_FILE_ATTRIBUTE_STANDARD_NAME.
974 * If @cancellable is not %NULL, then the operation can be cancelled by
975 * triggering the cancellable object from another thread. If the operation
976 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
978 * For symlinks, normally the information about the target of the
979 * symlink is returned, rather than information about the symlink itself.
980 * However if you pass #G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS in @flags the
981 * information about the symlink itself will be returned. Also, for symlinks
982 * that point to non-existing files the information about the symlink itself
985 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
986 * Other errors are possible too, and depend on what kind of filesystem the file is on.
988 * Returns: a #GFileInfo for the given @file, or %NULL on error.
991 g_file_query_info (GFile *file,
992 const char *attributes,
993 GFileQueryInfoFlags flags,
994 GCancellable *cancellable,
999 g_return_val_if_fail (G_IS_FILE (file), NULL);
1001 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1004 iface = G_FILE_GET_IFACE (file);
1006 if (iface->query_info == NULL)
1008 g_set_error (error, G_IO_ERROR,
1009 G_IO_ERROR_NOT_SUPPORTED,
1010 _("Operation not supported"));
1014 return (* iface->query_info) (file, attributes, flags, cancellable, error);
1018 * g_file_query_info_async:
1019 * @file: input #GFile.
1020 * @attributes: an attribute query string.
1021 * @flags: a set of #GFileQueryInfoFlags.
1022 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1024 * @cancellable: optional #GCancellable object, %NULL to ignore.
1025 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1026 * @user_data: the data to pass to callback function
1028 * Asynchronously gets the requested information about specified @file. The result
1029 * is a #GFileInfo object that contains key-value attributes (such as type or size
1032 * For more details, see g_file_query_info() which is
1033 * the synchronous version of this call.
1035 * When the operation is finished, @callback will be called. You can then call
1036 * g_file_query_info_finish() to get the result of the operation.
1039 g_file_query_info_async (GFile *file,
1040 const char *attributes,
1041 GFileQueryInfoFlags flags,
1043 GCancellable *cancellable,
1044 GAsyncReadyCallback callback,
1049 g_return_if_fail (G_IS_FILE (file));
1051 iface = G_FILE_GET_IFACE (file);
1052 (* iface->query_info_async) (file,
1062 * g_file_query_info_finish:
1063 * @file: input #GFile.
1064 * @res: a #GAsyncResult.
1065 * @error: a #GError.
1067 * Finishes an asynchronous file info query.
1068 * See g_file_query_info_async().
1070 * Returns: #GFileInfo for given @file or %NULL on error.
1073 g_file_query_info_finish (GFile *file,
1079 g_return_val_if_fail (G_IS_FILE (file), NULL);
1080 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1082 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1084 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1085 if (g_simple_async_result_propagate_error (simple, error))
1089 iface = G_FILE_GET_IFACE (file);
1090 return (* iface->query_info_finish) (file, res, error);
1094 * g_file_query_filesystem_info:
1095 * @file: input #GFile.
1096 * @attributes: an attribute query string.
1097 * @cancellable: optional #GCancellable object, %NULL to ignore.
1098 * @error: a #GError.
1100 * Similar to g_file_query_info(), but obtains information
1101 * about the filesystem the @file is on, rather than the file itself.
1102 * For instance the amount of space available and the type of
1105 * The @attribute value is a string that specifies the file attributes that
1106 * should be gathered. It is not an error if it's not possible to read a particular
1107 * requested attribute from a file - it just won't be set. @attribute should
1108 * be a comma-separated list of attribute or attribute wildcards. The wildcard "*"
1109 * means all attributes, and a wildcard like "fs:*" means all attributes in the fs
1110 * namespace. The standard namespace for filesystem attributes is "fs".
1111 * Common attributes of interest are #G_FILE_ATTRIBUTE_FILESYSTEM_SIZE
1112 * (the total size of the filesystem in bytes), #G_FILE_ATTRIBUTE_FILESYSTEM_FREE (number of
1113 * bytes available), and #G_FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).
1115 * If @cancellable is not %NULL, then the operation can be cancelled by
1116 * triggering the cancellable object from another thread. If the operation
1117 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1119 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1120 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1122 * Returns: a #GFileInfo or %NULL if there was an error.
1125 g_file_query_filesystem_info (GFile *file,
1126 const char *attributes,
1127 GCancellable *cancellable,
1132 g_return_val_if_fail (G_IS_FILE (file), NULL);
1134 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1137 iface = G_FILE_GET_IFACE (file);
1139 if (iface->query_filesystem_info == NULL)
1141 g_set_error (error, G_IO_ERROR,
1142 G_IO_ERROR_NOT_SUPPORTED,
1143 _("Operation not supported"));
1147 return (* iface->query_filesystem_info) (file, attributes, cancellable, error);
1151 * g_file_find_enclosing_mount:
1152 * @file: input #GFile.
1153 * @cancellable: optional #GCancellable object, %NULL to ignore.
1154 * @error: a #GError.
1156 * Gets a #GMount for the #GFile.
1158 * If the #GFileIface for @file does not have a mount (e.g. possibly a
1159 * remote share), @error will be set to %G_IO_ERROR_NOT_FOUND and %NULL
1162 * If @cancellable is not %NULL, then the operation can be cancelled by
1163 * triggering the cancellable object from another thread. If the operation
1164 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1166 * Returns: a #GMount where the @file is located or %NULL on error.
1169 g_file_find_enclosing_mount (GFile *file,
1170 GCancellable *cancellable,
1175 g_return_val_if_fail (G_IS_FILE (file), NULL);
1177 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1180 iface = G_FILE_GET_IFACE (file);
1181 if (iface->find_enclosing_mount == NULL)
1183 g_set_error (error, G_IO_ERROR,
1184 G_IO_ERROR_NOT_FOUND,
1185 _("Containing mount does not exist"));
1189 return (* iface->find_enclosing_mount) (file, cancellable, error);
1192 * g_file_find_enclosing_mount_async:
1194 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1196 * @cancellable: optional #GCancellable object, %NULL to ignore.
1197 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1198 * @user_data: the data to pass to callback function
1200 * Asynchronously gets the mount for the file.
1202 * For more details, see g_file_find_enclosing_mount() which is
1203 * the synchronous version of this call.
1205 * When the operation is finished, @callback will be called. You can then call
1206 * g_file_find_enclosing_mount_finish() to get the result of the operation.
1209 g_file_find_enclosing_mount_async (GFile *file,
1211 GCancellable *cancellable,
1212 GAsyncReadyCallback callback,
1217 g_return_if_fail (G_IS_FILE (file));
1219 iface = G_FILE_GET_IFACE (file);
1220 (* iface->find_enclosing_mount_async) (file,
1228 * g_file_find_enclosing_mount_finish:
1230 * @res: a #GAsyncResult
1233 * Finishes an asynchronous find mount request.
1234 * See g_file_find_enclosing_mount_async().
1236 * Returns: #GMount for given @file or %NULL on error.
1239 g_file_find_enclosing_mount_finish (GFile *file,
1245 g_return_val_if_fail (G_IS_FILE (file), NULL);
1246 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1248 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1250 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1251 if (g_simple_async_result_propagate_error (simple, error))
1255 iface = G_FILE_GET_IFACE (file);
1256 return (* iface->find_enclosing_mount_finish) (file, res, error);
1262 * @file: #GFile to read.
1263 * @cancellable: a #GCancellable
1264 * @error: a #GError, or %NULL
1266 * Opens a file for reading. The result is a #GFileInputStream that
1267 * can be used to read the contents of the file.
1269 * If @cancellable is not %NULL, then the operation can be cancelled by
1270 * triggering the cancellable object from another thread. If the operation
1271 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1273 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1274 * If the file is a directory, the G_IO_ERROR_IS_DIRECTORY error will be returned.
1275 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1277 * Returns: #GFileInputStream or %NULL on error.
1280 g_file_read (GFile *file,
1281 GCancellable *cancellable,
1286 g_return_val_if_fail (G_IS_FILE (file), NULL);
1288 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1291 iface = G_FILE_GET_IFACE (file);
1293 if (iface->read_fn == NULL)
1295 g_set_error (error, G_IO_ERROR,
1296 G_IO_ERROR_NOT_SUPPORTED,
1297 _("Operation not supported"));
1301 return (* iface->read_fn) (file, cancellable, error);
1306 * @file: input #GFile.
1307 * @flags: a set of #GFileCreateFlags.
1308 * @cancellable: optional #GCancellable object, %NULL to ignore.
1309 * @error: a #GError, or %NULL
1311 * Gets an output stream for appending data to the file. If
1312 * the file doesn't already exist it is created.
1314 * By default files created are generally readable by everyone,
1315 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1316 * will be made readable only to the current user, to the level that
1317 * is supported on the target filesystem.
1319 * If @cancellable is not %NULL, then the operation can be cancelled by
1320 * triggering the cancellable object from another thread. If the operation
1321 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1323 * Some file systems don't allow all file names, and may
1324 * return an G_IO_ERROR_INVALID_FILENAME error.
1325 * If the file is a directory the G_IO_ERROR_IS_DIRECTORY error will be
1326 * returned. Other errors are possible too, and depend on what kind of
1327 * filesystem the file is on.
1329 * Returns: a #GFileOutputStream.
1332 g_file_append_to (GFile *file,
1333 GFileCreateFlags flags,
1334 GCancellable *cancellable,
1339 g_return_val_if_fail (G_IS_FILE (file), NULL);
1341 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1344 iface = G_FILE_GET_IFACE (file);
1346 if (iface->append_to == NULL)
1348 g_set_error (error, G_IO_ERROR,
1349 G_IO_ERROR_NOT_SUPPORTED,
1350 _("Operation not supported"));
1354 return (* iface->append_to) (file, flags, cancellable, error);
1359 * @file: input #GFile.
1360 * @flags: a set of #GFileCreateFlags.
1361 * @cancellable: optional #GCancellable object, %NULL to ignore.
1362 * @error: a #GError, or %NULL
1364 * Creates a new file and returns an output stream for writing to it.
1365 * The file must not already exists.
1367 * By default files created are generally readable by everyone,
1368 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1369 * will be made readable only to the current user, to the level that
1370 * is supported on the target filesystem.
1372 * If @cancellable is not %NULL, then the operation can be cancelled by
1373 * triggering the cancellable object from another thread. If the operation
1374 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1376 * If a file or directory with this name already exists the G_IO_ERROR_EXISTS
1377 * error will be returned.
1378 * Some file systems don't allow all file names, and may
1379 * return an G_IO_ERROR_INVALID_FILENAME error, and if the name
1380 * is to long G_IO_ERROR_FILENAME_TOO_LONG will be returned.
1381 * Other errors are possible too, and depend on what kind of
1382 * filesystem the file is on.
1384 * Returns: a #GFileOutputStream for the newly created file, or
1388 g_file_create (GFile *file,
1389 GFileCreateFlags flags,
1390 GCancellable *cancellable,
1395 g_return_val_if_fail (G_IS_FILE (file), NULL);
1397 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1400 iface = G_FILE_GET_IFACE (file);
1402 if (iface->create == NULL)
1404 g_set_error (error, G_IO_ERROR,
1405 G_IO_ERROR_NOT_SUPPORTED,
1406 _("Operation not supported"));
1410 return (* iface->create) (file, flags, cancellable, error);
1415 * @file: input #GFile.
1416 * @etag: an optional <link linkend="gfile-etag">entity tag</link> for the
1417 * current #GFile, or #NULL to ignore.
1418 * @make_backup: %TRUE if a backup should be created.
1419 * @flags: a set of #GFileCreateFlags.
1420 * @cancellable: optional #GCancellable object, %NULL to ignore.
1421 * @error: a #GError, or %NULL
1423 * Returns an output stream for overwriting the file, possibly
1424 * creating a backup copy of the file first.
1426 * This will try to replace the file in the safest way possible so
1427 * that any errors during the writing will not affect an already
1428 * existing copy of the file. For instance, for local files it
1429 * may write to a temporary file and then atomically rename over
1430 * the destination when the stream is closed.
1432 * By default files created are generally readable by everyone,
1433 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1434 * will be made readable only to the current user, to the level that
1435 * is supported on the target filesystem.
1437 * If @cancellable is not %NULL, then the operation can be cancelled by
1438 * triggering the cancellable object from another thread. If the operation
1439 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1441 * If you pass in a non-#NULL @etag value, then this value is
1442 * compared to the current entity tag of the file, and if they differ
1443 * an G_IO_ERROR_WRONG_ETAG error is returned. This generally means
1444 * that the file has been changed since you last read it. You can get
1445 * the new etag from g_file_output_stream_get_etag() after you've
1446 * finished writing and closed the #GFileOutputStream. When you load
1447 * a new file you can use g_file_input_stream_query_info() to get
1448 * the etag of the file.
1450 * If @make_backup is %TRUE, this function will attempt to make a backup
1451 * of the current file before overwriting it. If this fails a G_IO_ERROR_CANT_CREATE_BACKUP
1452 * error will be returned. If you want to replace anyway, try again with
1453 * @make_backup set to %FALSE.
1455 * If the file is a directory the G_IO_ERROR_IS_DIRECTORY error will be returned,
1456 * and if the file is some other form of non-regular file then a
1457 * G_IO_ERROR_NOT_REGULAR_FILE error will be returned.
1458 * Some file systems don't allow all file names, and may
1459 * return an G_IO_ERROR_INVALID_FILENAME error, and if the name
1460 * is to long G_IO_ERROR_FILENAME_TOO_LONG will be returned.
1461 * Other errors are possible too, and depend on what kind of
1462 * filesystem the file is on.
1464 * Returns: a #GFileOutputStream or %NULL on error.
1467 g_file_replace (GFile *file,
1469 gboolean make_backup,
1470 GFileCreateFlags flags,
1471 GCancellable *cancellable,
1476 g_return_val_if_fail (G_IS_FILE (file), NULL);
1478 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1481 iface = G_FILE_GET_IFACE (file);
1483 if (iface->replace == NULL)
1485 g_set_error (error, G_IO_ERROR,
1486 G_IO_ERROR_NOT_SUPPORTED,
1487 _("Operation not supported"));
1492 /* Handle empty tag string as NULL in consistent way. */
1493 if (etag && *etag == 0)
1496 return (* iface->replace) (file, etag, make_backup, flags, cancellable, error);
1500 * g_file_read_async:
1501 * @file: input #GFile.
1502 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1504 * @cancellable: optional #GCancellable object, %NULL to ignore.
1505 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1506 * @user_data: the data to pass to callback function
1508 * Asynchronously opens @file for reading.
1510 * For more details, see g_file_read() which is
1511 * the synchronous version of this call.
1513 * When the operation is finished, @callback will be called. You can then call
1514 * g_file_read_finish() to get the result of the operation.
1517 g_file_read_async (GFile *file,
1519 GCancellable *cancellable,
1520 GAsyncReadyCallback callback,
1525 g_return_if_fail (G_IS_FILE (file));
1527 iface = G_FILE_GET_IFACE (file);
1528 (* iface->read_async) (file,
1536 * g_file_read_finish:
1537 * @file: input #GFile.
1538 * @res: a #GAsyncResult.
1539 * @error: a #GError, or %NULL
1541 * Finishes an asynchronous file read operation started with
1542 * g_file_read_async().
1544 * Returns: a #GFileInputStream or %NULL on error.
1547 g_file_read_finish (GFile *file,
1553 g_return_val_if_fail (G_IS_FILE (file), NULL);
1554 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1556 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1558 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1559 if (g_simple_async_result_propagate_error (simple, error))
1563 iface = G_FILE_GET_IFACE (file);
1564 return (* iface->read_finish) (file, res, error);
1568 * g_file_append_to_async:
1569 * @file: input #GFile.
1570 * @flags: a set of #GFileCreateFlags.
1571 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1573 * @cancellable: optional #GCancellable object, %NULL to ignore.
1574 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1575 * @user_data: the data to pass to callback function
1577 * Asynchronously opens @file for appending.
1579 * For more details, see g_file_append_to() which is
1580 * the synchronous version of this call.
1582 * When the operation is finished, @callback will be called. You can then call
1583 * g_file_append_to_finish() to get the result of the operation.
1586 g_file_append_to_async (GFile *file,
1587 GFileCreateFlags flags,
1589 GCancellable *cancellable,
1590 GAsyncReadyCallback callback,
1595 g_return_if_fail (G_IS_FILE (file));
1597 iface = G_FILE_GET_IFACE (file);
1598 (* iface->append_to_async) (file,
1607 * g_file_append_to_finish:
1608 * @file: input #GFile.
1609 * @res: #GAsyncResult
1610 * @error: a #GError, or %NULL
1612 * Finishes an asynchronous file append operation started with
1613 * g_file_append_to_async().
1615 * Returns: a valid #GFileOutputStream or %NULL on error.
1618 g_file_append_to_finish (GFile *file,
1624 g_return_val_if_fail (G_IS_FILE (file), NULL);
1625 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1627 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1629 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1630 if (g_simple_async_result_propagate_error (simple, error))
1634 iface = G_FILE_GET_IFACE (file);
1635 return (* iface->append_to_finish) (file, res, error);
1639 * g_file_create_async:
1640 * @file: input #GFile.
1641 * @flags: a set of #GFileCreateFlags.
1642 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1644 * @cancellable: optional #GCancellable object, %NULL to ignore.
1645 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1646 * @user_data: the data to pass to callback function
1648 * Asynchronously creates a new file and returns an output stream for writing to it.
1649 * The file must not already exists.
1651 * For more details, see g_file_create() which is
1652 * the synchronous version of this call.
1654 * When the operation is finished, @callback will be called. You can then call
1655 * g_file_create_finish() to get the result of the operation.
1658 g_file_create_async (GFile *file,
1659 GFileCreateFlags flags,
1661 GCancellable *cancellable,
1662 GAsyncReadyCallback callback,
1667 g_return_if_fail (G_IS_FILE (file));
1669 iface = G_FILE_GET_IFACE (file);
1670 (* iface->create_async) (file,
1679 * g_file_create_finish:
1680 * @file: input #GFile.
1681 * @res: a #GAsyncResult.
1682 * @error: a #GError, or %NULL
1684 * Finishes an asynchronous file create operation started with
1685 * g_file_create_async().
1687 * Returns: a #GFileOutputStream or %NULL on error.
1690 g_file_create_finish (GFile *file,
1696 g_return_val_if_fail (G_IS_FILE (file), NULL);
1697 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1699 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1701 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1702 if (g_simple_async_result_propagate_error (simple, error))
1706 iface = G_FILE_GET_IFACE (file);
1707 return (* iface->create_finish) (file, res, error);
1711 * g_file_replace_async:
1712 * @file: input #GFile.
1713 * @etag: an <link linkend="gfile-etag">entity tag</link> for the
1714 * current #GFile, or NULL to ignore.
1715 * @make_backup: %TRUE if a backup should be created.
1716 * @flags: a set of #GFileCreateFlags.
1717 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1719 * @cancellable: optional #GCancellable object, %NULL to ignore.
1720 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1721 * @user_data: the data to pass to callback function
1723 * Asynchronously overwrites the file, replacing the contents, possibly
1724 * creating a backup copy of the file first.
1726 * For more details, see g_file_replace() which is
1727 * the synchronous version of this call.
1729 * When the operation is finished, @callback will be called. You can then call
1730 * g_file_replace_finish() to get the result of the operation.
1733 g_file_replace_async (GFile *file,
1735 gboolean make_backup,
1736 GFileCreateFlags flags,
1738 GCancellable *cancellable,
1739 GAsyncReadyCallback callback,
1744 g_return_if_fail (G_IS_FILE (file));
1746 iface = G_FILE_GET_IFACE (file);
1747 (* iface->replace_async) (file,
1758 * g_file_replace_finish:
1759 * @file: input #GFile.
1760 * @res: a #GAsyncResult.
1761 * @error: a #GError, or %NULL
1763 * Finishes an asynchronous file replace operation started with
1764 * g_file_replace_async().
1766 * Returns: a #GFileOutputStream, or %NULL on error.
1769 g_file_replace_finish (GFile *file,
1775 g_return_val_if_fail (G_IS_FILE (file), NULL);
1776 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1778 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1780 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1781 if (g_simple_async_result_propagate_error (simple, error))
1785 iface = G_FILE_GET_IFACE (file);
1786 return (* iface->replace_finish) (file, res, error);
1790 copy_symlink (GFile *destination,
1791 GFileCopyFlags flags,
1792 GCancellable *cancellable,
1797 gboolean tried_delete;
1799 GFileType file_type;
1801 tried_delete = FALSE;
1805 if (!g_file_make_symbolic_link (destination, target, cancellable, &my_error))
1807 /* Maybe it already existed, and we want to overwrite? */
1808 if (!tried_delete && (flags & G_FILE_COPY_OVERWRITE) &&
1809 my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_EXISTS)
1811 g_error_free (my_error);
1814 /* Don't overwrite if the destination is a directory */
1815 info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
1816 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
1817 cancellable, &my_error);
1820 file_type = g_file_info_get_file_type (info);
1821 g_object_unref (info);
1823 if (file_type == G_FILE_TYPE_DIRECTORY)
1825 g_set_error (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY,
1826 _("Can't copy over directory"));
1831 if (!g_file_delete (destination, cancellable, error))
1834 tried_delete = TRUE;
1838 g_propagate_error (error, my_error);
1845 static GInputStream *
1846 open_source_for_copy (GFile *source,
1848 GFileCopyFlags flags,
1849 GCancellable *cancellable,
1855 GFileType file_type;
1858 in = (GInputStream *)g_file_read (source, cancellable, &my_error);
1862 /* There was an error opening the source, try to set a good error for it: */
1864 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_IS_DIRECTORY)
1866 /* The source is a directory, don't fail with WOULD_RECURSE immediately,
1867 * as that is less useful to the app. Better check for errors on the
1870 g_error_free (my_error);
1873 info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
1874 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
1875 cancellable, &my_error);
1878 file_type = g_file_info_get_file_type (info);
1879 g_object_unref (info);
1881 if (flags & G_FILE_COPY_OVERWRITE)
1883 if (file_type == G_FILE_TYPE_DIRECTORY)
1885 g_set_error (error, G_IO_ERROR, G_IO_ERROR_WOULD_MERGE,
1886 _("Can't copy directory over directory"));
1889 /* continue to would_recurse error */
1893 g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
1894 _("Target file exists"));
1900 /* Error getting info from target, return that error
1901 * (except for NOT_FOUND, which is no error here)
1903 if (my_error->domain != G_IO_ERROR && my_error->code != G_IO_ERROR_NOT_FOUND)
1905 g_propagate_error (error, my_error);
1908 g_error_free (my_error);
1911 g_set_error (error, G_IO_ERROR, G_IO_ERROR_WOULD_RECURSE,
1912 _("Can't recursively copy directory"));
1916 g_propagate_error (error, my_error);
1921 should_copy (GFileAttributeInfo *info,
1925 return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED;
1926 return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE;
1930 build_attribute_list_for_copy (GFileAttributeInfoList *attributes,
1931 GFileAttributeInfoList *namespaces,
1939 s = g_string_new ("");
1943 for (i = 0; i < attributes->n_infos; i++)
1945 if (should_copy (&attributes->infos[i], as_move))
1950 g_string_append_c (s, ',');
1952 g_string_append (s, attributes->infos[i].name);
1959 for (i = 0; i < namespaces->n_infos; i++)
1961 if (should_copy (&namespaces->infos[i], as_move))
1966 g_string_append_c (s, ',');
1968 g_string_append (s, namespaces->infos[i].name);
1969 g_string_append (s, ":*");
1974 return g_string_free (s, FALSE);
1978 * g_file_copy_attributes:
1979 * @source: a #GFile with attributes.
1980 * @destination: a #GFile to copy attributes to.
1981 * @flags: a set of #GFileCopyFlags.
1982 * @cancellable: optional #GCancellable object, %NULL to ignore.
1983 * @error: a #GError, %NULL to ignore.
1985 * Copies the file attributes from @source to @destination.
1987 * Normally only a subset of the file attributes are copied,
1988 * those that are copies in a normal file copy operation
1989 * (which for instance does not include e.g. mtime). However
1990 * if #G_FILE_COPY_ALL_METADATA is specified in @flags, then
1991 * all the metadata that is possible to copy is copied.
1993 * Returns: %TRUE if the attributes were copied successfully, %FALSE otherwise.
1996 g_file_copy_attributes (GFile *source,
1998 GFileCopyFlags flags,
1999 GCancellable *cancellable,
2002 GFileAttributeInfoList *attributes, *namespaces;
2003 char *attrs_to_read;
2007 gboolean source_nofollow_symlinks;
2009 as_move = flags & G_FILE_COPY_ALL_METADATA;
2010 source_nofollow_symlinks = flags & G_FILE_COPY_NOFOLLOW_SYMLINKS;
2012 /* Ignore errors here, if the target supports no attributes there is nothing to copy */
2013 attributes = g_file_query_settable_attributes (destination, cancellable, NULL);
2014 namespaces = g_file_query_writable_namespaces (destination, cancellable, NULL);
2016 if (attributes == NULL && namespaces == NULL)
2019 attrs_to_read = build_attribute_list_for_copy (attributes, namespaces, as_move);
2021 /* Ignore errors here, if we can't read some info (e.g. if it doesn't exist)
2022 * we just don't copy it.
2024 info = g_file_query_info (source, attrs_to_read,
2025 source_nofollow_symlinks ? G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS:0,
2029 g_free (attrs_to_read);
2034 res = g_file_set_attributes_from_info (destination,
2038 g_object_unref (info);
2041 g_file_attribute_info_list_unref (attributes);
2042 g_file_attribute_info_list_unref (namespaces);
2047 /* Closes the streams */
2049 copy_stream_with_progress (GInputStream *in,
2051 GCancellable *cancellable,
2052 GFileProgressCallback progress_callback,
2053 gpointer progress_callback_data,
2056 gssize n_read, n_written;
2057 goffset current_size;
2058 char buffer[8192], *p;
2064 info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (in),
2065 G_FILE_ATTRIBUTE_STANDARD_SIZE,
2069 total_size = g_file_info_get_size (info);
2070 g_object_unref (info);
2077 n_read = g_input_stream_read (in, buffer, sizeof (buffer), cancellable, error);
2087 current_size += n_read;
2092 n_written = g_output_stream_write (out, p, n_read, cancellable, error);
2093 if (n_written == -1)
2100 n_read -= n_written;
2106 if (progress_callback)
2107 progress_callback (current_size, total_size, progress_callback_data);
2111 error = NULL; /* Ignore further errors */
2113 /* Make sure we send full copied size */
2114 if (progress_callback)
2115 progress_callback (current_size, total_size, progress_callback_data);
2118 /* Don't care about errors in source here */
2119 g_input_stream_close (in, cancellable, NULL);
2121 /* But write errors on close are bad! */
2122 if (!g_output_stream_close (out, cancellable, error))
2125 g_object_unref (in);
2126 g_object_unref (out);
2132 file_copy_fallback (GFile *source,
2134 GFileCopyFlags flags,
2135 GCancellable *cancellable,
2136 GFileProgressCallback progress_callback,
2137 gpointer progress_callback_data,
2145 /* Maybe copy the symlink? */
2146 if (flags & G_FILE_COPY_NOFOLLOW_SYMLINKS)
2148 info = g_file_query_info (source,
2149 G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
2150 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2156 if (g_file_info_get_file_type (info) == G_FILE_TYPE_SYMBOLIC_LINK &&
2157 (target = g_file_info_get_symlink_target (info)) != NULL)
2159 if (!copy_symlink (destination, flags, cancellable, target, error))
2161 g_object_unref (info);
2165 g_object_unref (info);
2169 g_object_unref (info);
2172 in = open_source_for_copy (source, destination, flags, cancellable, error);
2176 if (flags & G_FILE_COPY_OVERWRITE)
2178 out = (GOutputStream *)g_file_replace (destination,
2180 flags & G_FILE_COPY_BACKUP,
2181 cancellable, error);
2185 out = (GOutputStream *)g_file_create (destination, 0, cancellable, error);
2190 g_object_unref (in);
2194 if (!copy_stream_with_progress (in, out, cancellable,
2195 progress_callback, progress_callback_data,
2201 /* Ignore errors here. Failure to copy metadata is not a hard error */
2202 g_file_copy_attributes (source, destination,
2203 flags, cancellable, NULL);
2210 * @source: input #GFile.
2211 * @destination: destination #GFile
2212 * @flags: set of #GFileCopyFlags
2213 * @cancellable: optional #GCancellable object, %NULL to ignore.
2214 * @progress_callback: function to callback with progress information
2215 * @progress_callback_data: user data to pass to @progress_callback
2216 * @error: #GError to set on error, or %NULL
2218 * Copies the file @source to the location specified by @destination.
2219 * Can not handle recursive copies of directories.
2221 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
2222 * existing @destination file is overwritten.
2224 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
2225 * will be copied as symlinks, otherwise the target of the
2226 * @source symlink will be copied.
2228 * If @cancellable is not %NULL, then the operation can be cancelled by
2229 * triggering the cancellable object from another thread. If the operation
2230 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
2232 * If @progress_callback is not %NULL, then the operation can be monitored by
2233 * setting this to a #GFileProgressCallback function. @progress_callback_data
2234 * will be passed to this function. It is guaranteed that this callback will
2235 * be called after all data has been transferred with the total number of bytes
2236 * copied during the operation.
2238 * If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
2239 * error is returned, independent on the status of the @destination.
2241 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then the
2242 * error G_IO_ERROR_EXISTS is returned.
2244 * If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY
2245 * error is returned. If trying to overwrite a directory with a directory the
2246 * G_IO_ERROR_WOULD_MERGE error is returned.
2248 * If the source is a directory and the target does not exist, or #G_FILE_COPY_OVERWRITE is
2249 * specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error
2252 * If you are interested in copying the #GFile object itself (not the on-disk
2253 * file), see g_file_dup().
2255 * Returns: %TRUE on success, %FALSE otherwise.
2258 g_file_copy (GFile *source,
2260 GFileCopyFlags flags,
2261 GCancellable *cancellable,
2262 GFileProgressCallback progress_callback,
2263 gpointer progress_callback_data,
2270 g_return_val_if_fail (G_IS_FILE (source), FALSE);
2271 g_return_val_if_fail (G_IS_FILE (destination), FALSE);
2273 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2276 iface = G_FILE_GET_IFACE (destination);
2280 res = (* iface->copy) (source, destination,
2282 progress_callback, progress_callback_data,
2288 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
2290 g_propagate_error (error, my_error);
2295 /* If the types are different, and the destination method failed
2296 also try the source method */
2297 if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
2299 iface = G_FILE_GET_IFACE (source);
2304 res = (* iface->copy) (source, destination,
2306 progress_callback, progress_callback_data,
2312 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
2314 g_propagate_error (error, my_error);
2320 return file_copy_fallback (source, destination, flags, cancellable,
2321 progress_callback, progress_callback_data,
2326 * g_file_copy_async:
2327 * @source: input #GFile.
2328 * @destination: destination #GFile
2329 * @flags: set of #GFileCopyFlags
2330 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2332 * @cancellable: optional #GCancellable object, %NULL to ignore.
2333 * @progress_callback: function to callback with progress information
2334 * @progress_callback_data: user data to pass to @progress_callback
2335 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
2336 * @user_data: the data to pass to callback function
2338 * Copies the file @source to the location specified by @destination
2339 * asynchronously. For details of the behaviour, see g_file_copy().
2341 * If @progress_callback is not %NULL, then that function that will be called
2342 * just like in g_file_copy(), however the callback will run in the main loop,
2343 * not in the thread that is doing the I/O operation.
2345 * When the operation is finished, @callback will be called. You can then call
2346 * g_file_copy_finish() to get the result of the operation.
2349 g_file_copy_async (GFile *source,
2351 GFileCopyFlags flags,
2353 GCancellable *cancellable,
2354 GFileProgressCallback progress_callback,
2355 gpointer progress_callback_data,
2356 GAsyncReadyCallback callback,
2361 g_return_if_fail (G_IS_FILE (source));
2362 g_return_if_fail (G_IS_FILE (destination));
2364 iface = G_FILE_GET_IFACE (source);
2365 (* iface->copy_async) (source,
2371 progress_callback_data,
2377 * g_file_copy_finish:
2378 * @file: input #GFile.
2379 * @res: a #GAsyncResult.
2380 * @error: a #GError, or %NULL
2382 * Finishes copying the file started with
2383 * g_file_copy_async().
2385 * Returns: a %TRUE on success, %FALSE on error.
2388 g_file_copy_finish (GFile *file,
2394 g_return_val_if_fail (G_IS_FILE (file), FALSE);
2395 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
2397 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2399 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2401 if (g_simple_async_result_propagate_error (simple, error))
2405 iface = G_FILE_GET_IFACE (file);
2406 return (* iface->copy_finish) (file, res, error);
2411 * @source: #GFile pointing to the source location.
2412 * @destination: #GFile pointing to the destination location.
2413 * @flags: set of #GFileCopyFlags.
2414 * @cancellable: optional #GCancellable object, %NULL to ignore.
2415 * @progress_callback: #GFileProgressCallback function for updates.
2416 * @progress_callback_data: gpointer to user data for the callback function.
2417 * @error: #GError for returning error conditions, or %NULL
2420 * Tries to move the file or directory @source to the location specified by @destination.
2421 * If native move operations are supported then this is used, otherwise a copy + delete
2422 * fallback is used. The native implementation may support moving directories (for instance
2423 * on moves inside the same filesystem), but the fallback code does not.
2425 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
2426 * existing @destination file is overwritten.
2428 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
2429 * will be copied as symlinks, otherwise the target of the
2430 * @source symlink will be copied.
2432 * If @cancellable is not %NULL, then the operation can be cancelled by
2433 * triggering the cancellable object from another thread. If the operation
2434 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
2436 * If @progress_callback is not %NULL, then the operation can be monitored by
2437 * setting this to a #GFileProgressCallback function. @progress_callback_data
2438 * will be passed to this function. It is guaranteed that this callback will
2439 * be called after all data has been transferred with the total number of bytes
2440 * copied during the operation.
2442 * If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
2443 * error is returned, independent on the status of the @destination.
2445 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then the
2446 * error G_IO_ERROR_EXISTS is returned.
2448 * If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY
2449 * error is returned. If trying to overwrite a directory with a directory the
2450 * G_IO_ERROR_WOULD_MERGE error is returned.
2452 * If the source is a directory and the target does not exist, or #G_FILE_COPY_OVERWRITE is
2453 * specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error
2454 * may be returned (if the native move operation isn't available).
2456 * Returns: %TRUE on successful move, %FALSE otherwise.
2459 g_file_move (GFile *source,
2461 GFileCopyFlags flags,
2462 GCancellable *cancellable,
2463 GFileProgressCallback progress_callback,
2464 gpointer progress_callback_data,
2471 g_return_val_if_fail (G_IS_FILE (source), FALSE);
2472 g_return_val_if_fail (G_IS_FILE (destination), FALSE);
2474 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2477 iface = G_FILE_GET_IFACE (destination);
2481 res = (* iface->move) (source, destination,
2483 progress_callback, progress_callback_data,
2489 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
2491 g_propagate_error (error, my_error);
2496 /* If the types are different, and the destination method failed
2497 also try the source method */
2498 if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
2500 iface = G_FILE_GET_IFACE (source);
2505 res = (* iface->move) (source, destination,
2507 progress_callback, progress_callback_data,
2513 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
2515 g_propagate_error (error, my_error);
2521 if (flags & G_FILE_COPY_NO_FALLBACK_FOR_MOVE)
2523 g_set_error (error, G_IO_ERROR,
2524 G_IO_ERROR_NOT_SUPPORTED,
2525 _("Operation not supported"));
2529 flags |= G_FILE_COPY_ALL_METADATA;
2530 if (!g_file_copy (source, destination, flags, cancellable,
2531 progress_callback, progress_callback_data,
2535 return g_file_delete (source, cancellable, error);
2539 * g_file_make_directory
2540 * @file: input #GFile.
2541 * @cancellable: optional #GCancellable object, %NULL to ignore.
2542 * @error: a #GError, or %NULL
2544 * Creates a directory.
2546 * If @cancellable is not %NULL, then the operation can be cancelled by
2547 * triggering the cancellable object from another thread. If the operation
2548 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
2550 * Returns: %TRUE on successful creation, %FALSE otherwise.
2553 g_file_make_directory (GFile *file,
2554 GCancellable *cancellable,
2559 g_return_val_if_fail (G_IS_FILE (file), FALSE);
2561 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2564 iface = G_FILE_GET_IFACE (file);
2566 if (iface->make_directory == NULL)
2568 g_set_error (error, G_IO_ERROR,
2569 G_IO_ERROR_NOT_SUPPORTED,
2570 _("Operation not supported"));
2574 return (* iface->make_directory) (file, cancellable, error);
2578 * g_file_make_symbolic_link:
2579 * @file: input #GFile.
2580 * @symlink_value: a string with the value of the new symlink.
2581 * @cancellable: optional #GCancellable object, %NULL to ignore.
2582 * @error: a #GError.
2584 * Creates a symbolic link.
2586 * If @cancellable is not %NULL, then the operation can be cancelled by
2587 * triggering the cancellable object from another thread. If the operation
2588 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
2590 * Returns: %TRUE on the creation of a new symlink, %FALSE otherwise.
2593 g_file_make_symbolic_link (GFile *file,
2594 const char *symlink_value,
2595 GCancellable *cancellable,
2600 g_return_val_if_fail (G_IS_FILE (file), FALSE);
2601 g_return_val_if_fail (symlink_value != NULL, FALSE);
2603 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2606 if (*symlink_value == '\0')
2608 g_set_error (error, G_IO_ERROR,
2609 G_IO_ERROR_INVALID_ARGUMENT,
2610 _("Invalid symlink value given"));
2614 iface = G_FILE_GET_IFACE (file);
2616 if (iface->make_symbolic_link == NULL)
2618 g_set_error (error, G_IO_ERROR,
2619 G_IO_ERROR_NOT_SUPPORTED,
2620 _("Operation not supported"));
2624 return (* iface->make_symbolic_link) (file, symlink_value, cancellable, error);
2629 * @file: input #GFile.
2630 * @cancellable: optional #GCancellable object, %NULL to ignore.
2631 * @error: a #GError, or %NULL
2635 * If @cancellable is not %NULL, then the operation can be cancelled by
2636 * triggering the cancellable object from another thread. If the operation
2637 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
2639 * Returns: %TRUE if the file was deleted. %FALSE otherwise.
2642 g_file_delete (GFile *file,
2643 GCancellable *cancellable,
2648 g_return_val_if_fail (G_IS_FILE (file), FALSE);
2650 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2653 iface = G_FILE_GET_IFACE (file);
2655 if (iface->delete_file == NULL)
2657 g_set_error (error, G_IO_ERROR,
2658 G_IO_ERROR_NOT_SUPPORTED,
2659 _("Operation not supported"));
2663 return (* iface->delete_file) (file, cancellable, error);
2668 * @file: #GFile to send to trash.
2669 * @cancellable: optional #GCancellable object, %NULL to ignore.
2670 * @error: a #GError, or %NULL
2672 * Sends @file to the "Trashcan", if possible. This is similar to
2673 * deleting it, but the user can recover it before emptying the trashcan.
2674 * Not all file systems support trashing, so this call can return the
2675 * %G_IO_ERROR_NOT_SUPPORTED error.
2678 * If @cancellable is not %NULL, then the operation can be cancelled by
2679 * triggering the cancellable object from another thread. If the operation
2680 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
2682 * Returns: %TRUE on successful trash, %FALSE otherwise.
2685 g_file_trash (GFile *file,
2686 GCancellable *cancellable,
2691 g_return_val_if_fail (G_IS_FILE (file), FALSE);
2693 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2696 iface = G_FILE_GET_IFACE (file);
2698 if (iface->trash == NULL)
2701 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2702 _("Trash not supported"));
2706 return (* iface->trash) (file, cancellable, error);
2710 * g_file_set_display_name:
2711 * @file: input #GFile.
2712 * @display_name: a string.
2713 * @cancellable: optional #GCancellable object, %NULL to ignore.
2714 * @error: a #GError, or %NULL
2716 * Renames @file to the specified display name.
2718 * The display name is converted from UTF8 to the correct encoding for the target
2719 * filesystem if possible and the @file is renamed to this.
2721 * If you want to implement a rename operation in the user interface the edit name
2722 * (#G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the initial value in the rename
2723 * widget, and then the result after editing should be passed to g_file_set_display_name().
2725 * On success the resulting converted filename is returned.
2727 * If @cancellable is not %NULL, then the operation can be cancelled by
2728 * triggering the cancellable object from another thread. If the operation
2729 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
2731 * Returns: a #GFile specifying what @file was renamed to, or %NULL if there was an error.
2734 g_file_set_display_name (GFile *file,
2735 const char *display_name,
2736 GCancellable *cancellable,
2741 g_return_val_if_fail (G_IS_FILE (file), NULL);
2742 g_return_val_if_fail (display_name != NULL, NULL);
2744 if (strchr (display_name, G_DIR_SEPARATOR) != NULL)
2748 G_IO_ERROR_INVALID_ARGUMENT,
2749 _("File names cannot contain '%c'"), G_DIR_SEPARATOR);
2753 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2756 iface = G_FILE_GET_IFACE (file);
2758 return (* iface->set_display_name) (file, display_name, cancellable, error);
2762 * g_file_set_display_name_async:
2763 * @file: input #GFile.
2764 * @display_name: a string.
2765 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2767 * @cancellable: optional #GCancellable object, %NULL to ignore.
2768 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
2769 * @user_data: the data to pass to callback function
2771 * Asynchronously sets the display name for a given #GFile.
2773 * For more details, see g_set_display_name() which is
2774 * the synchronous version of this call.
2776 * When the operation is finished, @callback will be called. You can then call
2777 * g_file_set_display_name_finish() to get the result of the operation.
2780 g_file_set_display_name_async (GFile *file,
2781 const char *display_name,
2783 GCancellable *cancellable,
2784 GAsyncReadyCallback callback,
2789 g_return_if_fail (G_IS_FILE (file));
2790 g_return_if_fail (display_name != NULL);
2792 iface = G_FILE_GET_IFACE (file);
2793 (* iface->set_display_name_async) (file,
2802 * g_file_set_display_name_finish:
2803 * @file: input #GFile.
2804 * @res: a #GAsyncResult.
2805 * @error: a #GError, or %NULL
2807 * Finishes setting a display name started with
2808 * g_file_set_display_name_async().
2810 * Returns: a #GFile or %NULL on error.
2813 g_file_set_display_name_finish (GFile *file,
2819 g_return_val_if_fail (G_IS_FILE (file), NULL);
2820 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2822 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2824 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2825 if (g_simple_async_result_propagate_error (simple, error))
2829 iface = G_FILE_GET_IFACE (file);
2830 return (* iface->set_display_name_finish) (file, res, error);
2834 * g_file_query_settable_attributes:
2835 * @file: input #GFile.
2836 * @cancellable: optional #GCancellable object, %NULL to ignore.
2837 * @error: a #GError, or %NULL
2839 * Obtain the list of settable attributes for the file.
2841 * Returns the type and full attribute name of all the attributes
2842 * that can be set on this file. This doesn't mean setting it will always
2843 * succeed though, you might get an access failure, or some specific
2844 * file may not support a specific attribute.
2846 * If @cancellable is not %NULL, then the operation can be cancelled by
2847 * triggering the cancellable object from another thread. If the operation
2848 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
2850 * Returns: a #GFileAttributeInfoList describing the settable attributes.
2851 * When you are done with it, release it with g_file_attribute_info_list_unref()
2853 GFileAttributeInfoList *
2854 g_file_query_settable_attributes (GFile *file,
2855 GCancellable *cancellable,
2860 GFileAttributeInfoList *list;
2862 g_return_val_if_fail (G_IS_FILE (file), NULL);
2864 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2867 iface = G_FILE_GET_IFACE (file);
2869 if (iface->query_settable_attributes == NULL)
2870 return g_file_attribute_info_list_new ();
2873 list = (* iface->query_settable_attributes) (file, cancellable, &my_error);
2877 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
2879 list = g_file_attribute_info_list_new ();
2880 g_error_free (my_error);
2883 g_propagate_error (error, my_error);
2890 * g_file_query_writable_namespaces:
2891 * @file: input #GFile.
2892 * @cancellable: optional #GCancellable object, %NULL to ignore.
2893 * @error: a #GError, or %NULL
2895 * Obtain the list of attribute namespaces where new attributes
2896 * can be created by a user. An example of this is extended
2897 * attributes (in the "xattr" namespace).
2899 * If @cancellable is not %NULL, then the operation can be cancelled by
2900 * triggering the cancellable object from another thread. If the operation
2901 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
2903 * Returns: a #GFileAttributeInfoList describing the writable namespaces.
2904 * When you are done with it, release it with g_file_attribute_info_list_unref()
2906 GFileAttributeInfoList *
2907 g_file_query_writable_namespaces (GFile *file,
2908 GCancellable *cancellable,
2913 GFileAttributeInfoList *list;
2915 g_return_val_if_fail (G_IS_FILE (file), NULL);
2917 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2920 iface = G_FILE_GET_IFACE (file);
2922 if (iface->query_writable_namespaces == NULL)
2923 return g_file_attribute_info_list_new ();
2926 list = (* iface->query_writable_namespaces) (file, cancellable, &my_error);
2930 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
2932 list = g_file_attribute_info_list_new ();
2933 g_error_free (my_error);
2936 g_propagate_error (error, my_error);
2943 * g_file_set_attribute:
2944 * @file: input #GFile.
2945 * @attribute: a string containing the attribute's name.
2946 * @type: The type of the attribute
2947 * @value_p: a pointer to the value (or the pointer itself if the type is a pointer type)
2948 * @flags: a set of #GFileQueryInfoFlags.
2949 * @cancellable: optional #GCancellable object, %NULL to ignore.
2950 * @error: a #GError, or %NULL
2952 * Sets an attribute in the file with attribute name @attribute to @value.
2954 * If @cancellable is not %NULL, then the operation can be cancelled by
2955 * triggering the cancellable object from another thread. If the operation
2956 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
2958 * Returns: %TRUE if the attribute was set, %FALSE otherwise.
2961 g_file_set_attribute (GFile *file,
2962 const char *attribute,
2963 GFileAttributeType type,
2965 GFileQueryInfoFlags flags,
2966 GCancellable *cancellable,
2971 g_return_val_if_fail (G_IS_FILE (file), FALSE);
2972 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
2974 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2977 iface = G_FILE_GET_IFACE (file);
2979 if (iface->set_attribute == NULL)
2981 g_set_error (error, G_IO_ERROR,
2982 G_IO_ERROR_NOT_SUPPORTED,
2983 _("Operation not supported"));
2987 return (* iface->set_attribute) (file, attribute, type, value_p, flags, cancellable, error);
2991 * g_file_set_attributes_from_info:
2992 * @file: input #GFile.
2993 * @info: a #GFileInfo.
2994 * @flags: #GFileQueryInfoFlags
2995 * @cancellable: optional #GCancellable object, %NULL to ignore.
2996 * @error: a #GError, or %NULL
2998 * Tries to set all attributes in the #GFileInfo on the target values,
2999 * not stopping on the first error.
3001 * If there is any error during this operation then @error will be set to
3002 * the first error. Error on particular fields are flagged by setting
3003 * the "status" field in the attribute value to
3004 * %G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can also detect
3007 * If @cancellable is not %NULL, then the operation can be cancelled by
3008 * triggering the cancellable object from another thread. If the operation
3009 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3011 * Returns: %TRUE if there was any error, %FALSE otherwise.
3014 g_file_set_attributes_from_info (GFile *file,
3016 GFileQueryInfoFlags flags,
3017 GCancellable *cancellable,
3022 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3023 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
3025 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3028 g_file_info_clear_status (info);
3030 iface = G_FILE_GET_IFACE (file);
3032 return (* iface->set_attributes_from_info) (file,
3041 g_file_real_set_attributes_from_info (GFile *file,
3043 GFileQueryInfoFlags flags,
3044 GCancellable *cancellable,
3050 GFileAttributeValue *value;
3054 attributes = g_file_info_list_attributes (info, NULL);
3056 for (i = 0; attributes[i] != NULL; i++)
3058 value = _g_file_info_get_attribute_value (info, attributes[i]);
3060 if (value->status != G_FILE_ATTRIBUTE_STATUS_UNSET)
3063 if (!g_file_set_attribute (file, attributes[i],
3064 value->type, _g_file_attribute_value_peek_as_pointer (value),
3065 flags, cancellable, error))
3067 value->status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
3069 /* Don't set error multiple times */
3073 value->status = G_FILE_ATTRIBUTE_STATUS_SET;
3076 g_strfreev (attributes);
3082 * g_file_set_attributes_async:
3083 * @file: input #GFile.
3084 * @info: a #GFileInfo.
3085 * @flags: a #GFileQueryInfoFlags.
3086 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3088 * @cancellable: optional #GCancellable object, %NULL to ignore.
3089 * @callback: a #GAsyncReadyCallback.
3090 * @user_data: a #gpointer.
3092 * Asynchronously sets the attributes of @file with @info.
3094 * For more details, see g_file_set_attributes_from_info() which is
3095 * the synchronous version of this call.
3097 * When the operation is finished, @callback will be called. You can then call
3098 * g_file_set_attributes_finish() to get the result of the operation.
3101 g_file_set_attributes_async (GFile *file,
3103 GFileQueryInfoFlags flags,
3105 GCancellable *cancellable,
3106 GAsyncReadyCallback callback,
3111 g_return_if_fail (G_IS_FILE (file));
3112 g_return_if_fail (G_IS_FILE_INFO (info));
3114 iface = G_FILE_GET_IFACE (file);
3115 (* iface->set_attributes_async) (file,
3125 * g_file_set_attributes_finish:
3126 * @file: input #GFile.
3127 * @result: a #GAsyncResult.
3128 * @info: a #GFileInfo.
3129 * @error: a #GError, or %NULL
3131 * Finishes setting an attribute started in g_file_set_attributes_async().
3133 * Returns: %TRUE if the attributes were set correctly, %FALSE otherwise.
3136 g_file_set_attributes_finish (GFile *file,
3137 GAsyncResult *result,
3143 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3144 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
3146 /* No standard handling of errors here, as we must set info even
3149 iface = G_FILE_GET_IFACE (file);
3150 return (* iface->set_attributes_finish) (file, result, info, error);
3154 * g_file_set_attribute_string:
3155 * @file: input #GFile.
3156 * @attribute: a string containing the attribute's name.
3157 * @value: a string containing the attribute's value.
3158 * @flags: #GFileQueryInfoFlags.
3159 * @cancellable: optional #GCancellable object, %NULL to ignore.
3160 * @error: a #GError, or %NULL
3162 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value.
3163 * If @attribute is of a different type, this operation will fail.
3165 * If @cancellable is not %NULL, then the operation can be cancelled by
3166 * triggering the cancellable object from another thread. If the operation
3167 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3169 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
3172 g_file_set_attribute_string (GFile *file,
3173 const char *attribute,
3175 GFileQueryInfoFlags flags,
3176 GCancellable *cancellable,
3179 return g_file_set_attribute (file, attribute,
3180 G_FILE_ATTRIBUTE_TYPE_STRING, (gpointer)value,
3181 flags, cancellable, error);
3185 * g_file_set_attribute_byte_string:
3186 * @file: input #GFile.
3187 * @attribute: a string containing the attribute's name.
3188 * @value: a string containing the attribute's new value.
3189 * @flags: a #GFileQueryInfoFlags.
3190 * @cancellable: optional #GCancellable object, %NULL to ignore.
3191 * @error: a #GError, or %NULL
3193 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value.
3194 * If @attribute is of a different type, this operation will fail,
3197 * If @cancellable is not %NULL, then the operation can be cancelled by
3198 * triggering the cancellable object from another thread. If the operation
3199 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3201 * Returns: %TRUE if the @attribute was successfully set to @value
3202 * in the @file, %FALSE otherwise.
3205 g_file_set_attribute_byte_string (GFile *file,
3206 const char *attribute,
3208 GFileQueryInfoFlags flags,
3209 GCancellable *cancellable,
3212 return g_file_set_attribute (file, attribute,
3213 G_FILE_ATTRIBUTE_TYPE_BYTE_STRING, (gpointer)value,
3214 flags, cancellable, error);
3218 * g_file_set_attribute_uint32:
3219 * @file: input #GFile.
3220 * @attribute: a string containing the attribute's name.
3221 * @value: a #guint32 containing the attribute's new value.
3222 * @flags: a #GFileQueryInfoFlags.
3223 * @cancellable: optional #GCancellable object, %NULL to ignore.
3224 * @error: a #GError, or %NULL
3226 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value.
3227 * If @attribute is of a different type, this operation will fail.
3229 * If @cancellable is not %NULL, then the operation can be cancelled by
3230 * triggering the cancellable object from another thread. If the operation
3231 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3233 * Returns: %TRUE if the @attribute was successfully set to @value
3234 * in the @file, %FALSE otherwise.
3237 g_file_set_attribute_uint32 (GFile *file,
3238 const char *attribute,
3240 GFileQueryInfoFlags flags,
3241 GCancellable *cancellable,
3244 return g_file_set_attribute (file, attribute,
3245 G_FILE_ATTRIBUTE_TYPE_UINT32, &value,
3246 flags, cancellable, error);
3250 * g_file_set_attribute_int32:
3251 * @file: input #GFile.
3252 * @attribute: a string containing the attribute's name.
3253 * @value: a #gint32 containing the attribute's new value.
3254 * @flags: a #GFileQueryInfoFlags.
3255 * @cancellable: optional #GCancellable object, %NULL to ignore.
3256 * @error: a #GError, or %NULL
3258 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value.
3259 * If @attribute is of a different type, this operation will fail.
3261 * If @cancellable is not %NULL, then the operation can be cancelled by
3262 * triggering the cancellable object from another thread. If the operation
3263 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3265 * Returns: %TRUE if the @attribute was successfully set to @value
3266 * in the @file, %FALSE otherwise.
3269 g_file_set_attribute_int32 (GFile *file,
3270 const char *attribute,
3272 GFileQueryInfoFlags flags,
3273 GCancellable *cancellable,
3276 return g_file_set_attribute (file, attribute,
3277 G_FILE_ATTRIBUTE_TYPE_INT32, &value,
3278 flags, cancellable, error);
3282 * g_file_set_attribute_uint64:
3283 * @file: input #GFile.
3284 * @attribute: a string containing the attribute's name.
3285 * @value: a #guint64 containing the attribute's new value.
3286 * @flags: a #GFileQueryInfoFlags.
3287 * @cancellable: optional #GCancellable object, %NULL to ignore.
3288 * @error: a #GError, or %NULL
3290 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value.
3291 * If @attribute is of a different type, this operation will fail.
3293 * If @cancellable is not %NULL, then the operation can be cancelled by
3294 * triggering the cancellable object from another thread. If the operation
3295 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3297 * Returns: %TRUE if the @attribute was successfully set to @value
3298 * in the @file, %FALSE otherwise.
3301 g_file_set_attribute_uint64 (GFile *file,
3302 const char *attribute,
3304 GFileQueryInfoFlags flags,
3305 GCancellable *cancellable,
3308 return g_file_set_attribute (file, attribute,
3309 G_FILE_ATTRIBUTE_TYPE_UINT64, &value,
3310 flags, cancellable, error);
3314 * g_file_set_attribute_int64:
3315 * @file: input #GFile.
3316 * @attribute: a string containing the attribute's name.
3317 * @value: a #guint64 containing the attribute's new value.
3318 * @flags: a #GFileQueryInfoFlags.
3319 * @cancellable: optional #GCancellable object, %NULL to ignore.
3320 * @error: a #GError, or %NULL
3322 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value.
3323 * If @attribute is of a different type, this operation will fail.
3325 * If @cancellable is not %NULL, then the operation can be cancelled by
3326 * triggering the cancellable object from another thread. If the operation
3327 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3329 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
3332 g_file_set_attribute_int64 (GFile *file,
3333 const char *attribute,
3335 GFileQueryInfoFlags flags,
3336 GCancellable *cancellable,
3339 return g_file_set_attribute (file, attribute,
3340 G_FILE_ATTRIBUTE_TYPE_INT64, &value,
3341 flags, cancellable, error);
3345 * g_file_mount_mountable:
3346 * @file: input #GFile.
3347 * @flags: flags affecting the operation
3348 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
3349 * @cancellable: optional #GCancellable object, %NULL to ignore.
3350 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
3351 * @user_data: the data to pass to callback function
3353 * Mounts a file of type G_FILE_TYPE_MOUNTABLE.
3354 * Using @mount_operation, you can request callbacks when, for instance,
3355 * passwords are needed during authentication.
3357 * If @cancellable is not %NULL, then the operation can be cancelled by
3358 * triggering the cancellable object from another thread. If the operation
3359 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3361 * When the operation is finished, @callback will be called. You can then call
3362 * g_file_mount_mountable_finish() to get the result of the operation.
3365 g_file_mount_mountable (GFile *file,
3366 GMountMountFlags flags,
3367 GMountOperation *mount_operation,
3368 GCancellable *cancellable,
3369 GAsyncReadyCallback callback,
3374 g_return_if_fail (G_IS_FILE (file));
3376 iface = G_FILE_GET_IFACE (file);
3378 if (iface->mount_mountable == NULL)
3380 g_simple_async_report_error_in_idle (G_OBJECT (file),
3384 G_IO_ERROR_NOT_SUPPORTED,
3385 _("Operation not supported"));
3389 (* iface->mount_mountable) (file,
3398 * g_file_mount_mountable_finish:
3399 * @file: input #GFile.
3400 * @result: a #GAsyncResult.
3401 * @error: a #GError, or %NULL
3403 * Finishes a mount operation. See g_file_mount_mountable() for details.
3405 * Finish an asynchronous mount operation that was started
3406 * with g_file_mount_mountable().
3408 * Returns: a #GFile or %NULL on error.
3411 g_file_mount_mountable_finish (GFile *file,
3412 GAsyncResult *result,
3417 g_return_val_if_fail (G_IS_FILE (file), NULL);
3418 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
3420 if (G_IS_SIMPLE_ASYNC_RESULT (result))
3422 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
3423 if (g_simple_async_result_propagate_error (simple, error))
3427 iface = G_FILE_GET_IFACE (file);
3428 return (* iface->mount_mountable_finish) (file, result, error);
3432 * g_file_unmount_mountable:
3433 * @file: input #GFile.
3434 * @flags: flags affecting the operation
3435 * @cancellable: optional #GCancellable object, %NULL to ignore.
3436 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
3437 * @user_data: the data to pass to callback function
3439 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
3441 * If @cancellable is not %NULL, then the operation can be cancelled by
3442 * triggering the cancellable object from another thread. If the operation
3443 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3445 * When the operation is finished, @callback will be called. You can then call
3446 * g_file_unmount_mountable_finish() to get the result of the operation.
3449 g_file_unmount_mountable (GFile *file,
3450 GMountUnmountFlags flags,
3451 GCancellable *cancellable,
3452 GAsyncReadyCallback callback,
3457 g_return_if_fail (G_IS_FILE (file));
3459 iface = G_FILE_GET_IFACE (file);
3461 if (iface->unmount_mountable == NULL)
3463 g_simple_async_report_error_in_idle (G_OBJECT (file),
3467 G_IO_ERROR_NOT_SUPPORTED,
3468 _("Operation not supported"));
3472 (* iface->unmount_mountable) (file,
3480 * g_file_unmount_mountable_finish:
3481 * @file: input #GFile.
3482 * @result: a #GAsyncResult.
3483 * @error: a #GError, or %NULL
3485 * Finishes an unmount operation, see g_file_unmount_mountable() for details.
3487 * Finish an asynchronous unmount operation that was started
3488 * with g_file_unmount_mountable().
3490 * Returns: %TRUE if the operation finished successfully. %FALSE
3494 g_file_unmount_mountable_finish (GFile *file,
3495 GAsyncResult *result,
3500 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3501 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
3503 if (G_IS_SIMPLE_ASYNC_RESULT (result))
3505 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
3506 if (g_simple_async_result_propagate_error (simple, error))
3510 iface = G_FILE_GET_IFACE (file);
3511 return (* iface->unmount_mountable_finish) (file, result, error);
3515 * g_file_eject_mountable:
3516 * @file: input #GFile.
3517 * @flags: flags affecting the operation
3518 * @cancellable: optional #GCancellable object, %NULL to ignore.
3519 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
3520 * @user_data: the data to pass to callback function
3522 * Starts an asynchronous eject on a mountable.
3523 * When this operation has completed, @callback will be called with
3524 * @user_user data, and the operation can be finalized with
3525 * g_file_eject_mountable_finish().
3527 * If @cancellable is not %NULL, then the operation can be cancelled by
3528 * triggering the cancellable object from another thread. If the operation
3529 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3532 g_file_eject_mountable (GFile *file,
3533 GMountUnmountFlags flags,
3534 GCancellable *cancellable,
3535 GAsyncReadyCallback callback,
3540 g_return_if_fail (G_IS_FILE (file));
3542 iface = G_FILE_GET_IFACE (file);
3544 if (iface->eject_mountable == NULL)
3546 g_simple_async_report_error_in_idle (G_OBJECT (file),
3550 G_IO_ERROR_NOT_SUPPORTED,
3551 _("Operation not supported"));
3555 (* iface->eject_mountable) (file,
3563 * g_file_eject_mountable_finish:
3564 * @file: input #GFile.
3565 * @result: a #GAsyncResult.
3566 * @error: a #GError, or %NULL
3568 * Finishes an asynchronous eject operation started by
3569 * g_file_eject_mountable().
3571 * Returns: %TRUE if the @file was ejected successfully. %FALSE
3575 g_file_eject_mountable_finish (GFile *file,
3576 GAsyncResult *result,
3581 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3582 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
3584 if (G_IS_SIMPLE_ASYNC_RESULT (result))
3586 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
3587 if (g_simple_async_result_propagate_error (simple, error))
3591 iface = G_FILE_GET_IFACE (file);
3592 return (* iface->eject_mountable_finish) (file, result, error);
3596 * g_file_monitor_directory:
3597 * @file: input #GFile.
3598 * @flags: a set of #GFileMonitorFlags.
3599 * @cancellable: optional #GCancellable object, %NULL to ignore.
3600 * @error: a #GError, or %NULL.
3602 * Obtains a directory monitor for the given file.
3603 * This may fail if directory monitoring is not supported.
3605 * If @cancellable is not %NULL, then the operation can be cancelled by
3606 * triggering the cancellable object from another thread. If the operation
3607 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3609 * Returns: a #GFileMonitor for the given @file,
3610 * or %NULL on error.
3613 g_file_monitor_directory (GFile *file,
3614 GFileMonitorFlags flags,
3615 GCancellable *cancellable,
3620 g_return_val_if_fail (G_IS_FILE (file), NULL);
3622 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3625 iface = G_FILE_GET_IFACE (file);
3627 if (iface->monitor_dir == NULL)
3629 g_set_error (error, G_IO_ERROR,
3630 G_IO_ERROR_NOT_SUPPORTED,
3631 _("Operation not supported"));
3635 return (* iface->monitor_dir) (file, flags, cancellable, error);
3639 * g_file_monitor_file:
3640 * @file: input #GFile.
3641 * @flags: a set of #GFileMonitorFlags.
3642 * @cancellable: optional #GCancellable object, %NULL to ignore.
3643 * @error: a #GError, or %NULL.
3645 * Obtains a file monitor for the given file. If no file notification
3646 * mechanism exists, then regular polling of the file is used.
3648 * If @cancellable is not %NULL, then the operation can be cancelled by
3649 * triggering the cancellable object from another thread. If the operation
3650 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3652 * Returns: a #GFileMonitor for the given @file.
3655 g_file_monitor_file (GFile *file,
3656 GFileMonitorFlags flags,
3657 GCancellable *cancellable,
3661 GFileMonitor *monitor;
3663 g_return_val_if_fail (G_IS_FILE (file), NULL);
3665 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3668 iface = G_FILE_GET_IFACE (file);
3672 if (iface->monitor_file)
3673 monitor = (* iface->monitor_file) (file, flags, cancellable, NULL);
3675 /* Fallback to polling */
3676 if (monitor == NULL)
3677 monitor = _g_poll_file_monitor_new (file);
3682 /********************************************
3683 * Default implementation of async ops *
3684 ********************************************/
3688 GFileQueryInfoFlags flags;
3690 } QueryInfoAsyncData;
3693 query_info_data_free (QueryInfoAsyncData *data)
3696 g_object_unref (data->info);
3697 g_free (data->attributes);
3702 query_info_async_thread (GSimpleAsyncResult *res,
3704 GCancellable *cancellable)
3706 GError *error = NULL;
3707 QueryInfoAsyncData *data;
3710 data = g_simple_async_result_get_op_res_gpointer (res);
3712 info = g_file_query_info (G_FILE (object), data->attributes, data->flags, cancellable, &error);
3716 g_simple_async_result_set_from_error (res, error);
3717 g_error_free (error);
3724 g_file_real_query_info_async (GFile *file,
3725 const char *attributes,
3726 GFileQueryInfoFlags flags,
3728 GCancellable *cancellable,
3729 GAsyncReadyCallback callback,
3732 GSimpleAsyncResult *res;
3733 QueryInfoAsyncData *data;
3735 data = g_new0 (QueryInfoAsyncData, 1);
3736 data->attributes = g_strdup (attributes);
3737 data->flags = flags;
3739 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_query_info_async);
3740 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_info_data_free);
3742 g_simple_async_result_run_in_thread (res, query_info_async_thread, io_priority, cancellable);
3743 g_object_unref (res);
3747 g_file_real_query_info_finish (GFile *file,
3751 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
3752 QueryInfoAsyncData *data;
3754 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_info_async);
3756 data = g_simple_async_result_get_op_res_gpointer (simple);
3758 return g_object_ref (data->info);
3765 GFileQueryInfoFlags flags;
3766 GFileEnumerator *enumerator;
3767 } EnumerateChildrenAsyncData;
3770 enumerate_children_data_free (EnumerateChildrenAsyncData *data)
3772 if (data->enumerator)
3773 g_object_unref (data->enumerator);
3774 g_free (data->attributes);
3779 enumerate_children_async_thread (GSimpleAsyncResult *res,
3781 GCancellable *cancellable)
3783 GError *error = NULL;
3784 EnumerateChildrenAsyncData *data;
3785 GFileEnumerator *enumerator;
3787 data = g_simple_async_result_get_op_res_gpointer (res);
3789 enumerator = g_file_enumerate_children (G_FILE (object), data->attributes, data->flags, cancellable, &error);
3791 if (enumerator == NULL)
3793 g_simple_async_result_set_from_error (res, error);
3794 g_error_free (error);
3797 data->enumerator = enumerator;
3801 g_file_real_enumerate_children_async (GFile *file,
3802 const char *attributes,
3803 GFileQueryInfoFlags flags,
3805 GCancellable *cancellable,
3806 GAsyncReadyCallback callback,
3809 GSimpleAsyncResult *res;
3810 EnumerateChildrenAsyncData *data;
3812 data = g_new0 (EnumerateChildrenAsyncData, 1);
3813 data->attributes = g_strdup (attributes);
3814 data->flags = flags;
3816 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_enumerate_children_async);
3817 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)enumerate_children_data_free);
3819 g_simple_async_result_run_in_thread (res, enumerate_children_async_thread, io_priority, cancellable);
3820 g_object_unref (res);
3823 static GFileEnumerator *
3824 g_file_real_enumerate_children_finish (GFile *file,
3828 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
3829 EnumerateChildrenAsyncData *data;
3831 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_enumerate_children_async);
3833 data = g_simple_async_result_get_op_res_gpointer (simple);
3834 if (data->enumerator)
3835 return g_object_ref (data->enumerator);
3841 open_read_async_thread (GSimpleAsyncResult *res,
3843 GCancellable *cancellable)
3846 GFileInputStream *stream;
3847 GError *error = NULL;
3849 iface = G_FILE_GET_IFACE (object);
3851 stream = iface->read_fn (G_FILE (object), cancellable, &error);
3855 g_simple_async_result_set_from_error (res, error);
3856 g_error_free (error);
3859 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
3863 g_file_real_read_async (GFile *file,
3865 GCancellable *cancellable,
3866 GAsyncReadyCallback callback,
3869 GSimpleAsyncResult *res;
3871 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_read_async);
3873 g_simple_async_result_run_in_thread (res, open_read_async_thread, io_priority, cancellable);
3874 g_object_unref (res);
3877 static GFileInputStream *
3878 g_file_real_read_finish (GFile *file,
3882 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
3885 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_read_async);
3887 op = g_simple_async_result_get_op_res_gpointer (simple);
3889 return g_object_ref (op);
3895 append_to_async_thread (GSimpleAsyncResult *res,
3897 GCancellable *cancellable)
3900 GFileCreateFlags *data;
3901 GFileOutputStream *stream;
3902 GError *error = NULL;
3904 iface = G_FILE_GET_IFACE (object);
3906 data = g_simple_async_result_get_op_res_gpointer (res);
3908 stream = iface->append_to (G_FILE (object), *data, cancellable, &error);
3912 g_simple_async_result_set_from_error (res, error);
3913 g_error_free (error);
3916 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
3920 g_file_real_append_to_async (GFile *file,
3921 GFileCreateFlags flags,
3923 GCancellable *cancellable,
3924 GAsyncReadyCallback callback,
3927 GFileCreateFlags *data;
3928 GSimpleAsyncResult *res;
3930 data = g_new0 (GFileCreateFlags, 1);
3933 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_append_to_async);
3934 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
3936 g_simple_async_result_run_in_thread (res, append_to_async_thread, io_priority, cancellable);
3937 g_object_unref (res);
3940 static GFileOutputStream *
3941 g_file_real_append_to_finish (GFile *file,
3945 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
3948 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_append_to_async);
3950 op = g_simple_async_result_get_op_res_gpointer (simple);
3952 return g_object_ref (op);
3958 create_async_thread (GSimpleAsyncResult *res,
3960 GCancellable *cancellable)
3963 GFileCreateFlags *data;
3964 GFileOutputStream *stream;
3965 GError *error = NULL;
3967 iface = G_FILE_GET_IFACE (object);
3969 data = g_simple_async_result_get_op_res_gpointer (res);
3971 stream = iface->create (G_FILE (object), *data, cancellable, &error);
3975 g_simple_async_result_set_from_error (res, error);
3976 g_error_free (error);
3979 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
3983 g_file_real_create_async (GFile *file,
3984 GFileCreateFlags flags,
3986 GCancellable *cancellable,
3987 GAsyncReadyCallback callback,
3990 GFileCreateFlags *data;
3991 GSimpleAsyncResult *res;
3993 data = g_new0 (GFileCreateFlags, 1);
3996 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_create_async);
3997 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
3999 g_simple_async_result_run_in_thread (res, create_async_thread, io_priority, cancellable);
4000 g_object_unref (res);
4003 static GFileOutputStream *
4004 g_file_real_create_finish (GFile *file,
4008 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4011 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_async);
4013 op = g_simple_async_result_get_op_res_gpointer (simple);
4015 return g_object_ref (op);
4021 GFileOutputStream *stream;
4023 gboolean make_backup;
4024 GFileCreateFlags flags;
4028 replace_async_data_free (ReplaceAsyncData *data)
4031 g_object_unref (data->stream);
4032 g_free (data->etag);
4037 replace_async_thread (GSimpleAsyncResult *res,
4039 GCancellable *cancellable)
4042 GFileOutputStream *stream;
4043 GError *error = NULL;
4044 ReplaceAsyncData *data;
4046 iface = G_FILE_GET_IFACE (object);
4048 data = g_simple_async_result_get_op_res_gpointer (res);
4050 stream = iface->replace (G_FILE (object),
4059 g_simple_async_result_set_from_error (res, error);
4060 g_error_free (error);
4063 data->stream = stream;
4067 g_file_real_replace_async (GFile *file,
4069 gboolean make_backup,
4070 GFileCreateFlags flags,
4072 GCancellable *cancellable,
4073 GAsyncReadyCallback callback,
4076 GSimpleAsyncResult *res;
4077 ReplaceAsyncData *data;
4079 data = g_new0 (ReplaceAsyncData, 1);
4080 data->etag = g_strdup (etag);
4081 data->make_backup = make_backup;
4082 data->flags = flags;
4084 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_replace_async);
4085 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_async_data_free);
4087 g_simple_async_result_run_in_thread (res, replace_async_thread, io_priority, cancellable);
4088 g_object_unref (res);
4091 static GFileOutputStream *
4092 g_file_real_replace_finish (GFile *file,
4096 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4097 ReplaceAsyncData *data;
4099 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_async);
4101 data = g_simple_async_result_get_op_res_gpointer (simple);
4103 return g_object_ref (data->stream);
4111 } SetDisplayNameAsyncData;
4114 set_display_name_data_free (SetDisplayNameAsyncData *data)
4116 g_free (data->name);
4118 g_object_unref (data->file);
4123 set_display_name_async_thread (GSimpleAsyncResult *res,
4125 GCancellable *cancellable)
4127 GError *error = NULL;
4128 SetDisplayNameAsyncData *data;
4131 data = g_simple_async_result_get_op_res_gpointer (res);
4133 file = g_file_set_display_name (G_FILE (object), data->name, cancellable, &error);
4137 g_simple_async_result_set_from_error (res, error);
4138 g_error_free (error);
4145 g_file_real_set_display_name_async (GFile *file,
4146 const char *display_name,
4148 GCancellable *cancellable,
4149 GAsyncReadyCallback callback,
4152 GSimpleAsyncResult *res;
4153 SetDisplayNameAsyncData *data;
4155 data = g_new0 (SetDisplayNameAsyncData, 1);
4156 data->name = g_strdup (display_name);
4158 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_set_display_name_async);
4159 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)set_display_name_data_free);
4161 g_simple_async_result_run_in_thread (res, set_display_name_async_thread, io_priority, cancellable);
4162 g_object_unref (res);
4166 g_file_real_set_display_name_finish (GFile *file,
4170 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4171 SetDisplayNameAsyncData *data;
4173 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_display_name_async);
4175 data = g_simple_async_result_get_op_res_gpointer (simple);
4177 return g_object_ref (data->file);
4183 GFileQueryInfoFlags flags;
4190 set_info_data_free (SetInfoAsyncData *data)
4193 g_object_unref (data->info);
4195 g_error_free (data->error);
4200 set_info_async_thread (GSimpleAsyncResult *res,
4202 GCancellable *cancellable)
4204 SetInfoAsyncData *data;
4206 data = g_simple_async_result_get_op_res_gpointer (res);
4209 data->res = g_file_set_attributes_from_info (G_FILE (object),
4217 g_file_real_set_attributes_async (GFile *file,
4219 GFileQueryInfoFlags flags,
4221 GCancellable *cancellable,
4222 GAsyncReadyCallback callback,
4225 GSimpleAsyncResult *res;
4226 SetInfoAsyncData *data;
4228 data = g_new0 (SetInfoAsyncData, 1);
4229 data->info = g_file_info_dup (info);
4230 data->flags = flags;
4232 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_set_attributes_async);
4233 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)set_info_data_free);
4235 g_simple_async_result_run_in_thread (res, set_info_async_thread, io_priority, cancellable);
4236 g_object_unref (res);
4240 g_file_real_set_attributes_finish (GFile *file,
4245 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4246 SetInfoAsyncData *data;
4248 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_attributes_async);
4250 data = g_simple_async_result_get_op_res_gpointer (simple);
4253 *info = g_object_ref (data->info);
4255 if (error != NULL && data->error)
4256 *error = g_error_copy (data->error);
4262 find_enclosing_mount_async_thread (GSimpleAsyncResult *res,
4264 GCancellable *cancellable)
4266 GError *error = NULL;
4269 mount = g_file_find_enclosing_mount (G_FILE (object), cancellable, &error);
4273 g_simple_async_result_set_from_error (res, error);
4274 g_error_free (error);
4277 g_simple_async_result_set_op_res_gpointer (res, mount, (GDestroyNotify)g_object_unref);
4281 g_file_real_find_enclosing_mount_async (GFile *file,
4283 GCancellable *cancellable,
4284 GAsyncReadyCallback callback,
4287 GSimpleAsyncResult *res;
4289 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_find_enclosing_mount_async);
4291 g_simple_async_result_run_in_thread (res, find_enclosing_mount_async_thread, io_priority, cancellable);
4292 g_object_unref (res);
4296 g_file_real_find_enclosing_mount_finish (GFile *file,
4300 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4303 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_find_enclosing_mount_async);
4305 mount = g_simple_async_result_get_op_res_gpointer (simple);
4306 return g_object_ref (mount);
4313 GFileCopyFlags flags;
4314 GFileProgressCallback progress_cb;
4315 gpointer progress_cb_data;
4316 GIOSchedulerJob *job;
4320 copy_async_data_free (CopyAsyncData *data)
4322 g_object_unref (data->source);
4323 g_object_unref (data->destination);
4328 CopyAsyncData *data;
4329 goffset current_num_bytes;
4330 goffset total_num_bytes;
4334 copy_async_progress_in_main (gpointer user_data)
4336 ProgressData *progress = user_data;
4337 CopyAsyncData *data = progress->data;
4339 data->progress_cb (progress->current_num_bytes,
4340 progress->total_num_bytes,
4341 data->progress_cb_data);
4347 mainloop_barrier (gpointer user_data)
4349 /* Does nothing, but ensures all queued idles before
4356 copy_async_progress_callback (goffset current_num_bytes,
4357 goffset total_num_bytes,
4360 CopyAsyncData *data = user_data;
4361 ProgressData *progress;
4363 progress = g_new (ProgressData, 1);
4364 progress->data = data;
4365 progress->current_num_bytes = current_num_bytes;
4366 progress->total_num_bytes = total_num_bytes;
4368 g_io_scheduler_job_send_to_mainloop_async (data->job,
4369 copy_async_progress_in_main,
4375 copy_async_thread (GIOSchedulerJob *job,
4376 GCancellable *cancellable,
4379 GSimpleAsyncResult *res;
4380 CopyAsyncData *data;
4385 data = g_simple_async_result_get_op_res_gpointer (res);
4389 result = g_file_copy (data->source,
4393 (data->progress_cb != NULL) ? copy_async_progress_callback : NULL,
4397 /* Ensure all progress callbacks are done running in main thread */
4398 if (data->progress_cb != NULL)
4399 g_io_scheduler_job_send_to_mainloop (job,
4405 g_simple_async_result_set_from_error (res, error);
4406 g_error_free (error);
4409 g_simple_async_result_complete_in_idle (res);
4415 g_file_real_copy_async (GFile *source,
4417 GFileCopyFlags flags,
4419 GCancellable *cancellable,
4420 GFileProgressCallback progress_callback,
4421 gpointer progress_callback_data,
4422 GAsyncReadyCallback callback,
4425 GSimpleAsyncResult *res;
4426 CopyAsyncData *data;
4428 data = g_new0 (CopyAsyncData, 1);
4429 data->source = g_object_ref (source);
4430 data->destination = g_object_ref (destination);
4431 data->flags = flags;
4432 data->progress_cb = progress_callback;
4433 data->progress_cb_data = progress_callback_data;
4435 res = g_simple_async_result_new (G_OBJECT (source), callback, user_data, g_file_real_copy_async);
4436 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)copy_async_data_free);
4438 g_io_scheduler_push_job (copy_async_thread, res, g_object_unref, io_priority, cancellable);
4442 g_file_real_copy_finish (GFile *file,
4446 /* Error handled in g_file_copy_finish() */
4451 /********************************************
4452 * Default VFS operations *
4453 ********************************************/
4456 * g_file_new_for_path:
4457 * @path: a string containing a relative or absolute path.
4459 * Constructs a #GFile for a given path. This operation never
4460 * fails, but the returned object might not support any I/O
4461 * operation if @path is malformed.
4463 * Returns: a new #GFile for the given @path.
4466 g_file_new_for_path (const char *path)
4468 g_return_val_if_fail (path != NULL, NULL);
4470 return g_vfs_get_file_for_path (g_vfs_get_default (), path);
4474 * g_file_new_for_uri:
4475 * @uri: a string containing a URI.
4477 * Constructs a #GFile for a given URI. This operation never
4478 * fails, but the returned object might not support any I/O
4479 * operation if @uri is malformed or if the uri type is
4482 * Returns: a #GFile for the given @uri.
4485 g_file_new_for_uri (const char *uri)
4487 g_return_val_if_fail (uri != NULL, NULL);
4489 return g_vfs_get_file_for_uri (g_vfs_get_default (), uri);
4493 * g_file_parse_name:
4494 * @parse_name: a file name or path to be parsed.
4496 * Constructs a #GFile with the given @parse_name (i.e. something given by g_file_get_parse_name()).
4497 * This operation never fails, but the returned object might not support any I/O
4498 * operation if the @parse_name cannot be parsed.
4500 * Returns: a new #GFile.
4503 g_file_parse_name (const char *parse_name)
4505 g_return_val_if_fail (parse_name != NULL, NULL);
4507 return g_vfs_parse_name (g_vfs_get_default (), parse_name);
4511 is_valid_scheme_character (char c)
4513 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
4517 has_valid_scheme (const char *uri)
4523 if (!is_valid_scheme_character (*p))
4528 } while (is_valid_scheme_character (*p));
4534 * g_file_new_for_commandline_arg:
4535 * @arg: a command line string.
4537 * Creates a #GFile with the given argument from the command line. The value of
4538 * @arg can be either a URI, an absolute path or a relative path resolved
4539 * relative to the current working directory.
4540 * This operation never fails, but the returned object might not support any
4541 * I/O operation if @arg points to a malformed path.
4543 * Returns: a new #GFile.
4546 g_file_new_for_commandline_arg (const char *arg)
4552 g_return_val_if_fail (arg != NULL, NULL);
4554 if (g_path_is_absolute (arg))
4555 return g_file_new_for_path (arg);
4557 if (has_valid_scheme (arg))
4558 return g_file_new_for_uri (arg);
4560 current_dir = g_get_current_dir ();
4561 filename = g_build_filename (current_dir, arg, NULL);
4562 g_free (current_dir);
4564 file = g_file_new_for_path (filename);
4571 * g_file_mount_enclosing_volume:
4572 * @location: input #GFile.
4573 * @flags: flags affecting the operation
4574 * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
4575 * @cancellable: optional #GCancellable object, %NULL to ignore.
4576 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4577 * @user_data: the data to pass to callback function
4579 * Starts a @mount_operation, mounting the volume that contains the file @location.
4581 * When this operation has completed, @callback will be called with
4582 * @user_user data, and the operation can be finalized with
4583 * g_file_mount_enclosing_volume_finish().
4585 * If @cancellable is not %NULL, then the operation can be cancelled by
4586 * triggering the cancellable object from another thread. If the operation
4587 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4590 g_file_mount_enclosing_volume (GFile *location,
4591 GMountMountFlags flags,
4592 GMountOperation *mount_operation,
4593 GCancellable *cancellable,
4594 GAsyncReadyCallback callback,
4599 g_return_if_fail (G_IS_FILE (location));
4601 iface = G_FILE_GET_IFACE (location);
4603 if (iface->mount_enclosing_volume == NULL)
4605 g_simple_async_report_error_in_idle (G_OBJECT (location),
4606 callback, user_data,
4607 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
4608 _("volume doesn't implement mount"));
4613 (* iface->mount_enclosing_volume) (location, flags, mount_operation, cancellable, callback, user_data);
4618 * g_file_mount_enclosing_volume_finish:
4619 * @location: input #GFile.
4620 * @result: a #GAsyncResult.
4621 * @error: a #GError, or %NULL
4623 * Finishes a mount operation started by g_file_mount_enclosing_volume().
4625 * Returns: %TRUE if successful. If an error
4626 * has occurred, this function will return %FALSE and set @error
4627 * appropriately if present.
4630 g_file_mount_enclosing_volume_finish (GFile *location,
4631 GAsyncResult *result,
4636 g_return_val_if_fail (G_IS_FILE (location), FALSE);
4637 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4639 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4641 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4642 if (g_simple_async_result_propagate_error (simple, error))
4646 iface = G_FILE_GET_IFACE (location);
4648 return (* iface->mount_enclosing_volume_finish) (location, result, error);
4651 /********************************************
4652 * Utility functions *
4653 ********************************************/
4656 * g_file_query_default_handler:
4657 * @file: a #GFile to open.
4658 * @cancellable: optional #GCancellable object, %NULL to ignore.
4659 * @error: a #GError, or %NULL
4661 * Returns the #GAppInfo that is registered as the default
4662 * application to handle the file specified by @file.
4664 * If @cancellable is not %NULL, then the operation can be cancelled by
4665 * triggering the cancellable object from another thread. If the operation
4666 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4668 * Returns: a #GAppInfo if the handle was found, %NULL if there were errors.
4669 * When you are done with it, release it with g_object_unref()
4672 g_file_query_default_handler (GFile *file,
4673 GCancellable *cancellable,
4677 const char *content_type;
4682 uri_scheme = g_file_get_uri_scheme (file);
4683 appinfo = g_app_info_get_default_for_uri_scheme (uri_scheme);
4684 g_free (uri_scheme);
4686 if (appinfo != NULL)
4689 info = g_file_query_info (file,
4690 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
4699 content_type = g_file_info_get_content_type (info);
4702 /* Don't use is_native(), as we want to support fuse paths if availible */
4703 path = g_file_get_path (file);
4704 appinfo = g_app_info_get_default_for_type (content_type,
4709 g_object_unref (info);
4711 if (appinfo != NULL)
4714 g_set_error (error, G_IO_ERROR,
4715 G_IO_ERROR_NOT_SUPPORTED,
4716 _("No application is registered as handling this file"));
4722 #define GET_CONTENT_BLOCK_SIZE 8192
4725 * g_file_load_contents:
4726 * @file: input #GFile.
4727 * @cancellable: optional #GCancellable object, %NULL to ignore.
4728 * @contents: a location to place the contents of the file.
4729 * @length: a location to place the length of the contents of the file.
4730 * @etag_out: a location to place the current entity tag for the file.
4731 * @error: a #GError, or %NULL
4733 * Loads the content of the file into memory, returning the size of
4734 * the data. The data is always zero terminated, but this is not
4735 * included in the resultant @length.
4737 * If @cancellable is not %NULL, then the operation can be cancelled by
4738 * triggering the cancellable object from another thread. If the operation
4739 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4741 * Returns: %TRUE if the @file's contents were successfully loaded.
4742 * %FALSE if there were errors..
4745 g_file_load_contents (GFile *file,
4746 GCancellable *cancellable,
4752 GFileInputStream *in;
4753 GByteArray *content;
4758 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4759 g_return_val_if_fail (contents != NULL, FALSE);
4761 in = g_file_read (file, cancellable, error);
4765 content = g_byte_array_new ();
4768 g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
4769 while ((res = g_input_stream_read (G_INPUT_STREAM (in),
4770 content->data + pos,
4771 GET_CONTENT_BLOCK_SIZE,
4772 cancellable, error)) > 0)
4775 g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
4782 info = g_file_input_stream_query_info (in,
4783 G_FILE_ATTRIBUTE_ETAG_VALUE,
4788 *etag_out = g_strdup (g_file_info_get_etag (info));
4789 g_object_unref (info);
4793 /* Ignore errors on close */
4794 g_input_stream_close (G_INPUT_STREAM (in), cancellable, NULL);
4795 g_object_unref (in);
4799 /* error is set already */
4800 g_byte_array_free (content, TRUE);
4807 /* Zero terminate (we got an extra byte allocated for this */
4808 content->data[pos] = 0;
4810 *contents = (char *)g_byte_array_free (content, FALSE);
4818 GCancellable *cancellable;
4819 GFileReadMoreCallback read_more_callback;
4820 GAsyncReadyCallback callback;
4822 GByteArray *content;
4829 load_contents_data_free (LoadContentsData *data)
4832 g_error_free (data->error);
4833 if (data->cancellable)
4834 g_object_unref (data->cancellable);
4836 g_byte_array_free (data->content, TRUE);
4837 g_free (data->etag);
4838 g_object_unref (data->file);
4843 load_contents_close_callback (GObject *obj,
4844 GAsyncResult *close_res,
4847 GInputStream *stream = G_INPUT_STREAM (obj);
4848 LoadContentsData *data = user_data;
4849 GSimpleAsyncResult *res;
4851 /* Ignore errors here, we're only reading anyway */
4852 g_input_stream_close_finish (stream, close_res, NULL);
4853 g_object_unref (stream);
4855 res = g_simple_async_result_new (G_OBJECT (data->file),
4858 g_file_load_contents_async);
4859 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)load_contents_data_free);
4860 g_simple_async_result_complete (res);
4861 g_object_unref (res);
4865 load_contents_fstat_callback (GObject *obj,
4866 GAsyncResult *stat_res,
4869 GInputStream *stream = G_INPUT_STREAM (obj);
4870 LoadContentsData *data = user_data;
4873 info = g_file_input_stream_query_info_finish (G_FILE_INPUT_STREAM (stream),
4877 data->etag = g_strdup (g_file_info_get_etag (info));
4878 g_object_unref (info);
4881 g_input_stream_close_async (stream, 0,
4883 load_contents_close_callback, data);
4887 load_contents_read_callback (GObject *obj,
4888 GAsyncResult *read_res,
4891 GInputStream *stream = G_INPUT_STREAM (obj);
4892 LoadContentsData *data = user_data;
4893 GError *error = NULL;
4896 read_size = g_input_stream_read_finish (stream, read_res, &error);
4900 /* Error or EOF, close the file */
4901 data->error = error;
4902 g_input_stream_close_async (stream, 0,
4904 load_contents_close_callback, data);
4906 else if (read_size == 0)
4908 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
4909 G_FILE_ATTRIBUTE_ETAG_VALUE,
4912 load_contents_fstat_callback,
4915 else if (read_size > 0)
4917 data->pos += read_size;
4919 g_byte_array_set_size (data->content,
4920 data->pos + GET_CONTENT_BLOCK_SIZE);
4923 if (data->read_more_callback &&
4924 !data->read_more_callback ((char *)data->content->data, data->pos, data->user_data))
4925 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
4926 G_FILE_ATTRIBUTE_ETAG_VALUE,
4929 load_contents_fstat_callback,
4932 g_input_stream_read_async (stream,
4933 data->content->data + data->pos,
4934 GET_CONTENT_BLOCK_SIZE,
4937 load_contents_read_callback,
4943 load_contents_open_callback (GObject *obj,
4944 GAsyncResult *open_res,
4947 GFile *file = G_FILE (obj);
4948 GFileInputStream *stream;
4949 LoadContentsData *data = user_data;
4950 GError *error = NULL;
4951 GSimpleAsyncResult *res;
4953 stream = g_file_read_finish (file, open_res, &error);
4957 g_byte_array_set_size (data->content,
4958 data->pos + GET_CONTENT_BLOCK_SIZE);
4959 g_input_stream_read_async (G_INPUT_STREAM (stream),
4960 data->content->data + data->pos,
4961 GET_CONTENT_BLOCK_SIZE,
4964 load_contents_read_callback,
4970 res = g_simple_async_result_new_from_error (G_OBJECT (data->file),
4974 g_simple_async_result_complete (res);
4975 g_error_free (error);
4976 load_contents_data_free (data);
4977 g_object_unref (res);
4982 * g_file_load_partial_contents_async:
4983 * @file: input #GFile.
4984 * @cancellable: optional #GCancellable object, %NULL to ignore.
4985 * @read_more_callback: a #GFileReadMoreCallback to receive partial data and to specify whether further data should be read.
4986 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
4987 * @user_data: the data to pass to the callback functions.
4989 * Reads the partial contents of a file. A #GFileReadMoreCallback should be
4990 * used to stop reading from the file when appropriate, else this function
4991 * will behave exactly as g_file_load_contents_async(). This operation
4992 * can be finished by g_file_load_partial_contents_finish().
4994 * Users of this function should be aware that @user_data is passed to
4995 * both the @read_more_callback and the @callback.
4997 * If @cancellable is not %NULL, then the operation can be cancelled by
4998 * triggering the cancellable object from another thread. If the operation
4999 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5002 g_file_load_partial_contents_async (GFile *file,
5003 GCancellable *cancellable,
5004 GFileReadMoreCallback read_more_callback,
5005 GAsyncReadyCallback callback,
5008 LoadContentsData *data;
5010 g_return_if_fail (G_IS_FILE (file));
5012 data = g_new0 (LoadContentsData, 1);
5015 data->cancellable = g_object_ref (cancellable);
5016 data->read_more_callback = read_more_callback;
5017 data->callback = callback;
5018 data->user_data = user_data;
5019 data->content = g_byte_array_new ();
5020 data->file = g_object_ref (file);
5022 g_file_read_async (file,
5025 load_contents_open_callback,
5030 * g_file_load_partial_contents_finish:
5031 * @file: input #GFile.
5032 * @res: a #GAsyncResult.
5033 * @contents: a location to place the contents of the file.
5034 * @length: a location to place the length of the contents of the file.
5035 * @etag_out: a location to place the current entity tag for the file.
5036 * @error: a #GError, or %NULL
5038 * Finishes an asynchronous partial load operation that was started
5039 * with g_file_load_partial_contents_async().
5041 * Returns: %TRUE if the load was successful. If %FALSE and @error is
5042 * present, it will be set appropriately.
5045 g_file_load_partial_contents_finish (GFile *file,
5052 GSimpleAsyncResult *simple;
5053 LoadContentsData *data;
5055 g_return_val_if_fail (G_IS_FILE (file), FALSE);
5056 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE);
5057 g_return_val_if_fail (contents != NULL, FALSE);
5059 simple = G_SIMPLE_ASYNC_RESULT (res);
5061 if (g_simple_async_result_propagate_error (simple, error))
5064 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_load_contents_async);
5066 data = g_simple_async_result_get_op_res_gpointer (simple);
5070 g_propagate_error (error, data->error);
5079 *length = data->pos;
5083 *etag_out = data->etag;
5087 /* Zero terminate */
5088 g_byte_array_set_size (data->content, data->pos + 1);
5089 data->content->data[data->pos] = 0;
5091 *contents = (char *)g_byte_array_free (data->content, FALSE);
5092 data->content = NULL;
5098 * g_file_load_contents_async:
5099 * @file: input #GFile.
5100 * @cancellable: optional #GCancellable object, %NULL to ignore.
5101 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
5102 * @user_data: the data to pass to callback function
5104 * Starts an asynchronous load of the @file's contents.
5106 * For more details, see g_file_load_contents() which is
5107 * the synchronous version of this call.
5109 * When the load operation has completed, @callback will be called
5110 * with @user data. To finish the operation, call
5111 * g_file_load_contents_finish() with the #GAsyncResult returned by
5114 * If @cancellable is not %NULL, then the operation can be cancelled by
5115 * triggering the cancellable object from another thread. If the operation
5116 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5119 g_file_load_contents_async (GFile *file,
5120 GCancellable *cancellable,
5121 GAsyncReadyCallback callback,
5124 g_file_load_partial_contents_async (file,
5127 callback, user_data);
5131 * g_file_load_contents_finish:
5132 * @file: input #GFile.
5133 * @res: a #GAsyncResult.
5134 * @contents: a location to place the contents of the file.
5135 * @length: a location to place the length of the contents of the file.
5136 * @etag_out: a location to place the current entity tag for the file.
5137 * @error: a #GError, or %NULL
5139 * Finishes an asynchronous load of the @file's contents.
5140 * The contents are placed in @contents, and @length is set to the
5141 * size of the @contents string. If @etag_out is present, it will be
5142 * set to the new entity tag for the @file.
5144 * Returns: %TRUE if the load was successful. If %FALSE and @error is
5145 * present, it will be set appropriately.
5148 g_file_load_contents_finish (GFile *file,
5155 return g_file_load_partial_contents_finish (file,
5164 * g_file_replace_contents:
5165 * @file: input #GFile.
5166 * @contents: a string containing the new contents for @file.
5167 * @length: the length of @contents in bytes.
5168 * @etag: the old <link linkend="gfile-etag">entity tag</link>
5170 * @make_backup: %TRUE if a backup should be created.
5171 * @flags: a set of #GFileCreateFlags.
5172 * @new_etag: a location to a new <link linkend="gfile-etag">entity tag</link>
5173 * for the document. This should be freed with g_free() when no longer
5175 * @cancellable: optional #GCancellable object, %NULL to ignore.
5176 * @error: a #GError, or %NULL
5178 * Replaces the contents of @file with @contents of @length bytes.
5180 * If @etag is specified (not %NULL) any existing file must have that etag, or
5181 * the error %G_IO_ERROR_WRONG_ETAG will be returned.
5183 * If @make_backup is %TRUE, this function will attempt to make a backup of @file.
5185 * If @cancellable is not %NULL, then the operation can be cancelled by
5186 * triggering the cancellable object from another thread. If the operation
5187 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5189 * The returned @new_etag can be used to verify that the file hasn't changed the
5190 * next time it is saved over.
5192 * Returns: %TRUE if successful. If an error
5193 * has occurred, this function will return %FALSE and set @error
5194 * appropriately if present.
5197 g_file_replace_contents (GFile *file,
5198 const char *contents,
5201 gboolean make_backup,
5202 GFileCreateFlags flags,
5204 GCancellable *cancellable,
5207 GFileOutputStream *out;
5208 gsize pos, remainder;
5211 g_return_val_if_fail (G_IS_FILE (file), FALSE);
5212 g_return_val_if_fail (contents != NULL, FALSE);
5214 out = g_file_replace (file, etag, make_backup, flags, cancellable, error);
5220 while (remainder > 0 &&
5221 (res = g_output_stream_write (G_OUTPUT_STREAM (out),
5223 MIN (remainder, GET_CONTENT_BLOCK_SIZE),
5231 if (remainder > 0 && res < 0)
5233 /* Ignore errors on close */
5234 g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, NULL);
5236 /* error is set already */
5240 if (!g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, error))
5244 *new_etag = g_file_output_stream_get_etag (out);
5252 GCancellable *cancellable;
5253 GAsyncReadyCallback callback;
5255 const char *content;
5259 } ReplaceContentsData;
5262 replace_contents_data_free (ReplaceContentsData *data)
5265 g_error_free (data->error);
5266 if (data->cancellable)
5267 g_object_unref (data->cancellable);
5268 g_object_unref (data->file);
5269 g_free (data->etag);
5274 replace_contents_close_callback (GObject *obj,
5275 GAsyncResult *close_res,
5278 GOutputStream *stream = G_OUTPUT_STREAM (obj);
5279 ReplaceContentsData *data = user_data;
5280 GSimpleAsyncResult *res;
5282 /* Ignore errors here, we're only reading anyway */
5283 g_output_stream_close_finish (stream, close_res, NULL);
5284 g_object_unref (stream);
5286 data->etag = g_file_output_stream_get_etag (G_FILE_OUTPUT_STREAM (stream));
5288 res = g_simple_async_result_new (G_OBJECT (data->file),
5291 g_file_replace_contents_async);
5292 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_contents_data_free);
5293 g_simple_async_result_complete (res);
5294 g_object_unref (res);
5298 replace_contents_write_callback (GObject *obj,
5299 GAsyncResult *read_res,
5302 GOutputStream *stream = G_OUTPUT_STREAM (obj);
5303 ReplaceContentsData *data = user_data;
5304 GError *error = NULL;
5307 write_size = g_output_stream_write_finish (stream, read_res, &error);
5309 if (write_size <= 0)
5311 /* Error or EOF, close the file */
5313 data->error = error;
5314 g_output_stream_close_async (stream, 0,
5316 replace_contents_close_callback, data);
5318 else if (write_size > 0)
5320 data->pos += write_size;
5322 if (data->pos >= data->length)
5323 g_output_stream_close_async (stream, 0,
5325 replace_contents_close_callback, data);
5327 g_output_stream_write_async (stream,
5328 data->content + data->pos,
5329 data->length - data->pos,
5332 replace_contents_write_callback,
5338 replace_contents_open_callback (GObject *obj,
5339 GAsyncResult *open_res,
5342 GFile *file = G_FILE (obj);
5343 GFileOutputStream *stream;
5344 ReplaceContentsData *data = user_data;
5345 GError *error = NULL;
5346 GSimpleAsyncResult *res;
5348 stream = g_file_replace_finish (file, open_res, &error);
5352 g_output_stream_write_async (G_OUTPUT_STREAM (stream),
5353 data->content + data->pos,
5354 data->length - data->pos,
5357 replace_contents_write_callback,
5363 res = g_simple_async_result_new_from_error (G_OBJECT (data->file),
5367 g_simple_async_result_complete (res);
5368 g_error_free (error);
5369 replace_contents_data_free (data);
5370 g_object_unref (res);
5375 * g_file_replace_contents_async:
5376 * @file: input #GFile.
5377 * @contents: string of contents to replace the file with.
5378 * @length: the length of @contents in bytes.
5379 * @etag: a new <link linkend="gfile-etag">entity tag</link> for the @file.
5380 * @make_backup: %TRUE if a backup should be created.
5381 * @flags: a set of #GFileCreateFlags.
5382 * @cancellable: optional #GCancellable object, %NULL to ignore.
5383 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
5384 * @user_data: the data to pass to callback function
5386 * Starts an asynchronous replacement of @file with the given
5387 * @contents of @length bytes. @etag will replace the document's
5388 * current entity tag.
5390 * When this operation has completed, @callback will be called with
5391 * @user_user data, and the operation can be finalized with
5392 * g_file_replace_contents_finish().
5394 * If @cancellable is not %NULL, then the operation can be cancelled by
5395 * triggering the cancellable object from another thread. If the operation
5396 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5398 * If @make_backup is %TRUE, this function will attempt to
5399 * make a backup of @file.
5402 g_file_replace_contents_async (GFile *file,
5403 const char *contents,
5406 gboolean make_backup,
5407 GFileCreateFlags flags,
5408 GCancellable *cancellable,
5409 GAsyncReadyCallback callback,
5412 ReplaceContentsData *data;
5414 g_return_if_fail (G_IS_FILE (file));
5415 g_return_if_fail (contents != NULL);
5417 data = g_new0 (ReplaceContentsData, 1);
5420 data->cancellable = g_object_ref (cancellable);
5421 data->callback = callback;
5422 data->user_data = user_data;
5423 data->content = contents;
5424 data->length = length;
5426 data->file = g_object_ref (file);
5428 g_file_replace_async (file,
5434 replace_contents_open_callback,
5439 * g_file_replace_contents_finish:
5440 * @file: input #GFile.
5441 * @res: a #GAsyncResult.
5442 * @new_etag: a location of a new <link linkend="gfile-etag">entity tag</link>
5443 * for the document. This should be freed with g_free() when it is no
5445 * @error: a #GError, or %NULL
5447 * Finishes an asynchronous replace of the given @file. See
5448 * g_file_replace_contents_async(). Sets @new_etag to the new entity
5449 * tag for the document, if present.
5451 * Returns: %TRUE on success, %FALSE on failure.
5454 g_file_replace_contents_finish (GFile *file,
5459 GSimpleAsyncResult *simple;
5460 ReplaceContentsData *data;
5462 g_return_val_if_fail (G_IS_FILE (file), FALSE);
5463 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE);
5465 simple = G_SIMPLE_ASYNC_RESULT (res);
5467 if (g_simple_async_result_propagate_error (simple, error))
5470 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_replace_contents_async);
5472 data = g_simple_async_result_get_op_res_gpointer (simple);
5476 g_propagate_error (error, data->error);
5484 *new_etag = data->etag;
5485 data->etag = NULL; /* Take ownership */
5491 #define __G_FILE_C__
5492 #include "gioaliasdef.c"