1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2006-2007 Red Hat, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
22 * Author: Alexander Larsson <alexl@redhat.com>
33 #include <sys/types.h>
39 #include "gioscheduler.h"
40 #include "gsimpleasyncresult.h"
41 #include "gfileattribute-priv.h"
42 #include "gfiledescriptorbased.h"
43 #include "gpollfilemonitor.h"
45 #include "gfileinputstream.h"
46 #include "gfileoutputstream.h"
47 #include "glocalfileoutputstream.h"
48 #include "glocalfileiostream.h"
49 #include "gcancellable.h"
50 #include "gasyncresult.h"
57 * @short_description: File and Directory Handling
59 * @see_also: #GFileInfo, #GFileEnumerator
61 * #GFile is a high level abstraction for manipulating files on a
62 * virtual file system. #GFile<!-- -->s are lightweight, immutable
63 * objects that do no I/O upon creation. It is necessary to understand that
64 * #GFile objects do not represent files, merely an identifier for a file. All
65 * file content I/O is implemented as streaming operations (see #GInputStream and
68 * To construct a #GFile, you can use:
69 * g_file_new_for_path() if you have a path.
70 * g_file_new_for_uri() if you have a URI.
71 * g_file_new_for_commandline_arg() for a command line argument.
72 * g_file_new_tmp() to create a temporary file from a template.
73 * g_file_parse_name() from a utf8 string gotten from g_file_get_parse_name().
75 * One way to think of a #GFile is as an abstraction of a pathname. For normal
76 * files the system pathname is what is stored internally, but as #GFile<!-- -->s
77 * are extensible it could also be something else that corresponds to a pathname
78 * in a userspace implementation of a filesystem.
80 * #GFile<!-- -->s make up hierarchies of directories and files that correspond to the
81 * files on a filesystem. You can move through the file system with #GFile using
82 * g_file_get_parent() to get an identifier for the parent directory, g_file_get_child()
83 * to get a child within a directory, g_file_resolve_relative_path() to resolve a relative
84 * path between two #GFile<!-- -->s. There can be multiple hierarchies, so you may not
85 * end up at the same root if you repeatedly call g_file_get_parent() on two different
88 * All #GFile<!-- -->s have a basename (get with g_file_get_basename()). These names
89 * are byte strings that are used to identify the file on the filesystem (relative to
90 * its parent directory) and there is no guarantees that they have any particular charset
91 * encoding or even make any sense at all. If you want to use filenames in a user
92 * interface you should use the display name that you can get by requesting the
93 * %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info().
94 * This is guaranteed to be in utf8 and can be used in a user interface. But always
95 * store the real basename or the #GFile to use to actually access the file, because
96 * there is no way to go from a display name to the actual name.
98 * Using #GFile as an identifier has the same weaknesses as using a path in that
99 * there may be multiple aliases for the same file. For instance, hard or
100 * soft links may cause two different #GFile<!-- -->s to refer to the same file.
101 * Other possible causes for aliases are: case insensitive filesystems, short
102 * and long names on Fat/NTFS, or bind mounts in Linux. If you want to check if
103 * two #GFile<!-- -->s point to the same file you can query for the
104 * %G_FILE_ATTRIBUTE_ID_FILE attribute. Note that #GFile does some trivial
105 * canonicalization of pathnames passed in, so that trivial differences in the
106 * path string used at creation (duplicated slashes, slash at end of path, "."
107 * or ".." path segments, etc) does not create different #GFile<!-- -->s.
109 * Many #GFile operations have both synchronous and asynchronous versions
110 * to suit your application. Asynchronous versions of synchronous functions
111 * simply have _async() appended to their function names. The asynchronous
112 * I/O functions call a #GAsyncReadyCallback which is then used to finalize
113 * the operation, producing a GAsyncResult which is then passed to the
114 * function's matching _finish() operation.
116 * Some #GFile operations do not have synchronous analogs, as they may
117 * take a very long time to finish, and blocking may leave an application
118 * unusable. Notable cases include:
119 * g_file_mount_mountable() to mount a mountable file.
120 * g_file_unmount_mountable_with_operation() to unmount a mountable file.
121 * g_file_eject_mountable_with_operation() to eject a mountable file.
123 * <para id="gfile-etag"><indexterm><primary>entity tag</primary></indexterm>
124 * One notable feature of #GFile<!-- -->s are entity tags, or "etags" for
125 * short. Entity tags are somewhat like a more abstract version of the
126 * traditional mtime, and can be used to quickly determine if the file has
127 * been modified from the version on the file system. See the HTTP 1.1
128 * <ulink url="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">specification</ulink>
129 * for HTTP Etag headers, which are a very similar concept.
133 static void g_file_real_query_info_async (GFile *file,
134 const char *attributes,
135 GFileQueryInfoFlags flags,
137 GCancellable *cancellable,
138 GAsyncReadyCallback callback,
140 static GFileInfo * g_file_real_query_info_finish (GFile *file,
143 static void g_file_real_query_filesystem_info_async (GFile *file,
144 const char *attributes,
146 GCancellable *cancellable,
147 GAsyncReadyCallback callback,
149 static GFileInfo * g_file_real_query_filesystem_info_finish (GFile *file,
152 static void g_file_real_enumerate_children_async (GFile *file,
153 const char *attributes,
154 GFileQueryInfoFlags flags,
156 GCancellable *cancellable,
157 GAsyncReadyCallback callback,
159 static GFileEnumerator * g_file_real_enumerate_children_finish (GFile *file,
162 static void g_file_real_read_async (GFile *file,
164 GCancellable *cancellable,
165 GAsyncReadyCallback callback,
167 static GFileInputStream * g_file_real_read_finish (GFile *file,
170 static void g_file_real_append_to_async (GFile *file,
171 GFileCreateFlags flags,
173 GCancellable *cancellable,
174 GAsyncReadyCallback callback,
176 static GFileOutputStream *g_file_real_append_to_finish (GFile *file,
179 static void g_file_real_create_async (GFile *file,
180 GFileCreateFlags flags,
182 GCancellable *cancellable,
183 GAsyncReadyCallback callback,
185 static GFileOutputStream *g_file_real_create_finish (GFile *file,
188 static void g_file_real_replace_async (GFile *file,
190 gboolean make_backup,
191 GFileCreateFlags flags,
193 GCancellable *cancellable,
194 GAsyncReadyCallback callback,
196 static GFileOutputStream *g_file_real_replace_finish (GFile *file,
199 static void g_file_real_open_readwrite_async (GFile *file,
201 GCancellable *cancellable,
202 GAsyncReadyCallback callback,
204 static GFileIOStream * g_file_real_open_readwrite_finish (GFile *file,
207 static void g_file_real_create_readwrite_async (GFile *file,
208 GFileCreateFlags flags,
210 GCancellable *cancellable,
211 GAsyncReadyCallback callback,
213 static GFileIOStream * g_file_real_create_readwrite_finish (GFile *file,
216 static void g_file_real_replace_readwrite_async (GFile *file,
218 gboolean make_backup,
219 GFileCreateFlags flags,
221 GCancellable *cancellable,
222 GAsyncReadyCallback callback,
224 static GFileIOStream * g_file_real_replace_readwrite_finish (GFile *file,
227 static gboolean g_file_real_set_attributes_from_info (GFile *file,
229 GFileQueryInfoFlags flags,
230 GCancellable *cancellable,
232 static void g_file_real_set_display_name_async (GFile *file,
233 const char *display_name,
235 GCancellable *cancellable,
236 GAsyncReadyCallback callback,
238 static GFile * g_file_real_set_display_name_finish (GFile *file,
241 static void g_file_real_set_attributes_async (GFile *file,
243 GFileQueryInfoFlags flags,
245 GCancellable *cancellable,
246 GAsyncReadyCallback callback,
248 static gboolean g_file_real_set_attributes_finish (GFile *file,
252 static void g_file_real_find_enclosing_mount_async (GFile *file,
254 GCancellable *cancellable,
255 GAsyncReadyCallback callback,
257 static GMount * g_file_real_find_enclosing_mount_finish (GFile *file,
260 static void g_file_real_copy_async (GFile *source,
262 GFileCopyFlags flags,
264 GCancellable *cancellable,
265 GFileProgressCallback progress_callback,
266 gpointer progress_callback_data,
267 GAsyncReadyCallback callback,
269 static gboolean g_file_real_copy_finish (GFile *file,
273 typedef GFileIface GFileInterface;
274 G_DEFINE_INTERFACE (GFile, g_file, G_TYPE_OBJECT)
277 g_file_default_init (GFileIface *iface)
279 iface->enumerate_children_async = g_file_real_enumerate_children_async;
280 iface->enumerate_children_finish = g_file_real_enumerate_children_finish;
281 iface->set_display_name_async = g_file_real_set_display_name_async;
282 iface->set_display_name_finish = g_file_real_set_display_name_finish;
283 iface->query_info_async = g_file_real_query_info_async;
284 iface->query_info_finish = g_file_real_query_info_finish;
285 iface->query_filesystem_info_async = g_file_real_query_filesystem_info_async;
286 iface->query_filesystem_info_finish = g_file_real_query_filesystem_info_finish;
287 iface->set_attributes_async = g_file_real_set_attributes_async;
288 iface->set_attributes_finish = g_file_real_set_attributes_finish;
289 iface->read_async = g_file_real_read_async;
290 iface->read_finish = g_file_real_read_finish;
291 iface->append_to_async = g_file_real_append_to_async;
292 iface->append_to_finish = g_file_real_append_to_finish;
293 iface->create_async = g_file_real_create_async;
294 iface->create_finish = g_file_real_create_finish;
295 iface->replace_async = g_file_real_replace_async;
296 iface->replace_finish = g_file_real_replace_finish;
297 iface->open_readwrite_async = g_file_real_open_readwrite_async;
298 iface->open_readwrite_finish = g_file_real_open_readwrite_finish;
299 iface->create_readwrite_async = g_file_real_create_readwrite_async;
300 iface->create_readwrite_finish = g_file_real_create_readwrite_finish;
301 iface->replace_readwrite_async = g_file_real_replace_readwrite_async;
302 iface->replace_readwrite_finish = g_file_real_replace_readwrite_finish;
303 iface->find_enclosing_mount_async = g_file_real_find_enclosing_mount_async;
304 iface->find_enclosing_mount_finish = g_file_real_find_enclosing_mount_finish;
305 iface->set_attributes_from_info = g_file_real_set_attributes_from_info;
306 iface->copy_async = g_file_real_copy_async;
307 iface->copy_finish = g_file_real_copy_finish;
313 * @file: input #GFile.
315 * Checks to see if a file is native to the platform.
317 * A native file s one expressed in the platform-native filename format,
318 * e.g. "C:\Windows" or "/usr/bin/". This does not mean the file is local,
319 * as it might be on a locally mounted remote filesystem.
321 * On some systems non-native files may be available using
322 * the native filesystem via a userspace filesystem (FUSE), in
323 * these cases this call will return %FALSE, but g_file_get_path()
324 * will still return a native path.
326 * This call does no blocking i/o.
328 * Returns: %TRUE if file is native.
331 g_file_is_native (GFile *file)
335 g_return_val_if_fail (G_IS_FILE (file), FALSE);
337 iface = G_FILE_GET_IFACE (file);
339 return (* iface->is_native) (file);
344 * g_file_has_uri_scheme:
345 * @file: input #GFile.
346 * @uri_scheme: a string containing a URI scheme.
348 * Checks to see if a #GFile has a given URI scheme.
350 * This call does no blocking i/o.
352 * Returns: %TRUE if #GFile's backend supports the
353 * given URI scheme, %FALSE if URI scheme is %NULL,
354 * not supported, or #GFile is invalid.
357 g_file_has_uri_scheme (GFile *file,
358 const char *uri_scheme)
362 g_return_val_if_fail (G_IS_FILE (file), FALSE);
363 g_return_val_if_fail (uri_scheme != NULL, FALSE);
365 iface = G_FILE_GET_IFACE (file);
367 return (* iface->has_uri_scheme) (file, uri_scheme);
372 * g_file_get_uri_scheme:
373 * @file: input #GFile.
375 * Gets the URI scheme for a #GFile.
376 * RFC 3986 decodes the scheme as:
378 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
380 * Common schemes include "file", "http", "ftp", etc.
382 * This call does no blocking i/o.
384 * Returns: a string containing the URI scheme for the given
385 * #GFile. The returned string should be freed with g_free()
386 * when no longer needed.
389 g_file_get_uri_scheme (GFile *file)
393 g_return_val_if_fail (G_IS_FILE (file), NULL);
395 iface = G_FILE_GET_IFACE (file);
397 return (* iface->get_uri_scheme) (file);
402 * g_file_get_basename:
403 * @file: input #GFile.
405 * Gets the base name (the last component of the path) for a given #GFile.
407 * If called for the top level of a system (such as the filesystem root
408 * or a uri like sftp://host/) it will return a single directory separator
409 * (and on Windows, possibly a drive letter).
411 * The base name is a byte string (*not* UTF-8). It has no defined encoding
412 * or rules other than it may not contain zero bytes. If you want to use
413 * filenames in a user interface you should use the display name that you
414 * can get by requesting the %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
415 * attribute with g_file_query_info().
417 * This call does no blocking i/o.
419 * Returns: string containing the #GFile's base name, or %NULL
420 * if given #GFile is invalid. The returned string should be
421 * freed with g_free() when no longer needed.
424 g_file_get_basename (GFile *file)
428 g_return_val_if_fail (G_IS_FILE (file), NULL);
430 iface = G_FILE_GET_IFACE (file);
432 return (* iface->get_basename) (file);
437 * @file: input #GFile.
439 * Gets the local pathname for #GFile, if one exists.
441 * This call does no blocking i/o.
443 * Returns: string containing the #GFile's path, or %NULL if
444 * no such path exists. The returned string should be
445 * freed with g_free() when no longer needed.
448 g_file_get_path (GFile *file)
452 g_return_val_if_fail (G_IS_FILE (file), NULL);
454 iface = G_FILE_GET_IFACE (file);
456 return (* iface->get_path) (file);
461 * @file: input #GFile.
463 * Gets the URI for the @file.
465 * This call does no blocking i/o.
467 * Returns: a string containing the #GFile's URI.
468 * The returned string should be freed with g_free() when no longer needed.
471 g_file_get_uri (GFile *file)
475 g_return_val_if_fail (G_IS_FILE (file), NULL);
477 iface = G_FILE_GET_IFACE (file);
479 return (* iface->get_uri) (file);
483 * g_file_get_parse_name:
484 * @file: input #GFile.
486 * Gets the parse name of the @file.
487 * A parse name is a UTF-8 string that describes the
488 * file such that one can get the #GFile back using
489 * g_file_parse_name().
491 * This is generally used to show the #GFile as a nice
492 * full-pathname kind of string in a user interface,
493 * like in a location entry.
495 * For local files with names that can safely be converted
496 * to UTF8 the pathname is used, otherwise the IRI is used
497 * (a form of URI that allows UTF8 characters unescaped).
499 * This call does no blocking i/o.
501 * Returns: a string containing the #GFile's parse name. The returned
502 * string should be freed with g_free() when no longer needed.
505 g_file_get_parse_name (GFile *file)
509 g_return_val_if_fail (G_IS_FILE (file), NULL);
511 iface = G_FILE_GET_IFACE (file);
513 return (* iface->get_parse_name) (file);
518 * @file: input #GFile.
520 * Duplicates a #GFile handle. This operation does not duplicate
521 * the actual file or directory represented by the #GFile; see
522 * g_file_copy() if attempting to copy a file.
524 * This call does no blocking i/o.
526 * Returns: (transfer full): a new #GFile that is a duplicate of the given #GFile.
529 g_file_dup (GFile *file)
533 g_return_val_if_fail (G_IS_FILE (file), NULL);
535 iface = G_FILE_GET_IFACE (file);
537 return (* iface->dup) (file);
542 * @file: (type GFile): #gconstpointer to a #GFile.
544 * Creates a hash value for a #GFile.
546 * This call does no blocking i/o.
549 * Returns: 0 if @file is not a valid #GFile, otherwise an
550 * integer that can be used as hash value for the #GFile.
551 * This function is intended for easily hashing a #GFile to
552 * add to a #GHashTable or similar data structure.
555 g_file_hash (gconstpointer file)
559 g_return_val_if_fail (G_IS_FILE (file), 0);
561 iface = G_FILE_GET_IFACE (file);
563 return (* iface->hash) ((GFile *)file);
568 * @file1: the first #GFile.
569 * @file2: the second #GFile.
571 * Checks equality of two given #GFile<!-- -->s. Note that two
572 * #GFile<!-- -->s that differ can still refer to the same
573 * file on the filesystem due to various forms of filename
576 * This call does no blocking i/o.
578 * Returns: %TRUE if @file1 and @file2 are equal.
579 * %FALSE if either is not a #GFile.
582 g_file_equal (GFile *file1,
587 g_return_val_if_fail (G_IS_FILE (file1), FALSE);
588 g_return_val_if_fail (G_IS_FILE (file2), FALSE);
590 if (G_TYPE_FROM_INSTANCE (file1) != G_TYPE_FROM_INSTANCE (file2))
593 iface = G_FILE_GET_IFACE (file1);
595 return (* iface->equal) (file1, file2);
601 * @file: input #GFile.
603 * Gets the parent directory for the @file.
604 * If the @file represents the root directory of the
605 * file system, then %NULL will be returned.
607 * This call does no blocking i/o.
609 * Returns: (transfer full): a #GFile structure to the parent of the given
610 * #GFile or %NULL if there is no parent.
611 * Free the returned object with g_object_unref().
614 g_file_get_parent (GFile *file)
618 g_return_val_if_fail (G_IS_FILE (file), NULL);
620 iface = G_FILE_GET_IFACE (file);
622 return (* iface->get_parent) (file);
627 * @file: input #GFile
628 * @parent: (allow-none): the parent to check for, or %NULL
630 * Checks if @file has a parent, and optionally, if it is @parent.
632 * If @parent is %NULL then this function returns %TRUE if @file has any
633 * parent at all. If @parent is non-%NULL then %TRUE is only returned
634 * if @file is a child of @parent.
636 * Returns: %TRUE if @file is a child of @parent (or any parent in the
637 * case that @parent is %NULL).
642 g_file_has_parent (GFile *file,
645 GFile *actual_parent;
648 g_return_val_if_fail (G_IS_FILE (file), FALSE);
649 g_return_val_if_fail (parent == NULL || G_IS_FILE (parent), FALSE);
651 actual_parent = g_file_get_parent (file);
653 if (actual_parent != NULL)
656 result = g_file_equal (parent, actual_parent);
660 g_object_unref (actual_parent);
670 * @file: input #GFile.
671 * @name: string containing the child's basename.
673 * Gets a child of @file with basename equal to @name.
675 * Note that the file with that specific name might not exist, but
676 * you can still have a #GFile that points to it. You can use this
677 * for instance to create that file.
679 * This call does no blocking i/o.
681 * Returns: (transfer full): a #GFile to a child specified by @name.
682 * Free the returned object with g_object_unref().
685 g_file_get_child (GFile *file,
688 g_return_val_if_fail (G_IS_FILE (file), NULL);
689 g_return_val_if_fail (name != NULL, NULL);
691 return g_file_resolve_relative_path (file, name);
695 * g_file_get_child_for_display_name:
696 * @file: input #GFile.
697 * @display_name: string to a possible child.
700 * Gets the child of @file for a given @display_name (i.e. a UTF8
701 * version of the name). If this function fails, it returns %NULL and @error will be
702 * set. This is very useful when constructing a GFile for a new file
703 * and the user entered the filename in the user interface, for instance
704 * when you select a directory and type a filename in the file selector.
706 * This call does no blocking i/o.
708 * Returns: (transfer full): a #GFile to the specified child, or
709 * %NULL if the display name couldn't be converted.
710 * Free the returned object with g_object_unref().
713 g_file_get_child_for_display_name (GFile *file,
714 const char *display_name,
719 g_return_val_if_fail (G_IS_FILE (file), NULL);
720 g_return_val_if_fail (display_name != NULL, NULL);
722 iface = G_FILE_GET_IFACE (file);
724 return (* iface->get_child_for_display_name) (file, display_name, error);
729 * @file: input #GFile.
730 * @prefix: input #GFile.
732 * Checks whether @file has the prefix specified by @prefix. In other word,
733 * if the names of initial elements of @file<!-- -->s pathname match @prefix.
734 * Only full pathname elements are matched, so a path like /foo is not
735 * considered a prefix of /foobar, only of /foo/bar.
737 * This call does no i/o, as it works purely on names. As such it can
738 * sometimes return %FALSE even if @file is inside a @prefix (from a
739 * filesystem point of view), because the prefix of @file is an alias
742 * Virtual: prefix_matches
743 * Returns: %TRUE if the @files's parent, grandparent, etc is @prefix.
747 g_file_has_prefix (GFile *file,
752 g_return_val_if_fail (G_IS_FILE (file), FALSE);
753 g_return_val_if_fail (G_IS_FILE (prefix), FALSE);
755 if (G_TYPE_FROM_INSTANCE (file) != G_TYPE_FROM_INSTANCE (prefix))
758 iface = G_FILE_GET_IFACE (file);
760 /* The vtable function differs in arg order since we're
761 using the old contains_file call */
762 return (* iface->prefix_matches) (prefix, file);
766 * g_file_get_relative_path:
767 * @parent: input #GFile.
768 * @descendant: input #GFile.
770 * Gets the path for @descendant relative to @parent.
772 * This call does no blocking i/o.
774 * Returns: string with the relative path from @descendant
775 * to @parent, or %NULL if @descendant doesn't have @parent as prefix.
776 * The returned string should be freed with g_free() when no longer needed.
779 g_file_get_relative_path (GFile *parent,
784 g_return_val_if_fail (G_IS_FILE (parent), NULL);
785 g_return_val_if_fail (G_IS_FILE (descendant), NULL);
787 if (G_TYPE_FROM_INSTANCE (parent) != G_TYPE_FROM_INSTANCE (descendant))
790 iface = G_FILE_GET_IFACE (parent);
792 return (* iface->get_relative_path) (parent, descendant);
796 * g_file_resolve_relative_path:
797 * @file: input #GFile.
798 * @relative_path: a given relative path string.
800 * Resolves a relative path for @file to an absolute path.
802 * This call does no blocking i/o.
804 * Returns: (transfer full): #GFile to the resolved path. %NULL if @relative_path
805 * is %NULL or if @file is invalid.
806 * Free the returned object with g_object_unref().
809 g_file_resolve_relative_path (GFile *file,
810 const char *relative_path)
814 g_return_val_if_fail (G_IS_FILE (file), NULL);
815 g_return_val_if_fail (relative_path != NULL, NULL);
817 iface = G_FILE_GET_IFACE (file);
819 return (* iface->resolve_relative_path) (file, relative_path);
823 * g_file_enumerate_children:
824 * @file: input #GFile.
825 * @attributes: an attribute query string.
826 * @flags: a set of #GFileQueryInfoFlags.
827 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
828 * @error: #GError for error reporting.
830 * Gets the requested information about the files in a directory. The result
831 * is a #GFileEnumerator object that will give out #GFileInfo objects for
832 * all the files in the directory.
834 * The @attributes value is a string that specifies the file attributes that
835 * should be gathered. It is not an error if it's not possible to read a particular
836 * requested attribute from a file - it just won't be set. @attributes should
837 * be a comma-separated list of attributes or attribute wildcards. The wildcard "*"
838 * means all attributes, and a wildcard like "standard::*" means all attributes in the standard
839 * namespace. An example attribute query be "standard::*,owner::user".
840 * The standard attributes are available as defines, like #G_FILE_ATTRIBUTE_STANDARD_NAME.
842 * If @cancellable is not %NULL, then the operation can be cancelled by
843 * triggering the cancellable object from another thread. If the operation
844 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
846 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
847 * If the file is not a directory, the G_FILE_ERROR_NOTDIR error will be returned.
848 * Other errors are possible too.
850 * Returns: (transfer full): A #GFileEnumerator if successful, %NULL on error.
851 * Free the returned object with g_object_unref().
854 g_file_enumerate_children (GFile *file,
855 const char *attributes,
856 GFileQueryInfoFlags flags,
857 GCancellable *cancellable,
863 g_return_val_if_fail (G_IS_FILE (file), NULL);
865 if (g_cancellable_set_error_if_cancelled (cancellable, error))
868 iface = G_FILE_GET_IFACE (file);
870 if (iface->enumerate_children == NULL)
872 g_set_error_literal (error, G_IO_ERROR,
873 G_IO_ERROR_NOT_SUPPORTED,
874 _("Operation not supported"));
878 return (* iface->enumerate_children) (file, attributes, flags,
883 * g_file_enumerate_children_async:
884 * @file: input #GFile.
885 * @attributes: an attribute query string.
886 * @flags: a set of #GFileQueryInfoFlags.
887 * @io_priority: the <link linkend="io-priority">I/O priority</link>
889 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
890 * @callback: (scope async) : a #GAsyncReadyCallback to call when the
891 * request is satisfied
892 * @user_data: (closure): the data to pass to callback function
894 * Asynchronously gets the requested information about the files in a directory. The result
895 * is a #GFileEnumerator object that will give out #GFileInfo objects for
896 * all the files in the directory.
898 * For more details, see g_file_enumerate_children() which is
899 * the synchronous version of this call.
901 * When the operation is finished, @callback will be called. You can then call
902 * g_file_enumerate_children_finish() to get the result of the operation.
905 g_file_enumerate_children_async (GFile *file,
906 const char *attributes,
907 GFileQueryInfoFlags flags,
909 GCancellable *cancellable,
910 GAsyncReadyCallback callback,
915 g_return_if_fail (G_IS_FILE (file));
917 iface = G_FILE_GET_IFACE (file);
918 (* iface->enumerate_children_async) (file,
928 * g_file_enumerate_children_finish:
929 * @file: input #GFile.
930 * @res: a #GAsyncResult.
933 * Finishes an async enumerate children operation.
934 * See g_file_enumerate_children_async().
936 * Returns: (transfer full): a #GFileEnumerator or %NULL if an error occurred.
937 * Free the returned object with g_object_unref().
940 g_file_enumerate_children_finish (GFile *file,
946 g_return_val_if_fail (G_IS_FILE (file), NULL);
947 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
949 if (g_async_result_legacy_propagate_error (res, error))
952 iface = G_FILE_GET_IFACE (file);
953 return (* iface->enumerate_children_finish) (file, res, error);
957 * g_file_query_exists:
958 * @file: input #GFile.
959 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
961 * Utility function to check if a particular file exists. This is
962 * implemented using g_file_query_info() and as such does blocking I/O.
964 * Note that in many cases it is racy to first check for file existence
965 * and then execute something based on the outcome of that, because the
966 * file might have been created or removed in between the operations. The
967 * general approach to handling that is to not check, but just do the
968 * operation and handle the errors as they come.
970 * As an example of race-free checking, take the case of reading a file, and
971 * if it doesn't exist, creating it. There are two racy versions: read it, and
972 * on error create it; and: check if it exists, if not create it. These
973 * can both result in two processes creating the file (with perhaps a partially
974 * written file as the result). The correct approach is to always try to create
975 * the file with g_file_create() which will either atomically create the file
976 * or fail with a G_IO_ERROR_EXISTS error.
978 * However, in many cases an existence check is useful in a user
979 * interface, for instance to make a menu item sensitive/insensitive, so that
980 * you don't have to fool users that something is possible and then just show
981 * and error dialog. If you do this, you should make sure to also handle the
982 * errors that can happen due to races when you execute the operation.
984 * Returns: %TRUE if the file exists (and can be detected without error), %FALSE otherwise (or if cancelled).
987 g_file_query_exists (GFile *file,
988 GCancellable *cancellable)
992 g_return_val_if_fail (G_IS_FILE(file), FALSE);
994 info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE,
995 G_FILE_QUERY_INFO_NONE, cancellable, NULL);
998 g_object_unref (info);
1006 * g_file_query_file_type:
1007 * @file: input #GFile.
1008 * @flags: a set of #GFileQueryInfoFlags passed to g_file_query_info().
1009 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1011 * Utility function to inspect the #GFileType of a file. This is
1012 * implemented using g_file_query_info() and as such does blocking I/O.
1014 * The primary use case of this method is to check if a file is a regular file,
1015 * directory, or symlink.
1017 * Returns: The #GFileType of the file and #G_FILE_TYPE_UNKNOWN if the file
1023 g_file_query_file_type (GFile *file,
1024 GFileQueryInfoFlags flags,
1025 GCancellable *cancellable)
1028 GFileType file_type;
1030 g_return_val_if_fail (G_IS_FILE(file), G_FILE_TYPE_UNKNOWN);
1031 info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, flags,
1035 file_type = g_file_info_get_file_type (info);
1036 g_object_unref (info);
1039 file_type = G_FILE_TYPE_UNKNOWN;
1045 * g_file_query_info:
1046 * @file: input #GFile.
1047 * @attributes: an attribute query string.
1048 * @flags: a set of #GFileQueryInfoFlags.
1049 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1050 * @error: a #GError.
1052 * Gets the requested information about specified @file. The result
1053 * is a #GFileInfo object that contains key-value attributes (such as
1054 * the type or size of the file).
1056 * The @attributes value is a string that specifies the file attributes that
1057 * should be gathered. It is not an error if it's not possible to read a particular
1058 * requested attribute from a file - it just won't be set. @attributes should
1059 * be a comma-separated list of attributes or attribute wildcards. The wildcard "*"
1060 * means all attributes, and a wildcard like "standard::*" means all attributes in the standard
1061 * namespace. An example attribute query be "standard::*,owner::user".
1062 * The standard attributes are available as defines, like #G_FILE_ATTRIBUTE_STANDARD_NAME.
1064 * If @cancellable is not %NULL, then the operation can be cancelled by
1065 * triggering the cancellable object from another thread. If the operation
1066 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1068 * For symlinks, normally the information about the target of the
1069 * symlink is returned, rather than information about the symlink itself.
1070 * However if you pass #G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS in @flags the
1071 * information about the symlink itself will be returned. Also, for symlinks
1072 * that point to non-existing files the information about the symlink itself
1075 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1076 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1078 * Returns: (transfer full): a #GFileInfo for the given @file, or %NULL on error.
1079 * Free the returned object with g_object_unref().
1082 g_file_query_info (GFile *file,
1083 const char *attributes,
1084 GFileQueryInfoFlags flags,
1085 GCancellable *cancellable,
1090 g_return_val_if_fail (G_IS_FILE (file), NULL);
1092 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1095 iface = G_FILE_GET_IFACE (file);
1097 if (iface->query_info == NULL)
1099 g_set_error_literal (error, G_IO_ERROR,
1100 G_IO_ERROR_NOT_SUPPORTED,
1101 _("Operation not supported"));
1105 return (* iface->query_info) (file, attributes, flags, cancellable, error);
1109 * g_file_query_info_async:
1110 * @file: input #GFile.
1111 * @attributes: an attribute query string.
1112 * @flags: a set of #GFileQueryInfoFlags.
1113 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1115 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1116 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1117 * @user_data: (closure): the data to pass to callback function
1119 * Asynchronously gets the requested information about specified @file. The result
1120 * is a #GFileInfo object that contains key-value attributes (such as type or size
1123 * For more details, see g_file_query_info() which is
1124 * the synchronous version of this call.
1126 * When the operation is finished, @callback will be called. You can then call
1127 * g_file_query_info_finish() to get the result of the operation.
1130 g_file_query_info_async (GFile *file,
1131 const char *attributes,
1132 GFileQueryInfoFlags flags,
1134 GCancellable *cancellable,
1135 GAsyncReadyCallback callback,
1140 g_return_if_fail (G_IS_FILE (file));
1142 iface = G_FILE_GET_IFACE (file);
1143 (* iface->query_info_async) (file,
1153 * g_file_query_info_finish:
1154 * @file: input #GFile.
1155 * @res: a #GAsyncResult.
1156 * @error: a #GError.
1158 * Finishes an asynchronous file info query.
1159 * See g_file_query_info_async().
1161 * Returns: (transfer full): #GFileInfo for given @file or %NULL on error.
1162 * Free the returned object with g_object_unref().
1165 g_file_query_info_finish (GFile *file,
1171 g_return_val_if_fail (G_IS_FILE (file), NULL);
1172 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1174 if (g_async_result_legacy_propagate_error (res, error))
1177 iface = G_FILE_GET_IFACE (file);
1178 return (* iface->query_info_finish) (file, res, error);
1182 * g_file_query_filesystem_info:
1183 * @file: input #GFile.
1184 * @attributes: an attribute query string.
1185 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1186 * @error: a #GError.
1188 * Similar to g_file_query_info(), but obtains information
1189 * about the filesystem the @file is on, rather than the file itself.
1190 * For instance the amount of space available and the type of
1193 * The @attributes value is a string that specifies the file attributes that
1194 * should be gathered. It is not an error if it's not possible to read a particular
1195 * requested attribute from a file - it just won't be set. @attributes should
1196 * be a comma-separated list of attributes or attribute wildcards. The wildcard "*"
1197 * means all attributes, and a wildcard like "filesystem::*" means all attributes in the
1198 * filesystem namespace. The standard namespace for filesystem attributes is "filesystem".
1199 * Common attributes of interest are #G_FILE_ATTRIBUTE_FILESYSTEM_SIZE
1200 * (the total size of the filesystem in bytes), #G_FILE_ATTRIBUTE_FILESYSTEM_FREE (number of
1201 * bytes available), and #G_FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).
1203 * If @cancellable is not %NULL, then the operation can be cancelled by
1204 * triggering the cancellable object from another thread. If the operation
1205 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1207 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1208 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1210 * Returns: (transfer full): a #GFileInfo or %NULL if there was an error.
1211 * Free the returned object with g_object_unref().
1214 g_file_query_filesystem_info (GFile *file,
1215 const char *attributes,
1216 GCancellable *cancellable,
1221 g_return_val_if_fail (G_IS_FILE (file), NULL);
1223 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1226 iface = G_FILE_GET_IFACE (file);
1228 if (iface->query_filesystem_info == NULL)
1230 g_set_error_literal (error, G_IO_ERROR,
1231 G_IO_ERROR_NOT_SUPPORTED,
1232 _("Operation not supported"));
1236 return (* iface->query_filesystem_info) (file, attributes, cancellable, error);
1240 * g_file_query_filesystem_info_async:
1241 * @file: input #GFile.
1242 * @attributes: an attribute query string.
1243 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1245 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1246 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1247 * @user_data: (closure): the data to pass to callback function
1249 * Asynchronously gets the requested information about the filesystem
1250 * that the specified @file is on. The result is a #GFileInfo object
1251 * that contains key-value attributes (such as type or size for the
1254 * For more details, see g_file_query_filesystem_info() which is the
1255 * synchronous version of this call.
1257 * When the operation is finished, @callback will be called. You can
1258 * then call g_file_query_info_finish() to get the result of the
1262 g_file_query_filesystem_info_async (GFile *file,
1263 const char *attributes,
1265 GCancellable *cancellable,
1266 GAsyncReadyCallback callback,
1271 g_return_if_fail (G_IS_FILE (file));
1273 iface = G_FILE_GET_IFACE (file);
1274 (* iface->query_filesystem_info_async) (file,
1283 * g_file_query_filesystem_info_finish:
1284 * @file: input #GFile.
1285 * @res: a #GAsyncResult.
1286 * @error: a #GError.
1288 * Finishes an asynchronous filesystem info query. See
1289 * g_file_query_filesystem_info_async().
1291 * Returns: (transfer full): #GFileInfo for given @file or %NULL on error.
1292 * Free the returned object with g_object_unref().
1295 g_file_query_filesystem_info_finish (GFile *file,
1301 g_return_val_if_fail (G_IS_FILE (file), NULL);
1302 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1304 if (g_async_result_legacy_propagate_error (res, error))
1307 iface = G_FILE_GET_IFACE (file);
1308 return (* iface->query_filesystem_info_finish) (file, res, error);
1312 * g_file_find_enclosing_mount:
1313 * @file: input #GFile.
1314 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1315 * @error: a #GError.
1317 * Gets a #GMount for the #GFile.
1319 * If the #GFileIface for @file does not have a mount (e.g. possibly a
1320 * remote share), @error will be set to %G_IO_ERROR_NOT_FOUND and %NULL
1323 * If @cancellable is not %NULL, then the operation can be cancelled by
1324 * triggering the cancellable object from another thread. If the operation
1325 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1327 * Returns: (transfer full): a #GMount where the @file is located or %NULL on error.
1328 * Free the returned object with g_object_unref().
1331 g_file_find_enclosing_mount (GFile *file,
1332 GCancellable *cancellable,
1337 g_return_val_if_fail (G_IS_FILE (file), NULL);
1339 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1342 iface = G_FILE_GET_IFACE (file);
1343 if (iface->find_enclosing_mount == NULL)
1346 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1347 /* Translators: This is an error message when trying to find the
1348 * enclosing (user visible) mount of a file, but none exists. */
1349 _("Containing mount does not exist"));
1353 return (* iface->find_enclosing_mount) (file, cancellable, error);
1357 * g_file_find_enclosing_mount_async:
1359 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1361 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1362 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1363 * @user_data: (closure): the data to pass to callback function
1365 * Asynchronously gets the mount for the file.
1367 * For more details, see g_file_find_enclosing_mount() which is
1368 * the synchronous version of this call.
1370 * When the operation is finished, @callback will be called. You can then call
1371 * g_file_find_enclosing_mount_finish() to get the result of the operation.
1374 g_file_find_enclosing_mount_async (GFile *file,
1376 GCancellable *cancellable,
1377 GAsyncReadyCallback callback,
1382 g_return_if_fail (G_IS_FILE (file));
1384 iface = G_FILE_GET_IFACE (file);
1385 (* iface->find_enclosing_mount_async) (file,
1393 * g_file_find_enclosing_mount_finish:
1395 * @res: a #GAsyncResult
1398 * Finishes an asynchronous find mount request.
1399 * See g_file_find_enclosing_mount_async().
1401 * Returns: (transfer full): #GMount for given @file or %NULL on error.
1402 * Free the returned object with g_object_unref().
1405 g_file_find_enclosing_mount_finish (GFile *file,
1411 g_return_val_if_fail (G_IS_FILE (file), NULL);
1412 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1414 if (g_async_result_legacy_propagate_error (res, error))
1417 iface = G_FILE_GET_IFACE (file);
1418 return (* iface->find_enclosing_mount_finish) (file, res, error);
1424 * @file: #GFile to read.
1425 * @cancellable: (allow-none): a #GCancellable
1426 * @error: a #GError, or %NULL
1428 * Opens a file for reading. The result is a #GFileInputStream that
1429 * can be used to read the contents of the file.
1431 * If @cancellable is not %NULL, then the operation can be cancelled by
1432 * triggering the cancellable object from another thread. If the operation
1433 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1435 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1436 * If the file is a directory, the G_IO_ERROR_IS_DIRECTORY error will be returned.
1437 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1440 * Returns: (transfer full): #GFileInputStream or %NULL on error.
1441 * Free the returned object with g_object_unref().
1444 g_file_read (GFile *file,
1445 GCancellable *cancellable,
1450 g_return_val_if_fail (G_IS_FILE (file), NULL);
1452 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1455 iface = G_FILE_GET_IFACE (file);
1457 if (iface->read_fn == NULL)
1459 g_set_error_literal (error, G_IO_ERROR,
1460 G_IO_ERROR_NOT_SUPPORTED,
1461 _("Operation not supported"));
1465 return (* iface->read_fn) (file, cancellable, error);
1470 * @file: input #GFile.
1471 * @flags: a set of #GFileCreateFlags.
1472 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1473 * @error: a #GError, or %NULL
1475 * Gets an output stream for appending data to the file. If
1476 * the file doesn't already exist it is created.
1478 * By default files created are generally readable by everyone,
1479 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1480 * will be made readable only to the current user, to the level that
1481 * is supported on the target filesystem.
1483 * If @cancellable is not %NULL, then the operation can be cancelled by
1484 * triggering the cancellable object from another thread. If the operation
1485 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1487 * Some file systems don't allow all file names, and may
1488 * return an %G_IO_ERROR_INVALID_FILENAME error.
1489 * If the file is a directory the %G_IO_ERROR_IS_DIRECTORY error will be
1490 * returned. Other errors are possible too, and depend on what kind of
1491 * filesystem the file is on.
1493 * Returns: (transfer full): a #GFileOutputStream, or %NULL on error.
1494 * Free the returned object with g_object_unref().
1497 g_file_append_to (GFile *file,
1498 GFileCreateFlags flags,
1499 GCancellable *cancellable,
1504 g_return_val_if_fail (G_IS_FILE (file), NULL);
1506 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1509 iface = G_FILE_GET_IFACE (file);
1511 if (iface->append_to == NULL)
1513 g_set_error_literal (error, G_IO_ERROR,
1514 G_IO_ERROR_NOT_SUPPORTED,
1515 _("Operation not supported"));
1519 return (* iface->append_to) (file, flags, cancellable, error);
1524 * @file: input #GFile.
1525 * @flags: a set of #GFileCreateFlags.
1526 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1527 * @error: a #GError, or %NULL
1529 * Creates a new file and returns an output stream for writing to it.
1530 * The file must not already exist.
1532 * By default files created are generally readable by everyone,
1533 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1534 * will be made readable only to the current user, to the level that
1535 * is supported on the target filesystem.
1537 * If @cancellable is not %NULL, then the operation can be cancelled by
1538 * triggering the cancellable object from another thread. If the operation
1539 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1541 * If a file or directory with this name already exists the G_IO_ERROR_EXISTS
1542 * error will be returned.
1543 * Some file systems don't allow all file names, and may
1544 * return an G_IO_ERROR_INVALID_FILENAME error, and if the name
1545 * is to long G_IO_ERROR_FILENAME_TOO_LONG will be returned.
1546 * Other errors are possible too, and depend on what kind of
1547 * filesystem the file is on.
1549 * Returns: (transfer full): a #GFileOutputStream for the newly created file, or
1551 * Free the returned object with g_object_unref().
1554 g_file_create (GFile *file,
1555 GFileCreateFlags flags,
1556 GCancellable *cancellable,
1561 g_return_val_if_fail (G_IS_FILE (file), NULL);
1563 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1566 iface = G_FILE_GET_IFACE (file);
1568 if (iface->create == NULL)
1570 g_set_error_literal (error, G_IO_ERROR,
1571 G_IO_ERROR_NOT_SUPPORTED,
1572 _("Operation not supported"));
1576 return (* iface->create) (file, flags, cancellable, error);
1581 * @file: input #GFile.
1582 * @etag: (allow-none): an optional <link linkend="gfile-etag">entity tag</link> for the
1583 * current #GFile, or #NULL to ignore.
1584 * @make_backup: %TRUE if a backup should be created.
1585 * @flags: a set of #GFileCreateFlags.
1586 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1587 * @error: a #GError, or %NULL
1589 * Returns an output stream for overwriting the file, possibly
1590 * creating a backup copy of the file first. If the file doesn't exist,
1591 * it will be created.
1593 * This will try to replace the file in the safest way possible so
1594 * that any errors during the writing will not affect an already
1595 * existing copy of the file. For instance, for local files it
1596 * may write to a temporary file and then atomically rename over
1597 * the destination when the stream is closed.
1599 * By default files created are generally readable by everyone,
1600 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1601 * will be made readable only to the current user, to the level that
1602 * is supported on the target filesystem.
1604 * If @cancellable is not %NULL, then the operation can be cancelled by
1605 * triggering the cancellable object from another thread. If the operation
1606 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1608 * If you pass in a non-#NULL @etag value, then this value is
1609 * compared to the current entity tag of the file, and if they differ
1610 * an G_IO_ERROR_WRONG_ETAG error is returned. This generally means
1611 * that the file has been changed since you last read it. You can get
1612 * the new etag from g_file_output_stream_get_etag() after you've
1613 * finished writing and closed the #GFileOutputStream. When you load
1614 * a new file you can use g_file_input_stream_query_info() to get
1615 * the etag of the file.
1617 * If @make_backup is %TRUE, this function will attempt to make a backup
1618 * of the current file before overwriting it. If this fails a G_IO_ERROR_CANT_CREATE_BACKUP
1619 * error will be returned. If you want to replace anyway, try again with
1620 * @make_backup set to %FALSE.
1622 * If the file is a directory the G_IO_ERROR_IS_DIRECTORY error will be returned,
1623 * and if the file is some other form of non-regular file then a
1624 * G_IO_ERROR_NOT_REGULAR_FILE error will be returned.
1625 * Some file systems don't allow all file names, and may
1626 * return an G_IO_ERROR_INVALID_FILENAME error, and if the name
1627 * is to long G_IO_ERROR_FILENAME_TOO_LONG will be returned.
1628 * Other errors are possible too, and depend on what kind of
1629 * filesystem the file is on.
1631 * Returns: (transfer full): a #GFileOutputStream or %NULL on error.
1632 * Free the returned object with g_object_unref().
1635 g_file_replace (GFile *file,
1637 gboolean make_backup,
1638 GFileCreateFlags flags,
1639 GCancellable *cancellable,
1644 g_return_val_if_fail (G_IS_FILE (file), NULL);
1646 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1649 iface = G_FILE_GET_IFACE (file);
1651 if (iface->replace == NULL)
1653 g_set_error_literal (error, G_IO_ERROR,
1654 G_IO_ERROR_NOT_SUPPORTED,
1655 _("Operation not supported"));
1660 /* Handle empty tag string as NULL in consistent way. */
1661 if (etag && *etag == 0)
1664 return (* iface->replace) (file, etag, make_backup, flags, cancellable, error);
1668 * g_file_open_readwrite:
1669 * @file: #GFile to open
1670 * @cancellable: (allow-none): a #GCancellable
1671 * @error: a #GError, or %NULL
1673 * Opens an existing file for reading and writing. The result is
1674 * a #GFileIOStream that can be used to read and write the contents of the file.
1676 * If @cancellable is not %NULL, then the operation can be cancelled by
1677 * triggering the cancellable object from another thread. If the operation
1678 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1680 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1681 * If the file is a directory, the G_IO_ERROR_IS_DIRECTORY error will be returned.
1682 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1683 * Note that in many non-local file cases read and write streams are not supported,
1684 * so make sure you really need to do read and write streaming, rather than
1685 * just opening for reading or writing.
1687 * Returns: (transfer full): #GFileIOStream or %NULL on error.
1688 * Free the returned object with g_object_unref().
1693 g_file_open_readwrite (GFile *file,
1694 GCancellable *cancellable,
1699 g_return_val_if_fail (G_IS_FILE (file), NULL);
1701 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1704 iface = G_FILE_GET_IFACE (file);
1706 if (iface->open_readwrite == NULL)
1708 g_set_error_literal (error, G_IO_ERROR,
1709 G_IO_ERROR_NOT_SUPPORTED,
1710 _("Operation not supported"));
1714 return (* iface->open_readwrite) (file, cancellable, error);
1718 * g_file_create_readwrite:
1720 * @flags: a set of #GFileCreateFlags
1721 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
1722 * @error: return location for a #GError, or %NULL
1724 * Creates a new file and returns a stream for reading and writing to it.
1725 * The file must not already exist.
1727 * By default files created are generally readable by everyone,
1728 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1729 * will be made readable only to the current user, to the level that
1730 * is supported on the target filesystem.
1732 * If @cancellable is not %NULL, then the operation can be cancelled by
1733 * triggering the cancellable object from another thread. If the operation
1734 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1736 * If a file or directory with this name already exists the %G_IO_ERROR_EXISTS
1737 * error will be returned. Some file systems don't allow all file names,
1738 * and may return an %G_IO_ERROR_INVALID_FILENAME error, and if the name
1739 * is too long, %G_IO_ERROR_FILENAME_TOO_LONG will be returned. Other errors
1740 * are possible too, and depend on what kind of filesystem the file is on.
1742 * Note that in many non-local file cases read and write streams are not
1743 * supported, so make sure you really need to do read and write streaming,
1744 * rather than just opening for reading or writing.
1746 * Returns: (transfer full): a #GFileIOStream for the newly created file, or %NULL on error.
1747 * Free the returned object with g_object_unref().
1752 g_file_create_readwrite (GFile *file,
1753 GFileCreateFlags flags,
1754 GCancellable *cancellable,
1759 g_return_val_if_fail (G_IS_FILE (file), NULL);
1761 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1764 iface = G_FILE_GET_IFACE (file);
1766 if (iface->create_readwrite == NULL)
1768 g_set_error_literal (error, G_IO_ERROR,
1769 G_IO_ERROR_NOT_SUPPORTED,
1770 _("Operation not supported"));
1774 return (* iface->create_readwrite) (file, flags, cancellable, error);
1778 * g_file_replace_readwrite:
1780 * @etag: (allow-none): an optional <link linkend="gfile-etag">entity tag</link> for the
1781 * current #GFile, or #NULL to ignore
1782 * @make_backup: %TRUE if a backup should be created
1783 * @flags: a set of #GFileCreateFlags
1784 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
1785 * @error: return location for a #GError, or %NULL
1787 * Returns an output stream for overwriting the file in readwrite mode,
1788 * possibly creating a backup copy of the file first. If the file doesn't
1789 * exist, it will be created.
1791 * For details about the behaviour, see g_file_replace() which does the same
1792 * thing but returns an output stream only.
1794 * Note that in many non-local file cases read and write streams are not
1795 * supported, so make sure you really need to do read and write streaming,
1796 * rather than just opening for reading or writing.
1798 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
1799 * Free the returned object with g_object_unref().
1804 g_file_replace_readwrite (GFile *file,
1806 gboolean make_backup,
1807 GFileCreateFlags flags,
1808 GCancellable *cancellable,
1813 g_return_val_if_fail (G_IS_FILE (file), NULL);
1815 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1818 iface = G_FILE_GET_IFACE (file);
1820 if (iface->replace_readwrite == NULL)
1822 g_set_error_literal (error, G_IO_ERROR,
1823 G_IO_ERROR_NOT_SUPPORTED,
1824 _("Operation not supported"));
1828 return (* iface->replace_readwrite) (file, etag, make_backup, flags, cancellable, error);
1832 * g_file_read_async:
1833 * @file: input #GFile
1834 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1836 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1837 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1838 * @user_data: (closure): the data to pass to callback function
1840 * Asynchronously opens @file for reading.
1842 * For more details, see g_file_read() which is
1843 * the synchronous version of this call.
1845 * When the operation is finished, @callback will be called. You can then call
1846 * g_file_read_finish() to get the result of the operation.
1849 g_file_read_async (GFile *file,
1851 GCancellable *cancellable,
1852 GAsyncReadyCallback callback,
1857 g_return_if_fail (G_IS_FILE (file));
1859 iface = G_FILE_GET_IFACE (file);
1860 (* iface->read_async) (file,
1868 * g_file_read_finish:
1869 * @file: input #GFile.
1870 * @res: a #GAsyncResult.
1871 * @error: a #GError, or %NULL
1873 * Finishes an asynchronous file read operation started with
1874 * g_file_read_async().
1876 * Returns: (transfer full): a #GFileInputStream or %NULL on error.
1877 * Free the returned object with g_object_unref().
1880 g_file_read_finish (GFile *file,
1886 g_return_val_if_fail (G_IS_FILE (file), NULL);
1887 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1889 if (g_async_result_legacy_propagate_error (res, error))
1892 iface = G_FILE_GET_IFACE (file);
1893 return (* iface->read_finish) (file, res, error);
1897 * g_file_append_to_async:
1898 * @file: input #GFile.
1899 * @flags: a set of #GFileCreateFlags.
1900 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1902 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1903 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1904 * @user_data: (closure): the data to pass to callback function
1906 * Asynchronously opens @file for appending.
1908 * For more details, see g_file_append_to() which is
1909 * the synchronous version of this call.
1911 * When the operation is finished, @callback will be called. You can then call
1912 * g_file_append_to_finish() to get the result of the operation.
1915 g_file_append_to_async (GFile *file,
1916 GFileCreateFlags flags,
1918 GCancellable *cancellable,
1919 GAsyncReadyCallback callback,
1924 g_return_if_fail (G_IS_FILE (file));
1926 iface = G_FILE_GET_IFACE (file);
1927 (* iface->append_to_async) (file,
1936 * g_file_append_to_finish:
1937 * @file: input #GFile.
1938 * @res: #GAsyncResult
1939 * @error: a #GError, or %NULL
1941 * Finishes an asynchronous file append operation started with
1942 * g_file_append_to_async().
1944 * Returns: (transfer full): a valid #GFileOutputStream or %NULL on error.
1945 * Free the returned object with g_object_unref().
1948 g_file_append_to_finish (GFile *file,
1954 g_return_val_if_fail (G_IS_FILE (file), NULL);
1955 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1957 if (g_async_result_legacy_propagate_error (res, error))
1960 iface = G_FILE_GET_IFACE (file);
1961 return (* iface->append_to_finish) (file, res, error);
1965 * g_file_create_async:
1966 * @file: input #GFile.
1967 * @flags: a set of #GFileCreateFlags.
1968 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1970 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1971 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1972 * @user_data: (closure): the data to pass to callback function
1974 * Asynchronously creates a new file and returns an output stream for writing to it.
1975 * The file must not already exist.
1977 * For more details, see g_file_create() which is
1978 * the synchronous version of this call.
1980 * When the operation is finished, @callback will be called. You can then call
1981 * g_file_create_finish() to get the result of the operation.
1984 g_file_create_async (GFile *file,
1985 GFileCreateFlags flags,
1987 GCancellable *cancellable,
1988 GAsyncReadyCallback callback,
1993 g_return_if_fail (G_IS_FILE (file));
1995 iface = G_FILE_GET_IFACE (file);
1996 (* iface->create_async) (file,
2005 * g_file_create_finish:
2006 * @file: input #GFile.
2007 * @res: a #GAsyncResult.
2008 * @error: a #GError, or %NULL
2010 * Finishes an asynchronous file create operation started with
2011 * g_file_create_async().
2013 * Returns: (transfer full): a #GFileOutputStream or %NULL on error.
2014 * Free the returned object with g_object_unref().
2017 g_file_create_finish (GFile *file,
2023 g_return_val_if_fail (G_IS_FILE (file), NULL);
2024 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2026 if (g_async_result_legacy_propagate_error (res, error))
2029 iface = G_FILE_GET_IFACE (file);
2030 return (* iface->create_finish) (file, res, error);
2034 * g_file_replace_async:
2035 * @file: input #GFile.
2036 * @etag: (allow-none): an <link linkend="gfile-etag">entity tag</link> for the
2037 * current #GFile, or NULL to ignore.
2038 * @make_backup: %TRUE if a backup should be created.
2039 * @flags: a set of #GFileCreateFlags.
2040 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2042 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
2043 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
2044 * @user_data: (closure): the data to pass to callback function
2046 * Asynchronously overwrites the file, replacing the contents, possibly
2047 * creating a backup copy of the file first.
2049 * For more details, see g_file_replace() which is
2050 * the synchronous version of this call.
2052 * When the operation is finished, @callback will be called. You can then call
2053 * g_file_replace_finish() to get the result of the operation.
2056 g_file_replace_async (GFile *file,
2058 gboolean make_backup,
2059 GFileCreateFlags flags,
2061 GCancellable *cancellable,
2062 GAsyncReadyCallback callback,
2067 g_return_if_fail (G_IS_FILE (file));
2069 iface = G_FILE_GET_IFACE (file);
2070 (* iface->replace_async) (file,
2081 * g_file_replace_finish:
2082 * @file: input #GFile.
2083 * @res: a #GAsyncResult.
2084 * @error: a #GError, or %NULL
2086 * Finishes an asynchronous file replace operation started with
2087 * g_file_replace_async().
2089 * Returns: (transfer full): a #GFileOutputStream, or %NULL on error.
2090 * Free the returned object with g_object_unref().
2093 g_file_replace_finish (GFile *file,
2099 g_return_val_if_fail (G_IS_FILE (file), NULL);
2100 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2102 if (g_async_result_legacy_propagate_error (res, error))
2105 iface = G_FILE_GET_IFACE (file);
2106 return (* iface->replace_finish) (file, res, error);
2111 * g_file_open_readwrite_async:
2112 * @file: input #GFile.
2113 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2115 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
2116 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
2117 * @user_data: (closure): the data to pass to callback function
2119 * Asynchronously opens @file for reading and writing.
2121 * For more details, see g_file_open_readwrite() which is
2122 * the synchronous version of this call.
2124 * When the operation is finished, @callback will be called. You can then call
2125 * g_file_open_readwrite_finish() to get the result of the operation.
2130 g_file_open_readwrite_async (GFile *file,
2132 GCancellable *cancellable,
2133 GAsyncReadyCallback callback,
2138 g_return_if_fail (G_IS_FILE (file));
2140 iface = G_FILE_GET_IFACE (file);
2141 (* iface->open_readwrite_async) (file,
2149 * g_file_open_readwrite_finish:
2150 * @file: input #GFile.
2151 * @res: a #GAsyncResult.
2152 * @error: a #GError, or %NULL
2154 * Finishes an asynchronous file read operation started with
2155 * g_file_open_readwrite_async().
2157 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
2158 * Free the returned object with g_object_unref().
2163 g_file_open_readwrite_finish (GFile *file,
2169 g_return_val_if_fail (G_IS_FILE (file), NULL);
2170 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2172 if (g_async_result_legacy_propagate_error (res, error))
2175 iface = G_FILE_GET_IFACE (file);
2176 return (* iface->open_readwrite_finish) (file, res, error);
2181 * g_file_create_readwrite_async:
2182 * @file: input #GFile
2183 * @flags: a set of #GFileCreateFlags
2184 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2186 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
2187 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
2188 * @user_data: (closure): the data to pass to callback function
2190 * Asynchronously creates a new file and returns a stream for reading and
2191 * writing to it. The file must not already exist.
2193 * For more details, see g_file_create_readwrite() which is
2194 * the synchronous version of this call.
2196 * When the operation is finished, @callback will be called. You can then
2197 * call g_file_create_readwrite_finish() to get the result of the operation.
2202 g_file_create_readwrite_async (GFile *file,
2203 GFileCreateFlags flags,
2205 GCancellable *cancellable,
2206 GAsyncReadyCallback callback,
2211 g_return_if_fail (G_IS_FILE (file));
2213 iface = G_FILE_GET_IFACE (file);
2214 (* iface->create_readwrite_async) (file,
2223 * g_file_create_readwrite_finish:
2224 * @file: input #GFile
2225 * @res: a #GAsyncResult
2226 * @error: a #GError, or %NULL
2228 * Finishes an asynchronous file create operation started with
2229 * g_file_create_readwrite_async().
2231 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
2232 * Free the returned object with g_object_unref().
2237 g_file_create_readwrite_finish (GFile *file,
2243 g_return_val_if_fail (G_IS_FILE (file), NULL);
2244 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2246 if (g_async_result_legacy_propagate_error (res, error))
2249 iface = G_FILE_GET_IFACE (file);
2250 return (* iface->create_readwrite_finish) (file, res, error);
2254 * g_file_replace_readwrite_async:
2255 * @file: input #GFile.
2256 * @etag: (allow-none): an <link linkend="gfile-etag">entity tag</link> for the
2257 * current #GFile, or NULL to ignore.
2258 * @make_backup: %TRUE if a backup should be created.
2259 * @flags: a set of #GFileCreateFlags.
2260 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2262 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
2263 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
2264 * @user_data: (closure): the data to pass to callback function
2266 * Asynchronously overwrites the file in read-write mode, replacing the
2267 * contents, possibly creating a backup copy of the file first.
2269 * For more details, see g_file_replace_readwrite() which is
2270 * the synchronous version of this call.
2272 * When the operation is finished, @callback will be called. You can then
2273 * call g_file_replace_readwrite_finish() to get the result of the operation.
2278 g_file_replace_readwrite_async (GFile *file,
2280 gboolean make_backup,
2281 GFileCreateFlags flags,
2283 GCancellable *cancellable,
2284 GAsyncReadyCallback callback,
2289 g_return_if_fail (G_IS_FILE (file));
2291 iface = G_FILE_GET_IFACE (file);
2292 (* iface->replace_readwrite_async) (file,
2303 * g_file_replace_readwrite_finish:
2304 * @file: input #GFile.
2305 * @res: a #GAsyncResult.
2306 * @error: a #GError, or %NULL
2308 * Finishes an asynchronous file replace operation started with
2309 * g_file_replace_readwrite_async().
2311 * Returns: (transfer full): a #GFileIOStream, or %NULL on error.
2312 * Free the returned object with g_object_unref().
2317 g_file_replace_readwrite_finish (GFile *file,
2323 g_return_val_if_fail (G_IS_FILE (file), NULL);
2324 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2326 if (g_async_result_legacy_propagate_error (res, error))
2329 iface = G_FILE_GET_IFACE (file);
2330 return (* iface->replace_readwrite_finish) (file, res, error);
2334 copy_symlink (GFile *destination,
2335 GFileCopyFlags flags,
2336 GCancellable *cancellable,
2341 gboolean tried_delete;
2343 GFileType file_type;
2345 tried_delete = FALSE;
2349 if (!g_file_make_symbolic_link (destination, target, cancellable, &my_error))
2351 /* Maybe it already existed, and we want to overwrite? */
2352 if (!tried_delete && (flags & G_FILE_COPY_OVERWRITE) &&
2353 my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_EXISTS)
2355 g_error_free (my_error);
2358 /* Don't overwrite if the destination is a directory */
2359 info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
2360 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2361 cancellable, &my_error);
2364 file_type = g_file_info_get_file_type (info);
2365 g_object_unref (info);
2367 if (file_type == G_FILE_TYPE_DIRECTORY)
2369 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY,
2370 _("Can't copy over directory"));
2375 if (!g_file_delete (destination, cancellable, error))
2378 tried_delete = TRUE;
2382 g_propagate_error (error, my_error);
2389 static GInputStream *
2390 open_source_for_copy (GFile *source,
2392 GFileCopyFlags flags,
2393 GCancellable *cancellable,
2399 GFileType file_type;
2402 in = (GInputStream *)g_file_read (source, cancellable, &my_error);
2406 /* There was an error opening the source, try to set a good error for it: */
2408 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_IS_DIRECTORY)
2410 /* The source is a directory, don't fail with WOULD_RECURSE immediately,
2411 * as that is less useful to the app. Better check for errors on the
2414 g_error_free (my_error);
2417 info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
2418 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2419 cancellable, &my_error);
2421 g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_TYPE))
2423 file_type = g_file_info_get_file_type (info);
2424 g_object_unref (info);
2426 if (flags & G_FILE_COPY_OVERWRITE)
2428 if (file_type == G_FILE_TYPE_DIRECTORY)
2430 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_MERGE,
2431 _("Can't copy directory over directory"));
2434 /* continue to would_recurse error */
2438 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
2439 _("Target file exists"));
2445 /* Error getting info from target, return that error
2446 * (except for NOT_FOUND, which is no error here)
2448 if (my_error != NULL && !g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
2450 g_propagate_error (error, my_error);
2453 g_clear_error (&my_error);
2456 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_RECURSE,
2457 _("Can't recursively copy directory"));
2461 g_propagate_error (error, my_error);
2466 should_copy (GFileAttributeInfo *info,
2468 gboolean skip_perms)
2470 if (skip_perms && strcmp(info->name, "unix::mode") == 0)
2474 return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED;
2475 return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE;
2479 build_attribute_list_for_copy (GFileAttributeInfoList *attributes,
2480 GFileAttributeInfoList *namespaces,
2482 gboolean skip_perms)
2489 s = g_string_new ("");
2493 for (i = 0; i < attributes->n_infos; i++)
2495 if (should_copy (&attributes->infos[i], as_move, skip_perms))
2500 g_string_append_c (s, ',');
2502 g_string_append (s, attributes->infos[i].name);
2509 for (i = 0; i < namespaces->n_infos; i++)
2511 if (should_copy (&namespaces->infos[i], as_move, FALSE))
2516 g_string_append_c (s, ',');
2518 g_string_append (s, namespaces->infos[i].name);
2519 g_string_append (s, "::*");
2524 return g_string_free (s, FALSE);
2528 * g_file_copy_attributes:
2529 * @source: a #GFile with attributes.
2530 * @destination: a #GFile to copy attributes to.
2531 * @flags: a set of #GFileCopyFlags.
2532 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
2533 * @error: a #GError, %NULL to ignore.
2535 * Copies the file attributes from @source to @destination.
2537 * Normally only a subset of the file attributes are copied,
2538 * those that are copies in a normal file copy operation
2539 * (which for instance does not include e.g. owner). However
2540 * if #G_FILE_COPY_ALL_METADATA is specified in @flags, then
2541 * all the metadata that is possible to copy is copied. This
2542 * is useful when implementing move by copy + delete source.
2544 * Returns: %TRUE if the attributes were copied successfully, %FALSE otherwise.
2547 g_file_copy_attributes (GFile *source,
2549 GFileCopyFlags flags,
2550 GCancellable *cancellable,
2553 GFileAttributeInfoList *attributes, *namespaces;
2554 char *attrs_to_read;
2558 gboolean source_nofollow_symlinks;
2559 gboolean skip_perms;
2561 as_move = flags & G_FILE_COPY_ALL_METADATA;
2562 source_nofollow_symlinks = flags & G_FILE_COPY_NOFOLLOW_SYMLINKS;
2563 skip_perms = (flags & G_FILE_COPY_TARGET_DEFAULT_PERMS) != 0;
2565 /* Ignore errors here, if the target supports no attributes there is nothing to copy */
2566 attributes = g_file_query_settable_attributes (destination, cancellable, NULL);
2567 namespaces = g_file_query_writable_namespaces (destination, cancellable, NULL);
2569 if (attributes == NULL && namespaces == NULL)
2572 attrs_to_read = build_attribute_list_for_copy (attributes, namespaces, as_move, skip_perms);
2574 /* Ignore errors here, if we can't read some info (e.g. if it doesn't exist)
2575 * we just don't copy it.
2577 info = g_file_query_info (source, attrs_to_read,
2578 source_nofollow_symlinks ? G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS:0,
2582 g_free (attrs_to_read);
2587 res = g_file_set_attributes_from_info (destination,
2589 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2592 g_object_unref (info);
2595 g_file_attribute_info_list_unref (attributes);
2596 g_file_attribute_info_list_unref (namespaces);
2602 copy_stream_with_progress (GInputStream *in,
2605 GCancellable *cancellable,
2606 GFileProgressCallback progress_callback,
2607 gpointer progress_callback_data,
2610 gssize n_read, n_written;
2611 goffset current_size;
2612 char buffer[1024*64], *p;
2618 /* avoid performance impact of querying total size when it's not needed */
2619 if (progress_callback)
2621 info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (in),
2622 G_FILE_ATTRIBUTE_STANDARD_SIZE,
2626 if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
2627 total_size = g_file_info_get_size (info);
2628 g_object_unref (info);
2631 if (total_size == -1)
2633 info = g_file_query_info (source,
2634 G_FILE_ATTRIBUTE_STANDARD_SIZE,
2635 G_FILE_QUERY_INFO_NONE,
2639 if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
2640 total_size = g_file_info_get_size (info);
2641 g_object_unref (info);
2646 if (total_size == -1)
2653 n_read = g_input_stream_read (in, buffer, sizeof (buffer), cancellable, error);
2663 current_size += n_read;
2668 n_written = g_output_stream_write (out, p, n_read, cancellable, error);
2669 if (n_written == -1)
2676 n_read -= n_written;
2682 if (progress_callback)
2683 progress_callback (current_size, total_size, progress_callback_data);
2686 /* Make sure we send full copied size */
2687 if (progress_callback)
2688 progress_callback (current_size, total_size, progress_callback_data);
2696 do_splice (int fd_in,
2701 long *bytes_transferd,
2707 result = splice (fd_in, off_in, fd_out, off_out, len, SPLICE_F_MORE);
2715 else if (errsv == ENOSYS || errsv == EINVAL)
2716 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2717 _("Splice not supported"));
2719 g_set_error (error, G_IO_ERROR,
2720 g_io_error_from_errno (errsv),
2721 _("Error splicing file: %s"),
2722 g_strerror (errsv));
2727 *bytes_transferd = result;
2732 splice_stream_with_progress (GInputStream *in,
2734 GCancellable *cancellable,
2735 GFileProgressCallback progress_callback,
2736 gpointer progress_callback_data,
2746 fd_in = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (in));
2747 fd_out = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (out));
2749 if (pipe (buffer) != 0)
2751 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2752 "Pipe creation failed");
2757 /* avoid performance impact of querying total size when it's not needed */
2758 if (progress_callback)
2762 if (fstat (fd_in, &sbuf) == 0)
2763 total_size = sbuf.st_size;
2766 if (total_size == -1)
2769 offset_in = offset_out = 0;
2776 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2779 if (!do_splice (fd_in, &offset_in, buffer[1], NULL, 1024*64, &n_read, error))
2790 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2793 if (!do_splice (buffer[0], NULL, fd_out, &offset_out, n_read, &n_written, error))
2796 n_read -= n_written;
2799 if (progress_callback)
2800 progress_callback (offset_in, total_size, progress_callback_data);
2803 /* Make sure we send full copied size */
2804 if (progress_callback)
2805 progress_callback (offset_in, total_size, progress_callback_data);
2816 file_copy_fallback (GFile *source,
2818 GFileCopyFlags flags,
2819 GCancellable *cancellable,
2820 GFileProgressCallback progress_callback,
2821 gpointer progress_callback_data,
2830 gboolean fallback = TRUE;
2833 /* need to know the file type */
2834 info = g_file_query_info (source,
2835 G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
2836 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2843 /* Maybe copy the symlink? */
2844 if ((flags & G_FILE_COPY_NOFOLLOW_SYMLINKS) &&
2845 g_file_info_get_file_type (info) == G_FILE_TYPE_SYMBOLIC_LINK)
2847 target = g_file_info_get_symlink_target (info);
2850 if (!copy_symlink (destination, flags, cancellable, target, error))
2852 g_object_unref (info);
2856 g_object_unref (info);
2859 /* ... else fall back on a regular file copy */
2860 g_object_unref (info);
2862 /* Handle "special" files (pipes, device nodes, ...)? */
2863 else if (g_file_info_get_file_type (info) == G_FILE_TYPE_SPECIAL)
2865 /* FIXME: could try to recreate device nodes and others? */
2867 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2868 _("Can't copy special file"));
2869 g_object_unref (info);
2872 /* Everything else should just fall back on a regular copy. */
2874 g_object_unref (info);
2876 in = open_source_for_copy (source, destination, flags, cancellable, error);
2880 if (flags & G_FILE_COPY_OVERWRITE)
2882 out = (GOutputStream *)g_file_replace (destination,
2884 flags & G_FILE_COPY_BACKUP,
2885 G_FILE_CREATE_REPLACE_DESTINATION,
2886 cancellable, error);
2890 out = (GOutputStream *)g_file_create (destination, 0, cancellable, error);
2895 g_object_unref (in);
2900 if (G_IS_FILE_DESCRIPTOR_BASED (in) && G_IS_FILE_DESCRIPTOR_BASED (out))
2902 GError *splice_err = NULL;
2904 result = splice_stream_with_progress (in, out, cancellable,
2905 progress_callback, progress_callback_data,
2908 if (result || !g_error_matches (splice_err, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
2912 g_propagate_error (error, splice_err);
2915 g_clear_error (&splice_err);
2920 result = copy_stream_with_progress (in, out, source, cancellable,
2921 progress_callback, progress_callback_data,
2924 /* Don't care about errors in source here */
2925 g_input_stream_close (in, cancellable, NULL);
2927 /* But write errors on close are bad! */
2928 if (!g_output_stream_close (out, cancellable, result ? error : NULL))
2931 g_object_unref (in);
2932 g_object_unref (out);
2934 if (result == FALSE)
2938 /* Ignore errors here. Failure to copy metadata is not a hard error */
2939 g_file_copy_attributes (source, destination,
2940 flags, cancellable, NULL);
2947 * @source: input #GFile.
2948 * @destination: destination #GFile
2949 * @flags: set of #GFileCopyFlags
2950 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
2951 * @progress_callback: (allow-none) (scope call): function to callback with
2952 * progress information, or %NULL if progress information is not needed
2953 * @progress_callback_data: (closure): user data to pass to @progress_callback
2954 * @error: #GError to set on error, or %NULL
2956 * Copies the file @source to the location specified by @destination.
2957 * Can not handle recursive copies of directories.
2959 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
2960 * existing @destination file is overwritten.
2962 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
2963 * will be copied as symlinks, otherwise the target of the
2964 * @source symlink will be copied.
2966 * If @cancellable is not %NULL, then the operation can be cancelled by
2967 * triggering the cancellable object from another thread. If the operation
2968 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
2970 * If @progress_callback is not %NULL, then the operation can be monitored by
2971 * setting this to a #GFileProgressCallback function. @progress_callback_data
2972 * will be passed to this function. It is guaranteed that this callback will
2973 * be called after all data has been transferred with the total number of bytes
2974 * copied during the operation.
2976 * If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
2977 * error is returned, independent on the status of the @destination.
2979 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then the
2980 * error G_IO_ERROR_EXISTS is returned.
2982 * If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY
2983 * error is returned. If trying to overwrite a directory with a directory the
2984 * G_IO_ERROR_WOULD_MERGE error is returned.
2986 * If the source is a directory and the target does not exist, or
2987 * #G_FILE_COPY_OVERWRITE is specified and the target is a file, then the
2988 * G_IO_ERROR_WOULD_RECURSE error is returned.
2990 * If you are interested in copying the #GFile object itself (not the on-disk
2991 * file), see g_file_dup().
2993 * Returns: %TRUE on success, %FALSE otherwise.
2996 g_file_copy (GFile *source,
2998 GFileCopyFlags flags,
2999 GCancellable *cancellable,
3000 GFileProgressCallback progress_callback,
3001 gpointer progress_callback_data,
3008 g_return_val_if_fail (G_IS_FILE (source), FALSE);
3009 g_return_val_if_fail (G_IS_FILE (destination), FALSE);
3011 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3014 iface = G_FILE_GET_IFACE (destination);
3018 res = (* iface->copy) (source, destination,
3020 progress_callback, progress_callback_data,
3026 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3028 g_propagate_error (error, my_error);
3032 g_clear_error (&my_error);
3035 /* If the types are different, and the destination method failed
3036 also try the source method */
3037 if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
3039 iface = G_FILE_GET_IFACE (source);
3044 res = (* iface->copy) (source, destination,
3046 progress_callback, progress_callback_data,
3052 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3054 g_propagate_error (error, my_error);
3058 g_clear_error (&my_error);
3062 return file_copy_fallback (source, destination, flags, cancellable,
3063 progress_callback, progress_callback_data,
3068 * g_file_copy_async: (skip)
3069 * @source: input #GFile.
3070 * @destination: destination #GFile
3071 * @flags: set of #GFileCopyFlags
3072 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3074 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
3075 * @progress_callback: (allow-none): function to callback with progress
3076 * information, or %NULL if progress information is not needed
3077 * @progress_callback_data: (closure): user data to pass to @progress_callback
3078 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
3079 * @user_data: the data to pass to callback function
3081 * Copies the file @source to the location specified by @destination
3082 * asynchronously. For details of the behaviour, see g_file_copy().
3084 * If @progress_callback is not %NULL, then that function that will be called
3085 * just like in g_file_copy(), however the callback will run in the main loop,
3086 * not in the thread that is doing the I/O operation.
3088 * When the operation is finished, @callback will be called. You can then call
3089 * g_file_copy_finish() to get the result of the operation.
3092 g_file_copy_async (GFile *source,
3094 GFileCopyFlags flags,
3096 GCancellable *cancellable,
3097 GFileProgressCallback progress_callback,
3098 gpointer progress_callback_data,
3099 GAsyncReadyCallback callback,
3104 g_return_if_fail (G_IS_FILE (source));
3105 g_return_if_fail (G_IS_FILE (destination));
3107 iface = G_FILE_GET_IFACE (source);
3108 (* iface->copy_async) (source,
3114 progress_callback_data,
3120 * g_file_copy_finish:
3121 * @file: input #GFile.
3122 * @res: a #GAsyncResult.
3123 * @error: a #GError, or %NULL
3125 * Finishes copying the file started with
3126 * g_file_copy_async().
3128 * Returns: a %TRUE on success, %FALSE on error.
3131 g_file_copy_finish (GFile *file,
3137 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3138 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
3140 if (g_async_result_legacy_propagate_error (res, error))
3143 iface = G_FILE_GET_IFACE (file);
3144 return (* iface->copy_finish) (file, res, error);
3149 * @source: #GFile pointing to the source location.
3150 * @destination: #GFile pointing to the destination location.
3151 * @flags: set of #GFileCopyFlags.
3152 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3153 * @progress_callback: (allow-none) (scope call): #GFileProgressCallback function for updates.
3154 * @progress_callback_data: (closure): gpointer to user data for the callback function.
3155 * @error: #GError for returning error conditions, or %NULL
3158 * Tries to move the file or directory @source to the location specified by @destination.
3159 * If native move operations are supported then this is used, otherwise a copy + delete
3160 * fallback is used. The native implementation may support moving directories (for instance
3161 * on moves inside the same filesystem), but the fallback code does not.
3163 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
3164 * existing @destination file is overwritten.
3166 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
3167 * will be copied as symlinks, otherwise the target of the
3168 * @source symlink will be copied.
3170 * If @cancellable is not %NULL, then the operation can be cancelled by
3171 * triggering the cancellable object from another thread. If the operation
3172 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3174 * If @progress_callback is not %NULL, then the operation can be monitored by
3175 * setting this to a #GFileProgressCallback function. @progress_callback_data
3176 * will be passed to this function. It is guaranteed that this callback will
3177 * be called after all data has been transferred with the total number of bytes
3178 * copied during the operation.
3180 * If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
3181 * error is returned, independent on the status of the @destination.
3183 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then the
3184 * error G_IO_ERROR_EXISTS is returned.
3186 * If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY
3187 * error is returned. If trying to overwrite a directory with a directory the
3188 * G_IO_ERROR_WOULD_MERGE error is returned.
3190 * If the source is a directory and the target does not exist, or #G_FILE_COPY_OVERWRITE is
3191 * specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error
3192 * may be returned (if the native move operation isn't available).
3194 * Returns: %TRUE on successful move, %FALSE otherwise.
3197 g_file_move (GFile *source,
3199 GFileCopyFlags flags,
3200 GCancellable *cancellable,
3201 GFileProgressCallback progress_callback,
3202 gpointer progress_callback_data,
3209 g_return_val_if_fail (G_IS_FILE (source), FALSE);
3210 g_return_val_if_fail (G_IS_FILE (destination), FALSE);
3212 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3215 iface = G_FILE_GET_IFACE (destination);
3219 res = (* iface->move) (source, destination,
3221 progress_callback, progress_callback_data,
3227 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3229 g_propagate_error (error, my_error);
3234 /* If the types are different, and the destination method failed
3235 also try the source method */
3236 if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
3238 iface = G_FILE_GET_IFACE (source);
3243 res = (* iface->move) (source, destination,
3245 progress_callback, progress_callback_data,
3251 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3253 g_propagate_error (error, my_error);
3259 if (flags & G_FILE_COPY_NO_FALLBACK_FOR_MOVE)
3261 g_set_error_literal (error, G_IO_ERROR,
3262 G_IO_ERROR_NOT_SUPPORTED,
3263 _("Operation not supported"));
3267 flags |= G_FILE_COPY_ALL_METADATA;
3268 if (!g_file_copy (source, destination, flags, cancellable,
3269 progress_callback, progress_callback_data,
3273 return g_file_delete (source, cancellable, error);
3277 * g_file_make_directory:
3278 * @file: input #GFile.
3279 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3280 * @error: a #GError, or %NULL
3282 * Creates a directory. Note that this will only create a child directory of
3283 * the immediate parent directory of the path or URI given by the #GFile. To
3284 * recursively create directories, see g_file_make_directory_with_parents().
3285 * This function will fail if the parent directory does not exist, setting
3286 * @error to %G_IO_ERROR_NOT_FOUND. If the file system doesn't support creating
3287 * directories, this function will fail, setting @error to
3288 * %G_IO_ERROR_NOT_SUPPORTED.
3290 * For a local #GFile the newly created directory will have the default
3291 * (current) ownership and permissions of the current process.
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 on successful creation, %FALSE otherwise.
3300 g_file_make_directory (GFile *file,
3301 GCancellable *cancellable,
3306 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3308 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3311 iface = G_FILE_GET_IFACE (file);
3313 if (iface->make_directory == NULL)
3315 g_set_error_literal (error, G_IO_ERROR,
3316 G_IO_ERROR_NOT_SUPPORTED,
3317 _("Operation not supported"));
3321 return (* iface->make_directory) (file, cancellable, error);
3325 * g_file_make_directory_with_parents:
3326 * @file: input #GFile.
3327 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3328 * @error: a #GError, or %NULL
3330 * Creates a directory and any parent directories that may not exist similar to
3331 * 'mkdir -p'. If the file system does not support creating directories, this
3332 * function will fail, setting @error to %G_IO_ERROR_NOT_SUPPORTED. If the
3333 * directory itself already exists, this function will fail setting @error
3334 * to %G_IO_ERROR_EXISTS, unlike the similar g_mkdir_with_parents().
3336 * For a local #GFile the newly created directories will have the default
3337 * (current) ownership and permissions of the current process.
3339 * If @cancellable is not %NULL, then the operation can be cancelled by
3340 * triggering the cancellable object from another thread. If the operation
3341 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3343 * Returns: %TRUE if all directories have been successfully created, %FALSE
3349 g_file_make_directory_with_parents (GFile *file,
3350 GCancellable *cancellable,
3354 GFile *work_file = NULL;
3355 GList *list = NULL, *l;
3356 GError *my_error = NULL;
3358 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3360 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3363 result = g_file_make_directory (file, cancellable, &my_error);
3364 if (result || my_error->code != G_IO_ERROR_NOT_FOUND)
3367 g_propagate_error (error, my_error);
3371 work_file = g_object_ref (file);
3373 while (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
3377 g_clear_error (&my_error);
3379 parent_file = g_file_get_parent (work_file);
3380 if (parent_file == NULL)
3382 result = g_file_make_directory (parent_file, cancellable, &my_error);
3384 g_object_unref (work_file);
3385 work_file = g_object_ref (parent_file);
3387 if (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
3388 list = g_list_prepend (list, parent_file); /* Transfer ownership of ref */
3390 g_object_unref (parent_file);
3393 g_clear_error (&my_error);
3394 for (l = list; result && l; l = l->next)
3396 result = g_file_make_directory ((GFile *) l->data, cancellable, &my_error);
3400 g_object_unref (work_file);
3403 while (list != NULL)
3405 g_object_unref ((GFile *) list->data);
3406 list = g_list_remove (list, list->data);
3411 g_propagate_error (error, my_error);
3415 return g_file_make_directory (file, cancellable, error);
3419 * g_file_make_symbolic_link:
3420 * @file: a #GFile with the name of the symlink to create
3421 * @symlink_value: a string with the path for the target of the new symlink
3422 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3423 * @error: a #GError.
3425 * Creates a symbolic link named @file which contains the string
3428 * If @cancellable is not %NULL, then the operation can be cancelled by
3429 * triggering the cancellable object from another thread. If the operation
3430 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3432 * Returns: %TRUE on the creation of a new symlink, %FALSE otherwise.
3435 g_file_make_symbolic_link (GFile *file,
3436 const char *symlink_value,
3437 GCancellable *cancellable,
3442 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3443 g_return_val_if_fail (symlink_value != NULL, FALSE);
3445 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3448 if (*symlink_value == '\0')
3450 g_set_error_literal (error, G_IO_ERROR,
3451 G_IO_ERROR_INVALID_ARGUMENT,
3452 _("Invalid symlink value given"));
3456 iface = G_FILE_GET_IFACE (file);
3458 if (iface->make_symbolic_link == NULL)
3460 g_set_error_literal (error, G_IO_ERROR,
3461 G_IO_ERROR_NOT_SUPPORTED,
3462 _("Operation not supported"));
3466 return (* iface->make_symbolic_link) (file, symlink_value, cancellable, error);
3471 * @file: input #GFile.
3472 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3473 * @error: a #GError, or %NULL
3475 * Deletes a file. If the @file is a directory, it will only be deleted if it
3478 * If @cancellable is not %NULL, then the operation can be cancelled by
3479 * triggering the cancellable object from another thread. If the operation
3480 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3482 * Virtual: delete_file
3483 * Returns: %TRUE if the file was deleted. %FALSE otherwise.
3486 g_file_delete (GFile *file,
3487 GCancellable *cancellable,
3492 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3494 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3497 iface = G_FILE_GET_IFACE (file);
3499 if (iface->delete_file == NULL)
3501 g_set_error_literal (error, G_IO_ERROR,
3502 G_IO_ERROR_NOT_SUPPORTED,
3503 _("Operation not supported"));
3507 return (* iface->delete_file) (file, cancellable, error);
3512 * @file: #GFile to send to trash.
3513 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3514 * @error: a #GError, or %NULL
3516 * Sends @file to the "Trashcan", if possible. This is similar to
3517 * deleting it, but the user can recover it before emptying the trashcan.
3518 * Not all file systems support trashing, so this call can return the
3519 * %G_IO_ERROR_NOT_SUPPORTED error.
3522 * If @cancellable is not %NULL, then the operation can be cancelled by
3523 * triggering the cancellable object from another thread. If the operation
3524 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3526 * Returns: %TRUE on successful trash, %FALSE otherwise.
3529 g_file_trash (GFile *file,
3530 GCancellable *cancellable,
3535 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3537 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3540 iface = G_FILE_GET_IFACE (file);
3542 if (iface->trash == NULL)
3544 g_set_error_literal (error,
3545 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
3546 _("Trash not supported"));
3550 return (* iface->trash) (file, cancellable, error);
3554 * g_file_set_display_name:
3555 * @file: input #GFile.
3556 * @display_name: a string.
3557 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3558 * @error: a #GError, or %NULL
3560 * Renames @file to the specified display name.
3562 * The display name is converted from UTF8 to the correct encoding for the target
3563 * filesystem if possible and the @file is renamed to this.
3565 * If you want to implement a rename operation in the user interface the edit name
3566 * (#G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the initial value in the rename
3567 * widget, and then the result after editing should be passed to g_file_set_display_name().
3569 * On success the resulting converted filename is returned.
3571 * If @cancellable is not %NULL, then the operation can be cancelled by
3572 * triggering the cancellable object from another thread. If the operation
3573 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3575 * Returns: (transfer full): a #GFile specifying what @file was renamed to, or %NULL
3576 * if there was an error.
3577 * Free the returned object with g_object_unref().
3580 g_file_set_display_name (GFile *file,
3581 const char *display_name,
3582 GCancellable *cancellable,
3587 g_return_val_if_fail (G_IS_FILE (file), NULL);
3588 g_return_val_if_fail (display_name != NULL, NULL);
3590 if (strchr (display_name, G_DIR_SEPARATOR) != NULL)
3594 G_IO_ERROR_INVALID_ARGUMENT,
3595 _("File names cannot contain '%c'"), G_DIR_SEPARATOR);
3599 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3602 iface = G_FILE_GET_IFACE (file);
3604 return (* iface->set_display_name) (file, display_name, cancellable, error);
3608 * g_file_set_display_name_async:
3609 * @file: input #GFile.
3610 * @display_name: a string.
3611 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3613 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3614 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
3615 * @user_data: (closure): the data to pass to callback function
3617 * Asynchronously sets the display name for a given #GFile.
3619 * For more details, see g_file_set_display_name() which is
3620 * the synchronous version of this call.
3622 * When the operation is finished, @callback will be called. You can then call
3623 * g_file_set_display_name_finish() to get the result of the operation.
3626 g_file_set_display_name_async (GFile *file,
3627 const char *display_name,
3629 GCancellable *cancellable,
3630 GAsyncReadyCallback callback,
3635 g_return_if_fail (G_IS_FILE (file));
3636 g_return_if_fail (display_name != NULL);
3638 iface = G_FILE_GET_IFACE (file);
3639 (* iface->set_display_name_async) (file,
3648 * g_file_set_display_name_finish:
3649 * @file: input #GFile.
3650 * @res: a #GAsyncResult.
3651 * @error: a #GError, or %NULL
3653 * Finishes setting a display name started with
3654 * g_file_set_display_name_async().
3656 * Returns: (transfer full): a #GFile or %NULL on error.
3657 * Free the returned object with g_object_unref().
3660 g_file_set_display_name_finish (GFile *file,
3666 g_return_val_if_fail (G_IS_FILE (file), NULL);
3667 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
3669 if (g_async_result_legacy_propagate_error (res, error))
3672 iface = G_FILE_GET_IFACE (file);
3673 return (* iface->set_display_name_finish) (file, res, error);
3677 * g_file_query_settable_attributes:
3678 * @file: input #GFile.
3679 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3680 * @error: a #GError, or %NULL
3682 * Obtain the list of settable attributes for the file.
3684 * Returns the type and full attribute name of all the attributes
3685 * that can be set on this file. This doesn't mean setting it will always
3686 * succeed though, you might get an access failure, or some specific
3687 * file may not support a specific attribute.
3689 * If @cancellable is not %NULL, then the operation can be cancelled by
3690 * triggering the cancellable object from another thread. If the operation
3691 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3693 * Returns: a #GFileAttributeInfoList describing the settable attributes.
3694 * When you are done with it, release it with g_file_attribute_info_list_unref()
3696 GFileAttributeInfoList *
3697 g_file_query_settable_attributes (GFile *file,
3698 GCancellable *cancellable,
3703 GFileAttributeInfoList *list;
3705 g_return_val_if_fail (G_IS_FILE (file), NULL);
3707 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3710 iface = G_FILE_GET_IFACE (file);
3712 if (iface->query_settable_attributes == NULL)
3713 return g_file_attribute_info_list_new ();
3716 list = (* iface->query_settable_attributes) (file, cancellable, &my_error);
3720 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
3722 list = g_file_attribute_info_list_new ();
3723 g_error_free (my_error);
3726 g_propagate_error (error, my_error);
3733 * g_file_query_writable_namespaces:
3734 * @file: input #GFile.
3735 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3736 * @error: a #GError, or %NULL
3738 * Obtain the list of attribute namespaces where new attributes
3739 * can be created by a user. An example of this is extended
3740 * attributes (in the "xattr" namespace).
3742 * If @cancellable is not %NULL, then the operation can be cancelled by
3743 * triggering the cancellable object from another thread. If the operation
3744 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3746 * Returns: a #GFileAttributeInfoList describing the writable namespaces.
3747 * When you are done with it, release it with g_file_attribute_info_list_unref()
3749 GFileAttributeInfoList *
3750 g_file_query_writable_namespaces (GFile *file,
3751 GCancellable *cancellable,
3756 GFileAttributeInfoList *list;
3758 g_return_val_if_fail (G_IS_FILE (file), NULL);
3760 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3763 iface = G_FILE_GET_IFACE (file);
3765 if (iface->query_writable_namespaces == NULL)
3766 return g_file_attribute_info_list_new ();
3769 list = (* iface->query_writable_namespaces) (file, cancellable, &my_error);
3773 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
3775 list = g_file_attribute_info_list_new ();
3776 g_error_free (my_error);
3779 g_propagate_error (error, my_error);
3786 * g_file_set_attribute:
3787 * @file: input #GFile.
3788 * @attribute: a string containing the attribute's name.
3789 * @type: The type of the attribute
3790 * @value_p: (allow-none): a pointer to the value (or the pointer itself if the type is a pointer type)
3791 * @flags: a set of #GFileQueryInfoFlags.
3792 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3793 * @error: a #GError, or %NULL
3795 * Sets an attribute in the file with attribute name @attribute to @value.
3797 * Some attributes can be unset by setting @attribute to
3798 * %G_FILE_ATTRIBUTE_TYPE_INVALID and @value_p to %NULL.
3800 * If @cancellable is not %NULL, then the operation can be cancelled by
3801 * triggering the cancellable object from another thread. If the operation
3802 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3804 * Returns: %TRUE if the attribute was set, %FALSE otherwise.
3807 g_file_set_attribute (GFile *file,
3808 const char *attribute,
3809 GFileAttributeType type,
3811 GFileQueryInfoFlags flags,
3812 GCancellable *cancellable,
3817 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3818 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
3820 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3823 iface = G_FILE_GET_IFACE (file);
3825 if (iface->set_attribute == NULL)
3827 g_set_error_literal (error, G_IO_ERROR,
3828 G_IO_ERROR_NOT_SUPPORTED,
3829 _("Operation not supported"));
3833 return (* iface->set_attribute) (file, attribute, type, value_p, flags, cancellable, error);
3837 * g_file_set_attributes_from_info:
3838 * @file: input #GFile.
3839 * @info: a #GFileInfo.
3840 * @flags: #GFileQueryInfoFlags
3841 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3842 * @error: a #GError, or %NULL
3844 * Tries to set all attributes in the #GFileInfo on the target values,
3845 * not stopping on the first error.
3847 * If there is any error during this operation then @error will be set to
3848 * the first error. Error on particular fields are flagged by setting
3849 * the "status" field in the attribute value to
3850 * %G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can also detect
3853 * If @cancellable is not %NULL, then the operation can be cancelled by
3854 * triggering the cancellable object from another thread. If the operation
3855 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3857 * Returns: %TRUE if there was any error, %FALSE otherwise.
3860 g_file_set_attributes_from_info (GFile *file,
3862 GFileQueryInfoFlags flags,
3863 GCancellable *cancellable,
3868 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3869 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
3871 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3874 g_file_info_clear_status (info);
3876 iface = G_FILE_GET_IFACE (file);
3878 return (* iface->set_attributes_from_info) (file,
3887 g_file_real_set_attributes_from_info (GFile *file,
3889 GFileQueryInfoFlags flags,
3890 GCancellable *cancellable,
3896 GFileAttributeValue *value;
3900 attributes = g_file_info_list_attributes (info, NULL);
3902 for (i = 0; attributes[i] != NULL; i++)
3904 value = _g_file_info_get_attribute_value (info, attributes[i]);
3906 if (value->status != G_FILE_ATTRIBUTE_STATUS_UNSET)
3909 if (!g_file_set_attribute (file, attributes[i],
3910 value->type, _g_file_attribute_value_peek_as_pointer (value),
3911 flags, cancellable, error))
3913 value->status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
3915 /* Don't set error multiple times */
3919 value->status = G_FILE_ATTRIBUTE_STATUS_SET;
3922 g_strfreev (attributes);
3928 * g_file_set_attributes_async:
3929 * @file: input #GFile.
3930 * @info: a #GFileInfo.
3931 * @flags: a #GFileQueryInfoFlags.
3932 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3934 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3935 * @callback: (scope async): a #GAsyncReadyCallback.
3936 * @user_data: (closure): a #gpointer.
3938 * Asynchronously sets the attributes of @file with @info.
3940 * For more details, see g_file_set_attributes_from_info() which is
3941 * the synchronous version of this call.
3943 * When the operation is finished, @callback will be called. You can then call
3944 * g_file_set_attributes_finish() to get the result of the operation.
3947 g_file_set_attributes_async (GFile *file,
3949 GFileQueryInfoFlags flags,
3951 GCancellable *cancellable,
3952 GAsyncReadyCallback callback,
3957 g_return_if_fail (G_IS_FILE (file));
3958 g_return_if_fail (G_IS_FILE_INFO (info));
3960 iface = G_FILE_GET_IFACE (file);
3961 (* iface->set_attributes_async) (file,
3971 * g_file_set_attributes_finish:
3972 * @file: input #GFile.
3973 * @result: a #GAsyncResult.
3974 * @info: (out) (transfer full): a #GFileInfo.
3975 * @error: a #GError, or %NULL
3977 * Finishes setting an attribute started in g_file_set_attributes_async().
3979 * Returns: %TRUE if the attributes were set correctly, %FALSE otherwise.
3982 g_file_set_attributes_finish (GFile *file,
3983 GAsyncResult *result,
3989 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3990 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
3992 /* No standard handling of errors here, as we must set info even
3995 iface = G_FILE_GET_IFACE (file);
3996 return (* iface->set_attributes_finish) (file, result, info, error);
4000 * g_file_set_attribute_string:
4001 * @file: input #GFile.
4002 * @attribute: a string containing the attribute's name.
4003 * @value: a string containing the attribute's value.
4004 * @flags: #GFileQueryInfoFlags.
4005 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4006 * @error: a #GError, or %NULL
4008 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value.
4009 * If @attribute is of a different type, this operation will fail.
4011 * If @cancellable is not %NULL, then the operation can be cancelled by
4012 * triggering the cancellable object from another thread. If the operation
4013 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4015 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
4018 g_file_set_attribute_string (GFile *file,
4019 const char *attribute,
4021 GFileQueryInfoFlags flags,
4022 GCancellable *cancellable,
4025 return g_file_set_attribute (file, attribute,
4026 G_FILE_ATTRIBUTE_TYPE_STRING, (gpointer)value,
4027 flags, cancellable, error);
4031 * g_file_set_attribute_byte_string:
4032 * @file: input #GFile.
4033 * @attribute: a string containing the attribute's name.
4034 * @value: a string containing the attribute's new value.
4035 * @flags: a #GFileQueryInfoFlags.
4036 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4037 * @error: a #GError, or %NULL
4039 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value.
4040 * If @attribute is of a different type, this operation will fail,
4043 * If @cancellable is not %NULL, then the operation can be cancelled by
4044 * triggering the cancellable object from another thread. If the operation
4045 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4047 * Returns: %TRUE if the @attribute was successfully set to @value
4048 * in the @file, %FALSE otherwise.
4051 g_file_set_attribute_byte_string (GFile *file,
4052 const char *attribute,
4054 GFileQueryInfoFlags flags,
4055 GCancellable *cancellable,
4058 return g_file_set_attribute (file, attribute,
4059 G_FILE_ATTRIBUTE_TYPE_BYTE_STRING, (gpointer)value,
4060 flags, cancellable, error);
4064 * g_file_set_attribute_uint32:
4065 * @file: input #GFile.
4066 * @attribute: a string containing the attribute's name.
4067 * @value: a #guint32 containing the attribute's new value.
4068 * @flags: a #GFileQueryInfoFlags.
4069 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4070 * @error: a #GError, or %NULL
4072 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value.
4073 * If @attribute is of a different type, this operation will fail.
4075 * If @cancellable is not %NULL, then the operation can be cancelled by
4076 * triggering the cancellable object from another thread. If the operation
4077 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4079 * Returns: %TRUE if the @attribute was successfully set to @value
4080 * in the @file, %FALSE otherwise.
4083 g_file_set_attribute_uint32 (GFile *file,
4084 const char *attribute,
4086 GFileQueryInfoFlags flags,
4087 GCancellable *cancellable,
4090 return g_file_set_attribute (file, attribute,
4091 G_FILE_ATTRIBUTE_TYPE_UINT32, &value,
4092 flags, cancellable, error);
4096 * g_file_set_attribute_int32:
4097 * @file: input #GFile.
4098 * @attribute: a string containing the attribute's name.
4099 * @value: a #gint32 containing the attribute's new value.
4100 * @flags: a #GFileQueryInfoFlags.
4101 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4102 * @error: a #GError, or %NULL
4104 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value.
4105 * If @attribute is of a different type, this operation will fail.
4107 * If @cancellable is not %NULL, then the operation can be cancelled by
4108 * triggering the cancellable object from another thread. If the operation
4109 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4111 * Returns: %TRUE if the @attribute was successfully set to @value
4112 * in the @file, %FALSE otherwise.
4115 g_file_set_attribute_int32 (GFile *file,
4116 const char *attribute,
4118 GFileQueryInfoFlags flags,
4119 GCancellable *cancellable,
4122 return g_file_set_attribute (file, attribute,
4123 G_FILE_ATTRIBUTE_TYPE_INT32, &value,
4124 flags, cancellable, error);
4128 * g_file_set_attribute_uint64:
4129 * @file: input #GFile.
4130 * @attribute: a string containing the attribute's name.
4131 * @value: a #guint64 containing the attribute's new value.
4132 * @flags: a #GFileQueryInfoFlags.
4133 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4134 * @error: a #GError, or %NULL
4136 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value.
4137 * If @attribute is of a different type, this operation will fail.
4139 * If @cancellable is not %NULL, then the operation can be cancelled by
4140 * triggering the cancellable object from another thread. If the operation
4141 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4143 * Returns: %TRUE if the @attribute was successfully set to @value
4144 * in the @file, %FALSE otherwise.
4147 g_file_set_attribute_uint64 (GFile *file,
4148 const char *attribute,
4150 GFileQueryInfoFlags flags,
4151 GCancellable *cancellable,
4154 return g_file_set_attribute (file, attribute,
4155 G_FILE_ATTRIBUTE_TYPE_UINT64, &value,
4156 flags, cancellable, error);
4160 * g_file_set_attribute_int64:
4161 * @file: input #GFile.
4162 * @attribute: a string containing the attribute's name.
4163 * @value: a #guint64 containing the attribute's new value.
4164 * @flags: a #GFileQueryInfoFlags.
4165 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4166 * @error: a #GError, or %NULL
4168 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value.
4169 * If @attribute is of a different type, this operation will fail.
4171 * If @cancellable is not %NULL, then the operation can be cancelled by
4172 * triggering the cancellable object from another thread. If the operation
4173 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4175 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
4178 g_file_set_attribute_int64 (GFile *file,
4179 const char *attribute,
4181 GFileQueryInfoFlags flags,
4182 GCancellable *cancellable,
4185 return g_file_set_attribute (file, attribute,
4186 G_FILE_ATTRIBUTE_TYPE_INT64, &value,
4187 flags, cancellable, error);
4191 * g_file_mount_mountable:
4192 * @file: input #GFile.
4193 * @flags: flags affecting the operation
4194 * @mount_operation: (allow-none): a #GMountOperation, or %NULL to avoid user interaction.
4195 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4196 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4197 * @user_data: (closure): the data to pass to callback function
4199 * Mounts a file of type G_FILE_TYPE_MOUNTABLE.
4200 * Using @mount_operation, you can request callbacks when, for instance,
4201 * passwords are needed during authentication.
4203 * If @cancellable is not %NULL, then the operation can be cancelled by
4204 * triggering the cancellable object from another thread. If the operation
4205 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4207 * When the operation is finished, @callback will be called. You can then call
4208 * g_file_mount_mountable_finish() to get the result of the operation.
4211 g_file_mount_mountable (GFile *file,
4212 GMountMountFlags flags,
4213 GMountOperation *mount_operation,
4214 GCancellable *cancellable,
4215 GAsyncReadyCallback callback,
4220 g_return_if_fail (G_IS_FILE (file));
4222 iface = G_FILE_GET_IFACE (file);
4224 if (iface->mount_mountable == NULL)
4226 g_simple_async_report_error_in_idle (G_OBJECT (file),
4230 G_IO_ERROR_NOT_SUPPORTED,
4231 _("Operation not supported"));
4235 (* iface->mount_mountable) (file,
4244 * g_file_mount_mountable_finish:
4245 * @file: input #GFile.
4246 * @result: a #GAsyncResult.
4247 * @error: a #GError, or %NULL
4249 * Finishes a mount operation. See g_file_mount_mountable() for details.
4251 * Finish an asynchronous mount operation that was started
4252 * with g_file_mount_mountable().
4254 * Returns: (transfer full): a #GFile or %NULL on error.
4255 * Free the returned object with g_object_unref().
4258 g_file_mount_mountable_finish (GFile *file,
4259 GAsyncResult *result,
4264 g_return_val_if_fail (G_IS_FILE (file), NULL);
4265 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
4267 if (g_async_result_legacy_propagate_error (result, error))
4270 iface = G_FILE_GET_IFACE (file);
4271 return (* iface->mount_mountable_finish) (file, result, error);
4275 * g_file_unmount_mountable:
4276 * @file: input #GFile.
4277 * @flags: flags affecting the operation
4278 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4279 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4280 * @user_data: (closure): the data to pass to callback function
4282 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
4284 * If @cancellable is not %NULL, then the operation can be cancelled by
4285 * triggering the cancellable object from another thread. If the operation
4286 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4288 * When the operation is finished, @callback will be called. You can then call
4289 * g_file_unmount_mountable_finish() to get the result of the operation.
4291 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation() instead.
4294 g_file_unmount_mountable (GFile *file,
4295 GMountUnmountFlags flags,
4296 GCancellable *cancellable,
4297 GAsyncReadyCallback callback,
4302 g_return_if_fail (G_IS_FILE (file));
4304 iface = G_FILE_GET_IFACE (file);
4306 if (iface->unmount_mountable == NULL)
4308 g_simple_async_report_error_in_idle (G_OBJECT (file),
4312 G_IO_ERROR_NOT_SUPPORTED,
4313 _("Operation not supported"));
4317 (* iface->unmount_mountable) (file,
4325 * g_file_unmount_mountable_finish:
4326 * @file: input #GFile.
4327 * @result: a #GAsyncResult.
4328 * @error: a #GError, or %NULL
4330 * Finishes an unmount operation, see g_file_unmount_mountable() for details.
4332 * Finish an asynchronous unmount operation that was started
4333 * with g_file_unmount_mountable().
4335 * Returns: %TRUE if the operation finished successfully. %FALSE
4338 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation_finish() instead.
4341 g_file_unmount_mountable_finish (GFile *file,
4342 GAsyncResult *result,
4347 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4348 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4350 if (g_async_result_legacy_propagate_error (result, error))
4353 iface = G_FILE_GET_IFACE (file);
4354 return (* iface->unmount_mountable_finish) (file, result, error);
4358 * g_file_unmount_mountable_with_operation:
4359 * @file: input #GFile.
4360 * @flags: flags affecting the operation
4361 * @mount_operation: (allow-none): a #GMountOperation, or %NULL to avoid user interaction.
4362 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4363 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4364 * @user_data: (closure): the data to pass to callback function
4366 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
4368 * If @cancellable is not %NULL, then the operation can be cancelled by
4369 * triggering the cancellable object from another thread. If the operation
4370 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4372 * When the operation is finished, @callback will be called. You can then call
4373 * g_file_unmount_mountable_finish() to get the result of the operation.
4378 g_file_unmount_mountable_with_operation (GFile *file,
4379 GMountUnmountFlags flags,
4380 GMountOperation *mount_operation,
4381 GCancellable *cancellable,
4382 GAsyncReadyCallback callback,
4387 g_return_if_fail (G_IS_FILE (file));
4389 iface = G_FILE_GET_IFACE (file);
4391 if (iface->unmount_mountable == NULL && iface->unmount_mountable_with_operation == NULL)
4393 g_simple_async_report_error_in_idle (G_OBJECT (file),
4397 G_IO_ERROR_NOT_SUPPORTED,
4398 _("Operation not supported"));
4402 if (iface->unmount_mountable_with_operation != NULL)
4403 (* iface->unmount_mountable_with_operation) (file,
4410 (* iface->unmount_mountable) (file,
4418 * g_file_unmount_mountable_with_operation_finish:
4419 * @file: input #GFile.
4420 * @result: a #GAsyncResult.
4421 * @error: a #GError, or %NULL
4423 * Finishes an unmount operation, see g_file_unmount_mountable_with_operation() for details.
4425 * Finish an asynchronous unmount operation that was started
4426 * with g_file_unmount_mountable_with_operation().
4428 * Returns: %TRUE if the operation finished successfully. %FALSE
4434 g_file_unmount_mountable_with_operation_finish (GFile *file,
4435 GAsyncResult *result,
4440 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4441 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4443 if (g_async_result_legacy_propagate_error (result, error))
4446 iface = G_FILE_GET_IFACE (file);
4447 if (iface->unmount_mountable_with_operation_finish != NULL)
4448 return (* iface->unmount_mountable_with_operation_finish) (file, result, error);
4450 return (* iface->unmount_mountable_finish) (file, result, error);
4454 * g_file_eject_mountable:
4455 * @file: input #GFile.
4456 * @flags: flags affecting the operation
4457 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4458 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4459 * @user_data: (closure): the data to pass to callback function
4461 * Starts an asynchronous eject on a mountable.
4462 * When this operation has completed, @callback will be called with
4463 * @user_user data, and the operation can be finalized with
4464 * g_file_eject_mountable_finish().
4466 * If @cancellable is not %NULL, then the operation can be cancelled by
4467 * triggering the cancellable object from another thread. If the operation
4468 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4470 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation() instead.
4473 g_file_eject_mountable (GFile *file,
4474 GMountUnmountFlags flags,
4475 GCancellable *cancellable,
4476 GAsyncReadyCallback callback,
4481 g_return_if_fail (G_IS_FILE (file));
4483 iface = G_FILE_GET_IFACE (file);
4485 if (iface->eject_mountable == NULL)
4487 g_simple_async_report_error_in_idle (G_OBJECT (file),
4491 G_IO_ERROR_NOT_SUPPORTED,
4492 _("Operation not supported"));
4496 (* iface->eject_mountable) (file,
4504 * g_file_eject_mountable_finish:
4505 * @file: input #GFile.
4506 * @result: a #GAsyncResult.
4507 * @error: a #GError, or %NULL
4509 * Finishes an asynchronous eject operation started by
4510 * g_file_eject_mountable().
4512 * Returns: %TRUE if the @file was ejected successfully. %FALSE
4515 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation_finish() instead.
4518 g_file_eject_mountable_finish (GFile *file,
4519 GAsyncResult *result,
4524 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4525 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4527 if (g_async_result_legacy_propagate_error (result, error))
4530 iface = G_FILE_GET_IFACE (file);
4531 return (* iface->eject_mountable_finish) (file, result, error);
4535 * g_file_eject_mountable_with_operation:
4536 * @file: input #GFile.
4537 * @flags: flags affecting the operation
4538 * @mount_operation: (allow-none): a #GMountOperation, or %NULL to avoid user interaction.
4539 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4540 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4541 * @user_data: (closure): the data to pass to callback function
4543 * Starts an asynchronous eject on a mountable.
4544 * When this operation has completed, @callback will be called with
4545 * @user_user data, and the operation can be finalized with
4546 * g_file_eject_mountable_with_operation_finish().
4548 * If @cancellable is not %NULL, then the operation can be cancelled by
4549 * triggering the cancellable object from another thread. If the operation
4550 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4555 g_file_eject_mountable_with_operation (GFile *file,
4556 GMountUnmountFlags flags,
4557 GMountOperation *mount_operation,
4558 GCancellable *cancellable,
4559 GAsyncReadyCallback callback,
4564 g_return_if_fail (G_IS_FILE (file));
4566 iface = G_FILE_GET_IFACE (file);
4568 if (iface->eject_mountable == NULL && iface->eject_mountable_with_operation == NULL)
4570 g_simple_async_report_error_in_idle (G_OBJECT (file),
4574 G_IO_ERROR_NOT_SUPPORTED,
4575 _("Operation not supported"));
4579 if (iface->eject_mountable_with_operation != NULL)
4580 (* iface->eject_mountable_with_operation) (file,
4587 (* iface->eject_mountable) (file,
4595 * g_file_eject_mountable_with_operation_finish:
4596 * @file: input #GFile.
4597 * @result: a #GAsyncResult.
4598 * @error: a #GError, or %NULL
4600 * Finishes an asynchronous eject operation started by
4601 * g_file_eject_mountable_with_operation().
4603 * Returns: %TRUE if the @file was ejected successfully. %FALSE
4609 g_file_eject_mountable_with_operation_finish (GFile *file,
4610 GAsyncResult *result,
4615 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4616 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4618 if (g_async_result_legacy_propagate_error (result, error))
4621 iface = G_FILE_GET_IFACE (file);
4622 if (iface->eject_mountable_with_operation_finish != NULL)
4623 return (* iface->eject_mountable_with_operation_finish) (file, result, error);
4625 return (* iface->eject_mountable_finish) (file, result, error);
4629 * g_file_monitor_directory:
4630 * @file: input #GFile.
4631 * @flags: a set of #GFileMonitorFlags.
4632 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4633 * @error: a #GError, or %NULL.
4635 * Obtains a directory monitor for the given file.
4636 * This may fail if directory monitoring is not supported.
4638 * If @cancellable is not %NULL, then the operation can be cancelled by
4639 * triggering the cancellable object from another thread. If the operation
4640 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4642 * Virtual: monitor_dir
4643 * Returns: (transfer full): a #GFileMonitor for the given @file, or %NULL on error.
4644 * Free the returned object with g_object_unref().
4647 g_file_monitor_directory (GFile *file,
4648 GFileMonitorFlags flags,
4649 GCancellable *cancellable,
4654 g_return_val_if_fail (G_IS_FILE (file), NULL);
4656 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4659 iface = G_FILE_GET_IFACE (file);
4661 if (iface->monitor_dir == NULL)
4663 g_set_error_literal (error, G_IO_ERROR,
4664 G_IO_ERROR_NOT_SUPPORTED,
4665 _("Operation not supported"));
4669 return (* iface->monitor_dir) (file, flags, cancellable, error);
4673 * g_file_monitor_file:
4674 * @file: input #GFile.
4675 * @flags: a set of #GFileMonitorFlags.
4676 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4677 * @error: a #GError, or %NULL.
4679 * Obtains a file monitor for the given file. If no file notification
4680 * mechanism exists, then regular polling of the file is used.
4682 * If @cancellable is not %NULL, then the operation can be cancelled by
4683 * triggering the cancellable object from another thread. If the operation
4684 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4686 * Returns: (transfer full): a #GFileMonitor for the given @file, or %NULL on error.
4687 * Free the returned object with g_object_unref().
4690 g_file_monitor_file (GFile *file,
4691 GFileMonitorFlags flags,
4692 GCancellable *cancellable,
4696 GFileMonitor *monitor;
4698 g_return_val_if_fail (G_IS_FILE (file), NULL);
4700 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4703 iface = G_FILE_GET_IFACE (file);
4707 if (iface->monitor_file)
4708 monitor = (* iface->monitor_file) (file, flags, cancellable, NULL);
4710 /* Fallback to polling */
4711 if (monitor == NULL)
4712 monitor = _g_poll_file_monitor_new (file);
4719 * @file: input #GFile
4720 * @flags: a set of #GFileMonitorFlags
4721 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
4722 * @error: a #GError, or %NULL
4724 * Obtains a file or directory monitor for the given file, depending
4725 * on the type of the file.
4727 * If @cancellable is not %NULL, then the operation can be cancelled by
4728 * triggering the cancellable object from another thread. If the operation
4729 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4731 * Returns: (transfer full): a #GFileMonitor for the given @file, or %NULL on error.
4732 * Free the returned object with g_object_unref().
4737 g_file_monitor (GFile *file,
4738 GFileMonitorFlags flags,
4739 GCancellable *cancellable,
4742 if (g_file_query_file_type (file, 0, cancellable) == G_FILE_TYPE_DIRECTORY)
4743 return g_file_monitor_directory (file, flags, cancellable, error);
4745 return g_file_monitor_file (file, flags, cancellable, error);
4748 /********************************************
4749 * Default implementation of async ops *
4750 ********************************************/
4754 GFileQueryInfoFlags flags;
4756 } QueryInfoAsyncData;
4759 query_info_data_free (QueryInfoAsyncData *data)
4762 g_object_unref (data->info);
4763 g_free (data->attributes);
4768 query_info_async_thread (GSimpleAsyncResult *res,
4770 GCancellable *cancellable)
4772 GError *error = NULL;
4773 QueryInfoAsyncData *data;
4776 data = g_simple_async_result_get_op_res_gpointer (res);
4778 info = g_file_query_info (G_FILE (object), data->attributes, data->flags, cancellable, &error);
4781 g_simple_async_result_take_error (res, error);
4787 g_file_real_query_info_async (GFile *file,
4788 const char *attributes,
4789 GFileQueryInfoFlags flags,
4791 GCancellable *cancellable,
4792 GAsyncReadyCallback callback,
4795 GSimpleAsyncResult *res;
4796 QueryInfoAsyncData *data;
4798 data = g_new0 (QueryInfoAsyncData, 1);
4799 data->attributes = g_strdup (attributes);
4800 data->flags = flags;
4802 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_query_info_async);
4803 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_info_data_free);
4805 g_simple_async_result_run_in_thread (res, query_info_async_thread, io_priority, cancellable);
4806 g_object_unref (res);
4810 g_file_real_query_info_finish (GFile *file,
4814 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4815 QueryInfoAsyncData *data;
4817 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_info_async);
4819 if (g_simple_async_result_propagate_error (simple, error))
4822 data = g_simple_async_result_get_op_res_gpointer (simple);
4824 return g_object_ref (data->info);
4832 } QueryFilesystemInfoAsyncData;
4835 query_filesystem_info_data_free (QueryFilesystemInfoAsyncData *data)
4838 g_object_unref (data->info);
4839 g_free (data->attributes);
4844 query_filesystem_info_async_thread (GSimpleAsyncResult *res,
4846 GCancellable *cancellable)
4848 GError *error = NULL;
4849 QueryFilesystemInfoAsyncData *data;
4852 data = g_simple_async_result_get_op_res_gpointer (res);
4854 info = g_file_query_filesystem_info (G_FILE (object), data->attributes, cancellable, &error);
4857 g_simple_async_result_take_error (res, error);
4863 g_file_real_query_filesystem_info_async (GFile *file,
4864 const char *attributes,
4866 GCancellable *cancellable,
4867 GAsyncReadyCallback callback,
4870 GSimpleAsyncResult *res;
4871 QueryFilesystemInfoAsyncData *data;
4873 data = g_new0 (QueryFilesystemInfoAsyncData, 1);
4874 data->attributes = g_strdup (attributes);
4876 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_query_filesystem_info_async);
4877 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_filesystem_info_data_free);
4879 g_simple_async_result_run_in_thread (res, query_filesystem_info_async_thread, io_priority, cancellable);
4880 g_object_unref (res);
4884 g_file_real_query_filesystem_info_finish (GFile *file,
4888 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4889 QueryFilesystemInfoAsyncData *data;
4891 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_filesystem_info_async);
4893 if (g_simple_async_result_propagate_error (simple, error))
4896 data = g_simple_async_result_get_op_res_gpointer (simple);
4898 return g_object_ref (data->info);
4905 GFileQueryInfoFlags flags;
4906 GFileEnumerator *enumerator;
4907 } EnumerateChildrenAsyncData;
4910 enumerate_children_data_free (EnumerateChildrenAsyncData *data)
4912 if (data->enumerator)
4913 g_object_unref (data->enumerator);
4914 g_free (data->attributes);
4919 enumerate_children_async_thread (GSimpleAsyncResult *res,
4921 GCancellable *cancellable)
4923 GError *error = NULL;
4924 EnumerateChildrenAsyncData *data;
4925 GFileEnumerator *enumerator;
4927 data = g_simple_async_result_get_op_res_gpointer (res);
4929 enumerator = g_file_enumerate_children (G_FILE (object), data->attributes, data->flags, cancellable, &error);
4931 if (enumerator == NULL)
4932 g_simple_async_result_take_error (res, error);
4934 data->enumerator = enumerator;
4938 g_file_real_enumerate_children_async (GFile *file,
4939 const char *attributes,
4940 GFileQueryInfoFlags flags,
4942 GCancellable *cancellable,
4943 GAsyncReadyCallback callback,
4946 GSimpleAsyncResult *res;
4947 EnumerateChildrenAsyncData *data;
4949 data = g_new0 (EnumerateChildrenAsyncData, 1);
4950 data->attributes = g_strdup (attributes);
4951 data->flags = flags;
4953 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_enumerate_children_async);
4954 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)enumerate_children_data_free);
4956 g_simple_async_result_run_in_thread (res, enumerate_children_async_thread, io_priority, cancellable);
4957 g_object_unref (res);
4960 static GFileEnumerator *
4961 g_file_real_enumerate_children_finish (GFile *file,
4965 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4966 EnumerateChildrenAsyncData *data;
4968 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_enumerate_children_async);
4970 if (g_simple_async_result_propagate_error (simple, error))
4973 data = g_simple_async_result_get_op_res_gpointer (simple);
4974 if (data->enumerator)
4975 return g_object_ref (data->enumerator);
4981 open_read_async_thread (GSimpleAsyncResult *res,
4983 GCancellable *cancellable)
4986 GFileInputStream *stream;
4987 GError *error = NULL;
4989 iface = G_FILE_GET_IFACE (object);
4991 if (iface->read_fn == NULL)
4993 g_set_error_literal (&error, G_IO_ERROR,
4994 G_IO_ERROR_NOT_SUPPORTED,
4995 _("Operation not supported"));
4997 g_simple_async_result_take_error (res, error);
5002 stream = iface->read_fn (G_FILE (object), cancellable, &error);
5005 g_simple_async_result_take_error (res, error);
5007 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5011 g_file_real_read_async (GFile *file,
5013 GCancellable *cancellable,
5014 GAsyncReadyCallback callback,
5017 GSimpleAsyncResult *res;
5019 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_read_async);
5021 g_simple_async_result_run_in_thread (res, open_read_async_thread, io_priority, cancellable);
5022 g_object_unref (res);
5025 static GFileInputStream *
5026 g_file_real_read_finish (GFile *file,
5030 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5033 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_read_async);
5035 if (g_simple_async_result_propagate_error (simple, error))
5038 op = g_simple_async_result_get_op_res_gpointer (simple);
5040 return g_object_ref (op);
5046 append_to_async_thread (GSimpleAsyncResult *res,
5048 GCancellable *cancellable)
5051 GFileCreateFlags *data;
5052 GFileOutputStream *stream;
5053 GError *error = NULL;
5055 iface = G_FILE_GET_IFACE (object);
5057 data = g_simple_async_result_get_op_res_gpointer (res);
5059 stream = iface->append_to (G_FILE (object), *data, cancellable, &error);
5062 g_simple_async_result_take_error (res, error);
5064 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5068 g_file_real_append_to_async (GFile *file,
5069 GFileCreateFlags flags,
5071 GCancellable *cancellable,
5072 GAsyncReadyCallback callback,
5075 GFileCreateFlags *data;
5076 GSimpleAsyncResult *res;
5078 data = g_new0 (GFileCreateFlags, 1);
5081 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_append_to_async);
5082 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
5084 g_simple_async_result_run_in_thread (res, append_to_async_thread, io_priority, cancellable);
5085 g_object_unref (res);
5088 static GFileOutputStream *
5089 g_file_real_append_to_finish (GFile *file,
5093 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5096 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_append_to_async);
5098 if (g_simple_async_result_propagate_error (simple, error))
5101 op = g_simple_async_result_get_op_res_gpointer (simple);
5103 return g_object_ref (op);
5109 create_async_thread (GSimpleAsyncResult *res,
5111 GCancellable *cancellable)
5114 GFileCreateFlags *data;
5115 GFileOutputStream *stream;
5116 GError *error = NULL;
5118 iface = G_FILE_GET_IFACE (object);
5120 data = g_simple_async_result_get_op_res_gpointer (res);
5122 stream = iface->create (G_FILE (object), *data, cancellable, &error);
5125 g_simple_async_result_take_error (res, error);
5127 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5131 g_file_real_create_async (GFile *file,
5132 GFileCreateFlags flags,
5134 GCancellable *cancellable,
5135 GAsyncReadyCallback callback,
5138 GFileCreateFlags *data;
5139 GSimpleAsyncResult *res;
5141 data = g_new0 (GFileCreateFlags, 1);
5144 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_create_async);
5145 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
5147 g_simple_async_result_run_in_thread (res, create_async_thread, io_priority, cancellable);
5148 g_object_unref (res);
5151 static GFileOutputStream *
5152 g_file_real_create_finish (GFile *file,
5156 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5159 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_async);
5161 if (g_simple_async_result_propagate_error (simple, error))
5164 op = g_simple_async_result_get_op_res_gpointer (simple);
5166 return g_object_ref (op);
5172 GFileOutputStream *stream;
5174 gboolean make_backup;
5175 GFileCreateFlags flags;
5179 replace_async_data_free (ReplaceAsyncData *data)
5182 g_object_unref (data->stream);
5183 g_free (data->etag);
5188 replace_async_thread (GSimpleAsyncResult *res,
5190 GCancellable *cancellable)
5193 GFileOutputStream *stream;
5194 GError *error = NULL;
5195 ReplaceAsyncData *data;
5197 iface = G_FILE_GET_IFACE (object);
5199 data = g_simple_async_result_get_op_res_gpointer (res);
5201 stream = iface->replace (G_FILE (object),
5209 g_simple_async_result_take_error (res, error);
5211 data->stream = stream;
5215 g_file_real_replace_async (GFile *file,
5217 gboolean make_backup,
5218 GFileCreateFlags flags,
5220 GCancellable *cancellable,
5221 GAsyncReadyCallback callback,
5224 GSimpleAsyncResult *res;
5225 ReplaceAsyncData *data;
5227 data = g_new0 (ReplaceAsyncData, 1);
5228 data->etag = g_strdup (etag);
5229 data->make_backup = make_backup;
5230 data->flags = flags;
5232 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_replace_async);
5233 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_async_data_free);
5235 g_simple_async_result_run_in_thread (res, replace_async_thread, io_priority, cancellable);
5236 g_object_unref (res);
5239 static GFileOutputStream *
5240 g_file_real_replace_finish (GFile *file,
5244 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5245 ReplaceAsyncData *data;
5247 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_async);
5249 if (g_simple_async_result_propagate_error (simple, error))
5252 data = g_simple_async_result_get_op_res_gpointer (simple);
5254 return g_object_ref (data->stream);
5260 open_readwrite_async_thread (GSimpleAsyncResult *res,
5262 GCancellable *cancellable)
5265 GFileIOStream *stream;
5266 GError *error = NULL;
5268 iface = G_FILE_GET_IFACE (object);
5270 if (iface->open_readwrite == NULL)
5272 g_set_error_literal (&error, G_IO_ERROR,
5273 G_IO_ERROR_NOT_SUPPORTED,
5274 _("Operation not supported"));
5276 g_simple_async_result_take_error (res, error);
5281 stream = iface->open_readwrite (G_FILE (object), cancellable, &error);
5284 g_simple_async_result_take_error (res, error);
5286 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5290 g_file_real_open_readwrite_async (GFile *file,
5292 GCancellable *cancellable,
5293 GAsyncReadyCallback callback,
5296 GSimpleAsyncResult *res;
5298 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_open_readwrite_async);
5300 g_simple_async_result_run_in_thread (res, open_readwrite_async_thread, io_priority, cancellable);
5301 g_object_unref (res);
5304 static GFileIOStream *
5305 g_file_real_open_readwrite_finish (GFile *file,
5309 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5312 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_open_readwrite_async);
5314 if (g_simple_async_result_propagate_error (simple, error))
5317 op = g_simple_async_result_get_op_res_gpointer (simple);
5319 return g_object_ref (op);
5325 create_readwrite_async_thread (GSimpleAsyncResult *res,
5327 GCancellable *cancellable)
5330 GFileCreateFlags *data;
5331 GFileIOStream *stream;
5332 GError *error = NULL;
5334 iface = G_FILE_GET_IFACE (object);
5336 data = g_simple_async_result_get_op_res_gpointer (res);
5338 if (iface->create_readwrite == NULL)
5340 g_set_error_literal (&error, G_IO_ERROR,
5341 G_IO_ERROR_NOT_SUPPORTED,
5342 _("Operation not supported"));
5344 g_simple_async_result_take_error (res, error);
5349 stream = iface->create_readwrite (G_FILE (object), *data, cancellable, &error);
5352 g_simple_async_result_take_error (res, error);
5354 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5358 g_file_real_create_readwrite_async (GFile *file,
5359 GFileCreateFlags flags,
5361 GCancellable *cancellable,
5362 GAsyncReadyCallback callback,
5365 GFileCreateFlags *data;
5366 GSimpleAsyncResult *res;
5368 data = g_new0 (GFileCreateFlags, 1);
5371 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_create_readwrite_async);
5372 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
5374 g_simple_async_result_run_in_thread (res, create_readwrite_async_thread, io_priority, cancellable);
5375 g_object_unref (res);
5378 static GFileIOStream *
5379 g_file_real_create_readwrite_finish (GFile *file,
5383 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5386 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_readwrite_async);
5388 if (g_simple_async_result_propagate_error (simple, error))
5391 op = g_simple_async_result_get_op_res_gpointer (simple);
5393 return g_object_ref (op);
5399 GFileIOStream *stream;
5401 gboolean make_backup;
5402 GFileCreateFlags flags;
5403 } ReplaceRWAsyncData;
5406 replace_rw_async_data_free (ReplaceRWAsyncData *data)
5409 g_object_unref (data->stream);
5410 g_free (data->etag);
5415 replace_readwrite_async_thread (GSimpleAsyncResult *res,
5417 GCancellable *cancellable)
5420 GFileIOStream *stream;
5421 GError *error = NULL;
5422 ReplaceRWAsyncData *data;
5424 iface = G_FILE_GET_IFACE (object);
5426 data = g_simple_async_result_get_op_res_gpointer (res);
5428 stream = iface->replace_readwrite (G_FILE (object),
5436 g_simple_async_result_take_error (res, error);
5438 data->stream = stream;
5442 g_file_real_replace_readwrite_async (GFile *file,
5444 gboolean make_backup,
5445 GFileCreateFlags flags,
5447 GCancellable *cancellable,
5448 GAsyncReadyCallback callback,
5451 GSimpleAsyncResult *res;
5452 ReplaceRWAsyncData *data;
5454 data = g_new0 (ReplaceRWAsyncData, 1);
5455 data->etag = g_strdup (etag);
5456 data->make_backup = make_backup;
5457 data->flags = flags;
5459 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_replace_readwrite_async);
5460 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_rw_async_data_free);
5462 g_simple_async_result_run_in_thread (res, replace_readwrite_async_thread, io_priority, cancellable);
5463 g_object_unref (res);
5466 static GFileIOStream *
5467 g_file_real_replace_readwrite_finish (GFile *file,
5471 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5472 ReplaceRWAsyncData *data;
5474 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_readwrite_async);
5476 if (g_simple_async_result_propagate_error (simple, error))
5479 data = g_simple_async_result_get_op_res_gpointer (simple);
5481 return g_object_ref (data->stream);
5489 } SetDisplayNameAsyncData;
5492 set_display_name_data_free (SetDisplayNameAsyncData *data)
5494 g_free (data->name);
5496 g_object_unref (data->file);
5501 set_display_name_async_thread (GSimpleAsyncResult *res,
5503 GCancellable *cancellable)
5505 GError *error = NULL;
5506 SetDisplayNameAsyncData *data;
5509 data = g_simple_async_result_get_op_res_gpointer (res);
5511 file = g_file_set_display_name (G_FILE (object), data->name, cancellable, &error);
5514 g_simple_async_result_take_error (res, error);
5520 g_file_real_set_display_name_async (GFile *file,
5521 const char *display_name,
5523 GCancellable *cancellable,
5524 GAsyncReadyCallback callback,
5527 GSimpleAsyncResult *res;
5528 SetDisplayNameAsyncData *data;
5530 data = g_new0 (SetDisplayNameAsyncData, 1);
5531 data->name = g_strdup (display_name);
5533 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_set_display_name_async);
5534 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)set_display_name_data_free);
5536 g_simple_async_result_run_in_thread (res, set_display_name_async_thread, io_priority, cancellable);
5537 g_object_unref (res);
5541 g_file_real_set_display_name_finish (GFile *file,
5545 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5546 SetDisplayNameAsyncData *data;
5548 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_display_name_async);
5550 if (g_simple_async_result_propagate_error (simple, error))
5553 data = g_simple_async_result_get_op_res_gpointer (simple);
5555 return g_object_ref (data->file);
5561 GFileQueryInfoFlags flags;
5568 set_info_data_free (SetInfoAsyncData *data)
5571 g_object_unref (data->info);
5573 g_error_free (data->error);
5578 set_info_async_thread (GSimpleAsyncResult *res,
5580 GCancellable *cancellable)
5582 SetInfoAsyncData *data;
5584 data = g_simple_async_result_get_op_res_gpointer (res);
5587 data->res = g_file_set_attributes_from_info (G_FILE (object),
5595 g_file_real_set_attributes_async (GFile *file,
5597 GFileQueryInfoFlags flags,
5599 GCancellable *cancellable,
5600 GAsyncReadyCallback callback,
5603 GSimpleAsyncResult *res;
5604 SetInfoAsyncData *data;
5606 data = g_new0 (SetInfoAsyncData, 1);
5607 data->info = g_file_info_dup (info);
5608 data->flags = flags;
5610 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_set_attributes_async);
5611 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)set_info_data_free);
5613 g_simple_async_result_run_in_thread (res, set_info_async_thread, io_priority, cancellable);
5614 g_object_unref (res);
5618 g_file_real_set_attributes_finish (GFile *file,
5623 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5624 SetInfoAsyncData *data;
5626 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_attributes_async);
5628 data = g_simple_async_result_get_op_res_gpointer (simple);
5631 *info = g_object_ref (data->info);
5633 if (error != NULL && data->error)
5634 *error = g_error_copy (data->error);
5640 find_enclosing_mount_async_thread (GSimpleAsyncResult *res,
5642 GCancellable *cancellable)
5644 GError *error = NULL;
5647 mount = g_file_find_enclosing_mount (G_FILE (object), cancellable, &error);
5650 g_simple_async_result_take_error (res, error);
5652 g_simple_async_result_set_op_res_gpointer (res, mount, (GDestroyNotify)g_object_unref);
5656 g_file_real_find_enclosing_mount_async (GFile *file,
5658 GCancellable *cancellable,
5659 GAsyncReadyCallback callback,
5662 GSimpleAsyncResult *res;
5664 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_find_enclosing_mount_async);
5666 g_simple_async_result_run_in_thread (res, find_enclosing_mount_async_thread, io_priority, cancellable);
5667 g_object_unref (res);
5671 g_file_real_find_enclosing_mount_finish (GFile *file,
5675 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5678 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_find_enclosing_mount_async);
5680 if (g_simple_async_result_propagate_error (simple, error))
5683 mount = g_simple_async_result_get_op_res_gpointer (simple);
5684 return g_object_ref (mount);
5691 GFileCopyFlags flags;
5692 GFileProgressCallback progress_cb;
5693 gpointer progress_cb_data;
5694 GIOSchedulerJob *job;
5698 copy_async_data_free (CopyAsyncData *data)
5700 g_object_unref (data->source);
5701 g_object_unref (data->destination);
5706 CopyAsyncData *data;
5707 goffset current_num_bytes;
5708 goffset total_num_bytes;
5712 copy_async_progress_in_main (gpointer user_data)
5714 ProgressData *progress = user_data;
5715 CopyAsyncData *data = progress->data;
5717 data->progress_cb (progress->current_num_bytes,
5718 progress->total_num_bytes,
5719 data->progress_cb_data);
5725 copy_async_progress_callback (goffset current_num_bytes,
5726 goffset total_num_bytes,
5729 CopyAsyncData *data = user_data;
5730 ProgressData *progress;
5732 progress = g_new (ProgressData, 1);
5733 progress->data = data;
5734 progress->current_num_bytes = current_num_bytes;
5735 progress->total_num_bytes = total_num_bytes;
5737 g_io_scheduler_job_send_to_mainloop_async (data->job,
5738 copy_async_progress_in_main,
5744 copy_async_thread (GIOSchedulerJob *job,
5745 GCancellable *cancellable,
5748 GSimpleAsyncResult *res;
5749 CopyAsyncData *data;
5754 data = g_simple_async_result_get_op_res_gpointer (res);
5758 result = g_file_copy (data->source,
5762 (data->progress_cb != NULL) ? copy_async_progress_callback : NULL,
5767 g_simple_async_result_take_error (res, error);
5769 g_simple_async_result_complete_in_idle (res);
5775 g_file_real_copy_async (GFile *source,
5777 GFileCopyFlags flags,
5779 GCancellable *cancellable,
5780 GFileProgressCallback progress_callback,
5781 gpointer progress_callback_data,
5782 GAsyncReadyCallback callback,
5785 GSimpleAsyncResult *res;
5786 CopyAsyncData *data;
5788 data = g_new0 (CopyAsyncData, 1);
5789 data->source = g_object_ref (source);
5790 data->destination = g_object_ref (destination);
5791 data->flags = flags;
5792 data->progress_cb = progress_callback;
5793 data->progress_cb_data = progress_callback_data;
5795 res = g_simple_async_result_new (G_OBJECT (source), callback, user_data, g_file_real_copy_async);
5796 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)copy_async_data_free);
5798 g_io_scheduler_push_job (copy_async_thread, res, g_object_unref, io_priority, cancellable);
5802 g_file_real_copy_finish (GFile *file,
5806 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5808 if (g_simple_async_result_propagate_error (simple, error))
5815 /********************************************
5816 * Default VFS operations *
5817 ********************************************/
5820 * g_file_new_for_path:
5821 * @path: a string containing a relative or absolute path. The string
5822 * must be encoded in the glib filename encoding.
5824 * Constructs a #GFile for a given path. This operation never
5825 * fails, but the returned object might not support any I/O
5826 * operation if @path is malformed.
5828 * Returns: (transfer full): a new #GFile for the given @path.
5829 * Free the returned object with g_object_unref().
5832 g_file_new_for_path (const char *path)
5834 g_return_val_if_fail (path != NULL, NULL);
5836 return g_vfs_get_file_for_path (g_vfs_get_default (), path);
5840 * g_file_new_for_uri:
5841 * @uri: a UTF8 string containing a URI.
5843 * Constructs a #GFile for a given URI. This operation never
5844 * fails, but the returned object might not support any I/O
5845 * operation if @uri is malformed or if the uri type is
5848 * Returns: (transfer full): a new #GFile for the given @uri.
5849 * Free the returned object with g_object_unref().
5852 g_file_new_for_uri (const char *uri)
5854 g_return_val_if_fail (uri != NULL, NULL);
5856 return g_vfs_get_file_for_uri (g_vfs_get_default (), uri);
5861 * @tmpl: (type filename) (allow-none): Template for the file
5862 * name, as in g_file_open_tmp(), or %NULL for a default template.
5863 * @iostream: (out): on return, a #GFileIOStream for the created file.
5864 * @error: a #GError, or %NULL
5866 * Opens a file in the preferred directory for temporary files (as
5867 * returned by g_get_tmp_dir()) and returns a #GFile and
5868 * #GFileIOStream pointing to it.
5870 * @tmpl should be a string in the GLib file name encoding
5871 * containing a sequence of six 'X' characters, and containing no
5872 * directory components. If it is %NULL, a default template is used.
5874 * Unlike the other #GFile constructors, this will return %NULL if
5875 * a temporary file could not be created.
5877 * Returns: (transfer full): a new #GFile.
5878 * Free the returned object with g_object_unref().
5883 g_file_new_tmp (const char *tmpl,
5884 GFileIOStream **iostream,
5890 GFileOutputStream *output;
5892 g_return_val_if_fail (iostream != NULL, NULL);
5894 fd = g_file_open_tmp (tmpl, &path, error);
5898 file = g_file_new_for_path (path);
5900 output = _g_local_file_output_stream_new (fd);
5901 *iostream = _g_local_file_io_stream_new (G_LOCAL_FILE_OUTPUT_STREAM (output));
5903 g_object_unref (output);
5910 * g_file_parse_name:
5911 * @parse_name: a file name or path to be parsed.
5913 * Constructs a #GFile with the given @parse_name (i.e. something given by g_file_get_parse_name()).
5914 * This operation never fails, but the returned object might not support any I/O
5915 * operation if the @parse_name cannot be parsed.
5917 * Returns: (transfer full): a new #GFile.
5920 g_file_parse_name (const char *parse_name)
5922 g_return_val_if_fail (parse_name != NULL, NULL);
5924 return g_vfs_parse_name (g_vfs_get_default (), parse_name);
5928 is_valid_scheme_character (char c)
5930 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
5933 /* Following RFC 2396, valid schemes are built like:
5934 * scheme = alpha *( alpha | digit | "+" | "-" | "." )
5937 has_valid_scheme (const char *uri)
5943 if (!g_ascii_isalpha (*p))
5948 } while (is_valid_scheme_character (*p));
5954 * g_file_new_for_commandline_arg:
5955 * @arg: a command line string.
5957 * Creates a #GFile with the given argument from the command line. The value of
5958 * @arg can be either a URI, an absolute path or a relative path resolved
5959 * relative to the current working directory.
5960 * This operation never fails, but the returned object might not support any
5961 * I/O operation if @arg points to a malformed path.
5963 * Returns: (transfer full): a new #GFile.
5964 * Free the returned object with g_object_unref().
5967 g_file_new_for_commandline_arg (const char *arg)
5973 g_return_val_if_fail (arg != NULL, NULL);
5975 if (g_path_is_absolute (arg))
5976 return g_file_new_for_path (arg);
5978 if (has_valid_scheme (arg))
5979 return g_file_new_for_uri (arg);
5981 current_dir = g_get_current_dir ();
5982 filename = g_build_filename (current_dir, arg, NULL);
5983 g_free (current_dir);
5985 file = g_file_new_for_path (filename);
5992 * g_file_mount_enclosing_volume:
5993 * @location: input #GFile.
5994 * @flags: flags affecting the operation
5995 * @mount_operation: (allow-none): a #GMountOperation or %NULL to avoid user interaction.
5996 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
5997 * @callback: (allow-none): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
5998 * @user_data: the data to pass to callback function
6000 * Starts a @mount_operation, mounting the volume that contains the file @location.
6002 * When this operation has completed, @callback will be called with
6003 * @user_user data, and the operation can be finalized with
6004 * g_file_mount_enclosing_volume_finish().
6006 * If @cancellable is not %NULL, then the operation can be cancelled by
6007 * triggering the cancellable object from another thread. If the operation
6008 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6011 g_file_mount_enclosing_volume (GFile *location,
6012 GMountMountFlags flags,
6013 GMountOperation *mount_operation,
6014 GCancellable *cancellable,
6015 GAsyncReadyCallback callback,
6020 g_return_if_fail (G_IS_FILE (location));
6022 iface = G_FILE_GET_IFACE (location);
6024 if (iface->mount_enclosing_volume == NULL)
6026 g_simple_async_report_error_in_idle (G_OBJECT (location),
6027 callback, user_data,
6028 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
6029 _("volume doesn't implement mount"));
6034 (* iface->mount_enclosing_volume) (location, flags, mount_operation, cancellable, callback, user_data);
6039 * g_file_mount_enclosing_volume_finish:
6040 * @location: input #GFile.
6041 * @result: a #GAsyncResult.
6042 * @error: a #GError, or %NULL
6044 * Finishes a mount operation started by g_file_mount_enclosing_volume().
6046 * Returns: %TRUE if successful. If an error
6047 * has occurred, this function will return %FALSE and set @error
6048 * appropriately if present.
6051 g_file_mount_enclosing_volume_finish (GFile *location,
6052 GAsyncResult *result,
6057 g_return_val_if_fail (G_IS_FILE (location), FALSE);
6058 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
6060 if (g_async_result_legacy_propagate_error (result, error))
6063 iface = G_FILE_GET_IFACE (location);
6065 return (* iface->mount_enclosing_volume_finish) (location, result, error);
6068 /********************************************
6069 * Utility functions *
6070 ********************************************/
6073 * g_file_query_default_handler:
6074 * @file: a #GFile to open.
6075 * @cancellable: optional #GCancellable object, %NULL to ignore.
6076 * @error: a #GError, or %NULL
6078 * Returns the #GAppInfo that is registered as the default
6079 * application to handle the file specified by @file.
6081 * If @cancellable is not %NULL, then the operation can be cancelled by
6082 * triggering the cancellable object from another thread. If the operation
6083 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6085 * Returns: (transfer full): a #GAppInfo if the handle was found, %NULL if there were errors.
6086 * When you are done with it, release it with g_object_unref()
6089 g_file_query_default_handler (GFile *file,
6090 GCancellable *cancellable,
6094 const char *content_type;
6099 uri_scheme = g_file_get_uri_scheme (file);
6100 if (uri_scheme && uri_scheme[0] != '\0')
6102 appinfo = g_app_info_get_default_for_uri_scheme (uri_scheme);
6103 g_free (uri_scheme);
6105 if (appinfo != NULL)
6109 info = g_file_query_info (file,
6110 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
6119 content_type = g_file_info_get_content_type (info);
6122 /* Don't use is_native(), as we want to support fuse paths if available */
6123 path = g_file_get_path (file);
6124 appinfo = g_app_info_get_default_for_type (content_type,
6129 g_object_unref (info);
6131 if (appinfo != NULL)
6134 g_set_error_literal (error, G_IO_ERROR,
6135 G_IO_ERROR_NOT_SUPPORTED,
6136 _("No application is registered as handling this file"));
6142 #define GET_CONTENT_BLOCK_SIZE 8192
6145 * g_file_load_contents:
6146 * @file: input #GFile.
6147 * @cancellable: optional #GCancellable object, %NULL to ignore.
6148 * @contents: (out) (transfer full) (element-type guint8) (array length=length): a location to place the contents of the file.
6149 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6150 * or %NULL if the length is not needed
6151 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6152 * or %NULL if the entity tag is not needed
6153 * @error: a #GError, or %NULL
6155 * Loads the content of the file into memory. The data is always
6156 * zero-terminated, but this is not included in the resultant @length.
6157 * The returned @content should be freed with g_free() when no longer
6160 * If @cancellable is not %NULL, then the operation can be cancelled by
6161 * triggering the cancellable object from another thread. If the operation
6162 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6164 * Returns: %TRUE if the @file's contents were successfully loaded.
6165 * %FALSE if there were errors.
6168 g_file_load_contents (GFile *file,
6169 GCancellable *cancellable,
6175 GFileInputStream *in;
6176 GByteArray *content;
6181 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6182 g_return_val_if_fail (contents != NULL, FALSE);
6184 in = g_file_read (file, cancellable, error);
6188 content = g_byte_array_new ();
6191 g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
6192 while ((res = g_input_stream_read (G_INPUT_STREAM (in),
6193 content->data + pos,
6194 GET_CONTENT_BLOCK_SIZE,
6195 cancellable, error)) > 0)
6198 g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
6205 info = g_file_input_stream_query_info (in,
6206 G_FILE_ATTRIBUTE_ETAG_VALUE,
6211 *etag_out = g_strdup (g_file_info_get_etag (info));
6212 g_object_unref (info);
6216 /* Ignore errors on close */
6217 g_input_stream_close (G_INPUT_STREAM (in), cancellable, NULL);
6218 g_object_unref (in);
6222 /* error is set already */
6223 g_byte_array_free (content, TRUE);
6230 /* Zero terminate (we got an extra byte allocated for this */
6231 content->data[pos] = 0;
6233 *contents = (char *)g_byte_array_free (content, FALSE);
6241 GCancellable *cancellable;
6242 GFileReadMoreCallback read_more_callback;
6243 GAsyncReadyCallback callback;
6245 GByteArray *content;
6252 load_contents_data_free (LoadContentsData *data)
6255 g_error_free (data->error);
6256 if (data->cancellable)
6257 g_object_unref (data->cancellable);
6259 g_byte_array_free (data->content, TRUE);
6260 g_free (data->etag);
6261 g_object_unref (data->file);
6266 load_contents_close_callback (GObject *obj,
6267 GAsyncResult *close_res,
6270 GInputStream *stream = G_INPUT_STREAM (obj);
6271 LoadContentsData *data = user_data;
6272 GSimpleAsyncResult *res;
6274 /* Ignore errors here, we're only reading anyway */
6275 g_input_stream_close_finish (stream, close_res, NULL);
6276 g_object_unref (stream);
6278 res = g_simple_async_result_new (G_OBJECT (data->file),
6281 g_file_load_contents_async);
6282 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)load_contents_data_free);
6283 g_simple_async_result_complete (res);
6284 g_object_unref (res);
6288 load_contents_fstat_callback (GObject *obj,
6289 GAsyncResult *stat_res,
6292 GInputStream *stream = G_INPUT_STREAM (obj);
6293 LoadContentsData *data = user_data;
6296 info = g_file_input_stream_query_info_finish (G_FILE_INPUT_STREAM (stream),
6300 data->etag = g_strdup (g_file_info_get_etag (info));
6301 g_object_unref (info);
6304 g_input_stream_close_async (stream, 0,
6306 load_contents_close_callback, data);
6310 load_contents_read_callback (GObject *obj,
6311 GAsyncResult *read_res,
6314 GInputStream *stream = G_INPUT_STREAM (obj);
6315 LoadContentsData *data = user_data;
6316 GError *error = NULL;
6319 read_size = g_input_stream_read_finish (stream, read_res, &error);
6323 /* Error or EOF, close the file */
6324 data->error = error;
6325 g_input_stream_close_async (stream, 0,
6327 load_contents_close_callback, data);
6329 else if (read_size == 0)
6331 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
6332 G_FILE_ATTRIBUTE_ETAG_VALUE,
6335 load_contents_fstat_callback,
6338 else if (read_size > 0)
6340 data->pos += read_size;
6342 g_byte_array_set_size (data->content,
6343 data->pos + GET_CONTENT_BLOCK_SIZE);
6346 if (data->read_more_callback &&
6347 !data->read_more_callback ((char *)data->content->data, data->pos, data->user_data))
6348 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
6349 G_FILE_ATTRIBUTE_ETAG_VALUE,
6352 load_contents_fstat_callback,
6355 g_input_stream_read_async (stream,
6356 data->content->data + data->pos,
6357 GET_CONTENT_BLOCK_SIZE,
6360 load_contents_read_callback,
6366 load_contents_open_callback (GObject *obj,
6367 GAsyncResult *open_res,
6370 GFile *file = G_FILE (obj);
6371 GFileInputStream *stream;
6372 LoadContentsData *data = user_data;
6373 GError *error = NULL;
6374 GSimpleAsyncResult *res;
6376 stream = g_file_read_finish (file, open_res, &error);
6380 g_byte_array_set_size (data->content,
6381 data->pos + GET_CONTENT_BLOCK_SIZE);
6382 g_input_stream_read_async (G_INPUT_STREAM (stream),
6383 data->content->data + data->pos,
6384 GET_CONTENT_BLOCK_SIZE,
6387 load_contents_read_callback,
6393 res = g_simple_async_result_new_take_error (G_OBJECT (data->file),
6397 g_simple_async_result_complete (res);
6398 load_contents_data_free (data);
6399 g_object_unref (res);
6404 * g_file_load_partial_contents_async: (skip)
6405 * @file: input #GFile.
6406 * @cancellable: optional #GCancellable object, %NULL to ignore.
6407 * @read_more_callback: a #GFileReadMoreCallback to receive partial data and to specify whether further data should be read.
6408 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6409 * @user_data: the data to pass to the callback functions.
6411 * Reads the partial contents of a file. A #GFileReadMoreCallback should be
6412 * used to stop reading from the file when appropriate, else this function
6413 * will behave exactly as g_file_load_contents_async(). This operation
6414 * can be finished by g_file_load_partial_contents_finish().
6416 * Users of this function should be aware that @user_data is passed to
6417 * both the @read_more_callback and the @callback.
6419 * If @cancellable is not %NULL, then the operation can be cancelled by
6420 * triggering the cancellable object from another thread. If the operation
6421 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6424 g_file_load_partial_contents_async (GFile *file,
6425 GCancellable *cancellable,
6426 GFileReadMoreCallback read_more_callback,
6427 GAsyncReadyCallback callback,
6430 LoadContentsData *data;
6432 g_return_if_fail (G_IS_FILE (file));
6434 data = g_new0 (LoadContentsData, 1);
6437 data->cancellable = g_object_ref (cancellable);
6438 data->read_more_callback = read_more_callback;
6439 data->callback = callback;
6440 data->user_data = user_data;
6441 data->content = g_byte_array_new ();
6442 data->file = g_object_ref (file);
6444 g_file_read_async (file,
6447 load_contents_open_callback,
6452 * g_file_load_partial_contents_finish:
6453 * @file: input #GFile.
6454 * @res: a #GAsyncResult.
6455 * @contents: (out) (transfer full) (element-type guint8) (array length=length): a location to place the contents of the file.
6456 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6457 * or %NULL if the length is not needed
6458 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6459 * or %NULL if the entity tag is not needed
6460 * @error: a #GError, or %NULL
6462 * Finishes an asynchronous partial load operation that was started
6463 * with g_file_load_partial_contents_async(). The data is always
6464 * zero-terminated, but this is not included in the resultant @length.
6465 * The returned @content should be freed with g_free() when no longer
6468 * Returns: %TRUE if the load was successful. If %FALSE and @error is
6469 * present, it will be set appropriately.
6472 g_file_load_partial_contents_finish (GFile *file,
6479 GSimpleAsyncResult *simple;
6480 LoadContentsData *data;
6482 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6483 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE);
6484 g_return_val_if_fail (contents != NULL, FALSE);
6486 simple = G_SIMPLE_ASYNC_RESULT (res);
6488 if (g_simple_async_result_propagate_error (simple, error))
6491 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_load_contents_async);
6493 data = g_simple_async_result_get_op_res_gpointer (simple);
6497 g_propagate_error (error, data->error);
6506 *length = data->pos;
6510 *etag_out = data->etag;
6514 /* Zero terminate */
6515 g_byte_array_set_size (data->content, data->pos + 1);
6516 data->content->data[data->pos] = 0;
6518 *contents = (char *)g_byte_array_free (data->content, FALSE);
6519 data->content = NULL;
6525 * g_file_load_contents_async:
6526 * @file: input #GFile.
6527 * @cancellable: optional #GCancellable object, %NULL to ignore.
6528 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6529 * @user_data: the data to pass to callback function
6531 * Starts an asynchronous load of the @file's contents.
6533 * For more details, see g_file_load_contents() which is
6534 * the synchronous version of this call.
6536 * When the load operation has completed, @callback will be called
6537 * with @user data. To finish the operation, call
6538 * g_file_load_contents_finish() with the #GAsyncResult returned by
6541 * If @cancellable is not %NULL, then the operation can be cancelled by
6542 * triggering the cancellable object from another thread. If the operation
6543 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6546 g_file_load_contents_async (GFile *file,
6547 GCancellable *cancellable,
6548 GAsyncReadyCallback callback,
6551 g_file_load_partial_contents_async (file,
6554 callback, user_data);
6558 * g_file_load_contents_finish:
6559 * @file: input #GFile.
6560 * @res: a #GAsyncResult.
6561 * @contents: (out) (transfer full) (element-type guint8) (array length=length): a location to place the contents of the file.
6562 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6563 * or %NULL if the length is not needed
6564 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6565 * or %NULL if the entity tag is not needed
6566 * @error: a #GError, or %NULL
6568 * Finishes an asynchronous load of the @file's contents.
6569 * The contents are placed in @contents, and @length is set to the
6570 * size of the @contents string. The @content should be freed with
6571 * g_free() when no longer needed. If @etag_out is present, it will be
6572 * set to the new entity tag for the @file.
6574 * Returns: %TRUE if the load was successful. If %FALSE and @error is
6575 * present, it will be set appropriately.
6578 g_file_load_contents_finish (GFile *file,
6585 return g_file_load_partial_contents_finish (file,
6594 * g_file_replace_contents:
6595 * @file: input #GFile.
6596 * @contents: (element-type guint8) (array length=length): a string containing the new contents for @file.
6597 * @length: the length of @contents in bytes.
6598 * @etag: (allow-none): the old <link linkend="gfile-etag">entity tag</link>
6599 * for the document, or %NULL
6600 * @make_backup: %TRUE if a backup should be created.
6601 * @flags: a set of #GFileCreateFlags.
6602 * @new_etag: (allow-none) (out): a location to a new <link linkend="gfile-etag">entity tag</link>
6603 * for the document. This should be freed with g_free() when no longer
6605 * @cancellable: optional #GCancellable object, %NULL to ignore.
6606 * @error: a #GError, or %NULL
6608 * Replaces the contents of @file with @contents of @length bytes.
6610 * If @etag is specified (not %NULL) any existing file must have that etag, or
6611 * the error %G_IO_ERROR_WRONG_ETAG will be returned.
6613 * If @make_backup is %TRUE, this function will attempt to make a backup of @file.
6615 * If @cancellable is not %NULL, then the operation can be cancelled by
6616 * triggering the cancellable object from another thread. If the operation
6617 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6619 * The returned @new_etag can be used to verify that the file hasn't changed the
6620 * next time it is saved over.
6622 * Returns: %TRUE if successful. If an error
6623 * has occurred, this function will return %FALSE and set @error
6624 * appropriately if present.
6627 g_file_replace_contents (GFile *file,
6628 const char *contents,
6631 gboolean make_backup,
6632 GFileCreateFlags flags,
6634 GCancellable *cancellable,
6637 GFileOutputStream *out;
6638 gsize pos, remainder;
6642 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6643 g_return_val_if_fail (contents != NULL, FALSE);
6645 out = g_file_replace (file, etag, make_backup, flags, cancellable, error);
6651 while (remainder > 0 &&
6652 (res = g_output_stream_write (G_OUTPUT_STREAM (out),
6654 MIN (remainder, GET_CONTENT_BLOCK_SIZE),
6662 if (remainder > 0 && res < 0)
6664 /* Ignore errors on close */
6665 g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, NULL);
6666 g_object_unref (out);
6668 /* error is set already */
6672 ret = g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, error);
6675 *new_etag = g_file_output_stream_get_etag (out);
6677 g_object_unref (out);
6685 GCancellable *cancellable;
6686 GAsyncReadyCallback callback;
6688 const char *content;
6692 } ReplaceContentsData;
6695 replace_contents_data_free (ReplaceContentsData *data)
6698 g_error_free (data->error);
6699 if (data->cancellable)
6700 g_object_unref (data->cancellable);
6701 g_object_unref (data->file);
6702 g_free (data->etag);
6707 replace_contents_close_callback (GObject *obj,
6708 GAsyncResult *close_res,
6711 GOutputStream *stream = G_OUTPUT_STREAM (obj);
6712 ReplaceContentsData *data = user_data;
6713 GSimpleAsyncResult *res;
6715 /* Ignore errors here, we're only reading anyway */
6716 g_output_stream_close_finish (stream, close_res, NULL);
6717 g_object_unref (stream);
6719 data->etag = g_file_output_stream_get_etag (G_FILE_OUTPUT_STREAM (stream));
6721 res = g_simple_async_result_new (G_OBJECT (data->file),
6724 g_file_replace_contents_async);
6725 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_contents_data_free);
6726 g_simple_async_result_complete (res);
6727 g_object_unref (res);
6731 replace_contents_write_callback (GObject *obj,
6732 GAsyncResult *read_res,
6735 GOutputStream *stream = G_OUTPUT_STREAM (obj);
6736 ReplaceContentsData *data = user_data;
6737 GError *error = NULL;
6740 write_size = g_output_stream_write_finish (stream, read_res, &error);
6742 if (write_size <= 0)
6744 /* Error or EOF, close the file */
6746 data->error = error;
6747 g_output_stream_close_async (stream, 0,
6749 replace_contents_close_callback, data);
6751 else if (write_size > 0)
6753 data->pos += write_size;
6755 if (data->pos >= data->length)
6756 g_output_stream_close_async (stream, 0,
6758 replace_contents_close_callback, data);
6760 g_output_stream_write_async (stream,
6761 data->content + data->pos,
6762 data->length - data->pos,
6765 replace_contents_write_callback,
6771 replace_contents_open_callback (GObject *obj,
6772 GAsyncResult *open_res,
6775 GFile *file = G_FILE (obj);
6776 GFileOutputStream *stream;
6777 ReplaceContentsData *data = user_data;
6778 GError *error = NULL;
6779 GSimpleAsyncResult *res;
6781 stream = g_file_replace_finish (file, open_res, &error);
6785 g_output_stream_write_async (G_OUTPUT_STREAM (stream),
6786 data->content + data->pos,
6787 data->length - data->pos,
6790 replace_contents_write_callback,
6796 res = g_simple_async_result_new_take_error (G_OBJECT (data->file),
6800 g_simple_async_result_complete (res);
6801 replace_contents_data_free (data);
6802 g_object_unref (res);
6807 * g_file_replace_contents_async:
6808 * @file: input #GFile.
6809 * @contents: (element-type guint8) (array length=length): string of contents to replace the file with.
6810 * @length: the length of @contents in bytes.
6811 * @etag: (allow-none): a new <link linkend="gfile-etag">entity tag</link> for the @file, or %NULL
6812 * @make_backup: %TRUE if a backup should be created.
6813 * @flags: a set of #GFileCreateFlags.
6814 * @cancellable: optional #GCancellable object, %NULL to ignore.
6815 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6816 * @user_data: the data to pass to callback function
6818 * Starts an asynchronous replacement of @file with the given
6819 * @contents of @length bytes. @etag will replace the document's
6820 * current entity tag.
6822 * When this operation has completed, @callback will be called with
6823 * @user_user data, and the operation can be finalized with
6824 * g_file_replace_contents_finish().
6826 * If @cancellable is not %NULL, then the operation can be cancelled by
6827 * triggering the cancellable object from another thread. If the operation
6828 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6830 * If @make_backup is %TRUE, this function will attempt to
6831 * make a backup of @file.
6834 g_file_replace_contents_async (GFile *file,
6835 const char *contents,
6838 gboolean make_backup,
6839 GFileCreateFlags flags,
6840 GCancellable *cancellable,
6841 GAsyncReadyCallback callback,
6844 ReplaceContentsData *data;
6846 g_return_if_fail (G_IS_FILE (file));
6847 g_return_if_fail (contents != NULL);
6849 data = g_new0 (ReplaceContentsData, 1);
6852 data->cancellable = g_object_ref (cancellable);
6853 data->callback = callback;
6854 data->user_data = user_data;
6855 data->content = contents;
6856 data->length = length;
6858 data->file = g_object_ref (file);
6860 g_file_replace_async (file,
6866 replace_contents_open_callback,
6871 * g_file_replace_contents_finish:
6872 * @file: input #GFile.
6873 * @res: a #GAsyncResult.
6874 * @new_etag: (out) (allow-none): a location of a new <link linkend="gfile-etag">entity tag</link>
6875 * for the document. This should be freed with g_free() when it is no
6876 * longer needed, or %NULL
6877 * @error: a #GError, or %NULL
6879 * Finishes an asynchronous replace of the given @file. See
6880 * g_file_replace_contents_async(). Sets @new_etag to the new entity
6881 * tag for the document, if present.
6883 * Returns: %TRUE on success, %FALSE on failure.
6886 g_file_replace_contents_finish (GFile *file,
6891 GSimpleAsyncResult *simple;
6892 ReplaceContentsData *data;
6894 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6895 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE);
6897 simple = G_SIMPLE_ASYNC_RESULT (res);
6899 if (g_simple_async_result_propagate_error (simple, error))
6902 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_replace_contents_async);
6904 data = g_simple_async_result_get_op_res_gpointer (simple);
6908 g_propagate_error (error, data->error);
6916 *new_etag = data->etag;
6917 data->etag = NULL; /* Take ownership */
6924 * g_file_start_mountable:
6925 * @file: input #GFile.
6926 * @flags: flags affecting the operation
6927 * @start_operation: (allow-none): a #GMountOperation, or %NULL to avoid user interaction.
6928 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
6929 * @callback: (allow-none): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
6930 * @user_data: the data to pass to callback function
6932 * Starts a file of type G_FILE_TYPE_MOUNTABLE.
6933 * Using @start_operation, you can request callbacks when, for instance,
6934 * passwords are needed during authentication.
6936 * If @cancellable is not %NULL, then the operation can be cancelled by
6937 * triggering the cancellable object from another thread. If the operation
6938 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6940 * When the operation is finished, @callback will be called. You can then call
6941 * g_file_mount_mountable_finish() to get the result of the operation.
6946 g_file_start_mountable (GFile *file,
6947 GDriveStartFlags flags,
6948 GMountOperation *start_operation,
6949 GCancellable *cancellable,
6950 GAsyncReadyCallback callback,
6955 g_return_if_fail (G_IS_FILE (file));
6957 iface = G_FILE_GET_IFACE (file);
6959 if (iface->start_mountable == NULL)
6961 g_simple_async_report_error_in_idle (G_OBJECT (file),
6965 G_IO_ERROR_NOT_SUPPORTED,
6966 _("Operation not supported"));
6970 (* iface->start_mountable) (file,
6979 * g_file_start_mountable_finish:
6980 * @file: input #GFile.
6981 * @result: a #GAsyncResult.
6982 * @error: a #GError, or %NULL
6984 * Finishes a start operation. See g_file_start_mountable() for details.
6986 * Finish an asynchronous start operation that was started
6987 * with g_file_start_mountable().
6989 * Returns: %TRUE if the operation finished successfully. %FALSE
6995 g_file_start_mountable_finish (GFile *file,
6996 GAsyncResult *result,
7001 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7002 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7004 if (g_async_result_legacy_propagate_error (result, error))
7007 iface = G_FILE_GET_IFACE (file);
7008 return (* iface->start_mountable_finish) (file, result, error);
7012 * g_file_stop_mountable:
7013 * @file: input #GFile.
7014 * @flags: flags affecting the operation
7015 * @mount_operation: (allow-none): a #GMountOperation, or %NULL to avoid user interaction.
7016 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
7017 * @callback: (allow-none): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
7018 * @user_data: the data to pass to callback function
7020 * Stops a file of type G_FILE_TYPE_MOUNTABLE.
7022 * If @cancellable is not %NULL, then the operation can be cancelled by
7023 * triggering the cancellable object from another thread. If the operation
7024 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7026 * When the operation is finished, @callback will be called. You can then call
7027 * g_file_stop_mountable_finish() to get the result of the operation.
7032 g_file_stop_mountable (GFile *file,
7033 GMountUnmountFlags flags,
7034 GMountOperation *mount_operation,
7035 GCancellable *cancellable,
7036 GAsyncReadyCallback callback,
7041 g_return_if_fail (G_IS_FILE (file));
7043 iface = G_FILE_GET_IFACE (file);
7045 if (iface->stop_mountable == NULL)
7047 g_simple_async_report_error_in_idle (G_OBJECT (file),
7051 G_IO_ERROR_NOT_SUPPORTED,
7052 _("Operation not supported"));
7056 (* iface->stop_mountable) (file,
7065 * g_file_stop_mountable_finish:
7066 * @file: input #GFile.
7067 * @result: a #GAsyncResult.
7068 * @error: a #GError, or %NULL
7070 * Finishes an stop operation, see g_file_stop_mountable() for details.
7072 * Finish an asynchronous stop operation that was started
7073 * with g_file_stop_mountable().
7075 * Returns: %TRUE if the operation finished successfully. %FALSE
7081 g_file_stop_mountable_finish (GFile *file,
7082 GAsyncResult *result,
7087 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7088 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7090 if (g_async_result_legacy_propagate_error (result, error))
7093 iface = G_FILE_GET_IFACE (file);
7094 return (* iface->stop_mountable_finish) (file, result, error);
7098 * g_file_poll_mountable:
7099 * @file: input #GFile.
7100 * @cancellable: optional #GCancellable object, %NULL to ignore.
7101 * @callback: (allow-none): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
7102 * @user_data: the data to pass to callback function
7104 * Polls a file of type G_FILE_TYPE_MOUNTABLE.
7106 * If @cancellable is not %NULL, then the operation can be cancelled by
7107 * triggering the cancellable object from another thread. If the operation
7108 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7110 * When the operation is finished, @callback will be called. You can then call
7111 * g_file_mount_mountable_finish() to get the result of the operation.
7116 g_file_poll_mountable (GFile *file,
7117 GCancellable *cancellable,
7118 GAsyncReadyCallback callback,
7123 g_return_if_fail (G_IS_FILE (file));
7125 iface = G_FILE_GET_IFACE (file);
7127 if (iface->poll_mountable == NULL)
7129 g_simple_async_report_error_in_idle (G_OBJECT (file),
7133 G_IO_ERROR_NOT_SUPPORTED,
7134 _("Operation not supported"));
7138 (* iface->poll_mountable) (file,
7145 * g_file_poll_mountable_finish:
7146 * @file: input #GFile.
7147 * @result: a #GAsyncResult.
7148 * @error: a #GError, or %NULL
7150 * Finishes a poll operation. See g_file_poll_mountable() for details.
7152 * Finish an asynchronous poll operation that was polled
7153 * with g_file_poll_mountable().
7155 * Returns: %TRUE if the operation finished successfully. %FALSE
7161 g_file_poll_mountable_finish (GFile *file,
7162 GAsyncResult *result,
7167 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7168 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7170 if (g_async_result_legacy_propagate_error (result, error))
7173 iface = G_FILE_GET_IFACE (file);
7174 return (* iface->poll_mountable_finish) (file, result, error);
7178 * g_file_supports_thread_contexts:
7181 * Checks if @file supports <link
7182 * linkend="g-main-context-push-thread-default-context">thread-default
7183 * contexts</link>. If this returns %FALSE, you cannot perform
7184 * asynchronous operations on @file in a thread that has a
7185 * thread-default context.
7187 * Returns: Whether or not @file supports thread-default contexts.
7192 g_file_supports_thread_contexts (GFile *file)
7196 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7198 iface = G_FILE_GET_IFACE (file);
7199 return iface->supports_thread_contexts;