1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2006-2007 Red Hat, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
22 * Author: Alexander Larsson <alexl@redhat.com>
34 #include <sys/types.h>
40 #include "gioscheduler.h"
41 #include "gsimpleasyncresult.h"
42 #include "gfileattribute-priv.h"
43 #include "gfiledescriptorbased.h"
44 #include "gpollfilemonitor.h"
46 #include "gfileinputstream.h"
47 #include "gfileoutputstream.h"
48 #include "gcancellable.h"
49 #include "gasyncresult.h"
56 * @short_description: File and Directory Handling
58 * @see_also: #GFileInfo, #GFileEnumerator
60 * #GFile is a high level abstraction for manipulating files on a
61 * virtual file system. #GFile<!-- -->s are lightweight, immutable
62 * objects that do no I/O upon creation. It is necessary to understand that
63 * #GFile objects do not represent files, merely an identifier for a file. All
64 * file content I/O is implemented as streaming operations (see #GInputStream and
67 * To construct a #GFile, you can use:
68 * g_file_new_for_path() if you have a path.
69 * g_file_new_for_uri() if you have a URI.
70 * g_file_new_for_commandline_arg() for a command line argument.
71 * g_file_parse_name() from a utf8 string gotten from g_file_get_parse_name().
73 * One way to think of a #GFile is as an abstraction of a pathname. For normal
74 * files the system pathname is what is stored internally, but as #GFile<!-- -->s
75 * are extensible it could also be something else that corresponds to a pathname
76 * in a userspace implementation of a filesystem.
78 * #GFile<!-- -->s make up hierarchies of directories and files that correspond to the
79 * files on a filesystem. You can move through the file system with #GFile using
80 * g_file_get_parent() to get an identifier for the parent directory, g_file_get_child()
81 * to get a child within a directory, g_file_resolve_relative_path() to resolve a relative
82 * path between two #GFile<!-- -->s. There can be multiple hierarchies, so you may not
83 * end up at the same root if you repeatedly call g_file_get_parent() on two different
86 * All #GFile<!-- -->s have a basename (get with g_file_get_basename()). These names
87 * are byte strings that are used to identify the file on the filesystem (relative to
88 * its parent directory) and there is no guarantees that they have any particular charset
89 * encoding or even make any sense at all. If you want to use filenames in a user
90 * interface you should use the display name that you can get by requesting the
91 * %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info().
92 * This is guaranteed to be in utf8 and can be used in a user interface. But always
93 * store the real basename or the #GFile to use to actually access the file, because
94 * there is no way to go from a display name to the actual name.
96 * Using #GFile as an identifier has the same weaknesses as using a path in that
97 * there may be multiple aliases for the same file. For instance, hard or
98 * soft links may cause two different #GFile<!-- -->s to refer to the same file.
99 * Other possible causes for aliases are: case insensitive filesystems, short
100 * and long names on Fat/NTFS, or bind mounts in Linux. If you want to check if
101 * two #GFile<!-- -->s point to the same file you can query for the
102 * %G_FILE_ATTRIBUTE_ID_FILE attribute. Note that #GFile does some trivial
103 * canonicalization of pathnames passed in, so that trivial differences in the
104 * path string used at creation (duplicated slashes, slash at end of path, "."
105 * or ".." path segments, etc) does not create different #GFile<!-- -->s.
107 * Many #GFile operations have both synchronous and asynchronous versions
108 * to suit your application. Asynchronous versions of synchronous functions
109 * simply have _async() appended to their function names. The asynchronous
110 * I/O functions call a #GAsyncReadyCallback which is then used to finalize
111 * the operation, producing a GAsyncResult which is then passed to the
112 * function's matching _finish() operation.
114 * Some #GFile operations do not have synchronous analogs, as they may
115 * take a very long time to finish, and blocking may leave an application
116 * unusable. Notable cases include:
117 * g_file_mount_mountable() to mount a mountable file.
118 * g_file_unmount_mountable_with_operation() to unmount a mountable file.
119 * g_file_eject_mountable_with_operation() to eject a mountable file.
121 * <para id="gfile-etag"><indexterm><primary>entity tag</primary></indexterm>
122 * One notable feature of #GFile<!-- -->s are entity tags, or "etags" for
123 * short. Entity tags are somewhat like a more abstract version of the
124 * traditional mtime, and can be used to quickly determine if the file has
125 * been modified from the version on the file system. See the HTTP 1.1
126 * <ulink url="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">specification</ulink>
127 * for HTTP Etag headers, which are a very similar concept.
131 static void g_file_real_query_info_async (GFile *file,
132 const char *attributes,
133 GFileQueryInfoFlags flags,
135 GCancellable *cancellable,
136 GAsyncReadyCallback callback,
138 static GFileInfo * g_file_real_query_info_finish (GFile *file,
141 static void g_file_real_query_filesystem_info_async (GFile *file,
142 const char *attributes,
144 GCancellable *cancellable,
145 GAsyncReadyCallback callback,
147 static GFileInfo * g_file_real_query_filesystem_info_finish (GFile *file,
150 static void g_file_real_enumerate_children_async (GFile *file,
151 const char *attributes,
152 GFileQueryInfoFlags flags,
154 GCancellable *cancellable,
155 GAsyncReadyCallback callback,
157 static GFileEnumerator * g_file_real_enumerate_children_finish (GFile *file,
160 static void g_file_real_read_async (GFile *file,
162 GCancellable *cancellable,
163 GAsyncReadyCallback callback,
165 static GFileInputStream * g_file_real_read_finish (GFile *file,
168 static void g_file_real_append_to_async (GFile *file,
169 GFileCreateFlags flags,
171 GCancellable *cancellable,
172 GAsyncReadyCallback callback,
174 static GFileOutputStream *g_file_real_append_to_finish (GFile *file,
177 static void g_file_real_create_async (GFile *file,
178 GFileCreateFlags flags,
180 GCancellable *cancellable,
181 GAsyncReadyCallback callback,
183 static GFileOutputStream *g_file_real_create_finish (GFile *file,
186 static void g_file_real_replace_async (GFile *file,
188 gboolean make_backup,
189 GFileCreateFlags flags,
191 GCancellable *cancellable,
192 GAsyncReadyCallback callback,
194 static GFileOutputStream *g_file_real_replace_finish (GFile *file,
197 static void g_file_real_open_readwrite_async (GFile *file,
199 GCancellable *cancellable,
200 GAsyncReadyCallback callback,
202 static GFileIOStream * g_file_real_open_readwrite_finish (GFile *file,
205 static void g_file_real_create_readwrite_async (GFile *file,
206 GFileCreateFlags flags,
208 GCancellable *cancellable,
209 GAsyncReadyCallback callback,
211 static GFileIOStream * g_file_real_create_readwrite_finish (GFile *file,
214 static void g_file_real_replace_readwrite_async (GFile *file,
216 gboolean make_backup,
217 GFileCreateFlags flags,
219 GCancellable *cancellable,
220 GAsyncReadyCallback callback,
222 static GFileIOStream * g_file_real_replace_readwrite_finish (GFile *file,
225 static gboolean g_file_real_set_attributes_from_info (GFile *file,
227 GFileQueryInfoFlags flags,
228 GCancellable *cancellable,
230 static void g_file_real_set_display_name_async (GFile *file,
231 const char *display_name,
233 GCancellable *cancellable,
234 GAsyncReadyCallback callback,
236 static GFile * g_file_real_set_display_name_finish (GFile *file,
239 static void g_file_real_set_attributes_async (GFile *file,
241 GFileQueryInfoFlags flags,
243 GCancellable *cancellable,
244 GAsyncReadyCallback callback,
246 static gboolean g_file_real_set_attributes_finish (GFile *file,
250 static void g_file_real_find_enclosing_mount_async (GFile *file,
252 GCancellable *cancellable,
253 GAsyncReadyCallback callback,
255 static GMount * g_file_real_find_enclosing_mount_finish (GFile *file,
258 static void g_file_real_copy_async (GFile *source,
260 GFileCopyFlags flags,
262 GCancellable *cancellable,
263 GFileProgressCallback progress_callback,
264 gpointer progress_callback_data,
265 GAsyncReadyCallback callback,
267 static gboolean g_file_real_copy_finish (GFile *file,
271 typedef GFileIface GFileInterface;
272 G_DEFINE_INTERFACE (GFile, g_file, G_TYPE_OBJECT)
275 g_file_default_init (GFileIface *iface)
277 iface->enumerate_children_async = g_file_real_enumerate_children_async;
278 iface->enumerate_children_finish = g_file_real_enumerate_children_finish;
279 iface->set_display_name_async = g_file_real_set_display_name_async;
280 iface->set_display_name_finish = g_file_real_set_display_name_finish;
281 iface->query_info_async = g_file_real_query_info_async;
282 iface->query_info_finish = g_file_real_query_info_finish;
283 iface->query_filesystem_info_async = g_file_real_query_filesystem_info_async;
284 iface->query_filesystem_info_finish = g_file_real_query_filesystem_info_finish;
285 iface->set_attributes_async = g_file_real_set_attributes_async;
286 iface->set_attributes_finish = g_file_real_set_attributes_finish;
287 iface->read_async = g_file_real_read_async;
288 iface->read_finish = g_file_real_read_finish;
289 iface->append_to_async = g_file_real_append_to_async;
290 iface->append_to_finish = g_file_real_append_to_finish;
291 iface->create_async = g_file_real_create_async;
292 iface->create_finish = g_file_real_create_finish;
293 iface->replace_async = g_file_real_replace_async;
294 iface->replace_finish = g_file_real_replace_finish;
295 iface->open_readwrite_async = g_file_real_open_readwrite_async;
296 iface->open_readwrite_finish = g_file_real_open_readwrite_finish;
297 iface->create_readwrite_async = g_file_real_create_readwrite_async;
298 iface->create_readwrite_finish = g_file_real_create_readwrite_finish;
299 iface->replace_readwrite_async = g_file_real_replace_readwrite_async;
300 iface->replace_readwrite_finish = g_file_real_replace_readwrite_finish;
301 iface->find_enclosing_mount_async = g_file_real_find_enclosing_mount_async;
302 iface->find_enclosing_mount_finish = g_file_real_find_enclosing_mount_finish;
303 iface->set_attributes_from_info = g_file_real_set_attributes_from_info;
304 iface->copy_async = g_file_real_copy_async;
305 iface->copy_finish = g_file_real_copy_finish;
311 * @file: input #GFile.
313 * Checks to see if a file is native to the platform.
315 * A native file s one expressed in the platform-native filename format,
316 * e.g. "C:\Windows" or "/usr/bin/". This does not mean the file is local,
317 * as it might be on a locally mounted remote filesystem.
319 * On some systems non-native files may be available using
320 * the native filesystem via a userspace filesystem (FUSE), in
321 * these cases this call will return %FALSE, but g_file_get_path()
322 * will still return a native path.
324 * This call does no blocking i/o.
326 * Returns: %TRUE if file is native.
329 g_file_is_native (GFile *file)
333 g_return_val_if_fail (G_IS_FILE (file), FALSE);
335 iface = G_FILE_GET_IFACE (file);
337 return (* iface->is_native) (file);
342 * g_file_has_uri_scheme:
343 * @file: input #GFile.
344 * @uri_scheme: a string containing a URI scheme.
346 * Checks to see if a #GFile has a given URI scheme.
348 * This call does no blocking i/o.
350 * Returns: %TRUE if #GFile's backend supports the
351 * given URI scheme, %FALSE if URI scheme is %NULL,
352 * not supported, or #GFile is invalid.
355 g_file_has_uri_scheme (GFile *file,
356 const char *uri_scheme)
360 g_return_val_if_fail (G_IS_FILE (file), FALSE);
361 g_return_val_if_fail (uri_scheme != NULL, FALSE);
363 iface = G_FILE_GET_IFACE (file);
365 return (* iface->has_uri_scheme) (file, uri_scheme);
370 * g_file_get_uri_scheme:
371 * @file: input #GFile.
373 * Gets the URI scheme for a #GFile.
374 * RFC 3986 decodes the scheme as:
376 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
378 * Common schemes include "file", "http", "ftp", etc.
380 * This call does no blocking i/o.
382 * Returns: a string containing the URI scheme for the given
383 * #GFile. The returned string should be freed with g_free()
384 * when no longer needed.
387 g_file_get_uri_scheme (GFile *file)
391 g_return_val_if_fail (G_IS_FILE (file), NULL);
393 iface = G_FILE_GET_IFACE (file);
395 return (* iface->get_uri_scheme) (file);
400 * g_file_get_basename:
401 * @file: input #GFile.
403 * Gets the base name (the last component of the path) for a given #GFile.
405 * If called for the top level of a system (such as the filesystem root
406 * or a uri like sftp://host/) it will return a single directory separator
407 * (and on Windows, possibly a drive letter).
409 * The base name is a byte string (*not* UTF-8). It has no defined encoding
410 * or rules other than it may not contain zero bytes. If you want to use
411 * filenames in a user interface you should use the display name that you
412 * can get by requesting the %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
413 * attribute with g_file_query_info().
415 * This call does no blocking i/o.
417 * Returns: string containing the #GFile's base name, or %NULL
418 * if given #GFile is invalid. The returned string should be
419 * freed with g_free() when no longer needed.
422 g_file_get_basename (GFile *file)
426 g_return_val_if_fail (G_IS_FILE (file), NULL);
428 iface = G_FILE_GET_IFACE (file);
430 return (* iface->get_basename) (file);
435 * @file: input #GFile.
437 * Gets the local pathname for #GFile, if one exists.
439 * This call does no blocking i/o.
441 * Returns: string containing the #GFile's path, or %NULL if
442 * no such path exists. The returned string should be
443 * freed with g_free() when no longer needed.
446 g_file_get_path (GFile *file)
450 g_return_val_if_fail (G_IS_FILE (file), NULL);
452 iface = G_FILE_GET_IFACE (file);
454 return (* iface->get_path) (file);
459 * @file: input #GFile.
461 * Gets the URI for the @file.
463 * This call does no blocking i/o.
465 * Returns: a string containing the #GFile's URI.
466 * The returned string should be freed with g_free() when no longer needed.
469 g_file_get_uri (GFile *file)
473 g_return_val_if_fail (G_IS_FILE (file), NULL);
475 iface = G_FILE_GET_IFACE (file);
477 return (* iface->get_uri) (file);
481 * g_file_get_parse_name:
482 * @file: input #GFile.
484 * Gets the parse name of the @file.
485 * A parse name is a UTF-8 string that describes the
486 * file such that one can get the #GFile back using
487 * g_file_parse_name().
489 * This is generally used to show the #GFile as a nice
490 * full-pathname kind of string in a user interface,
491 * like in a location entry.
493 * For local files with names that can safely be converted
494 * to UTF8 the pathname is used, otherwise the IRI is used
495 * (a form of URI that allows UTF8 characters unescaped).
497 * This call does no blocking i/o.
499 * Returns: a string containing the #GFile's parse name. The returned
500 * string should be freed with g_free() when no longer needed.
503 g_file_get_parse_name (GFile *file)
507 g_return_val_if_fail (G_IS_FILE (file), NULL);
509 iface = G_FILE_GET_IFACE (file);
511 return (* iface->get_parse_name) (file);
516 * @file: input #GFile.
518 * Duplicates a #GFile handle. This operation does not duplicate
519 * the actual file or directory represented by the #GFile; see
520 * g_file_copy() if attempting to copy a file.
522 * This call does no blocking i/o.
524 * Returns: (transfer full): a new #GFile that is a duplicate of the given #GFile.
527 g_file_dup (GFile *file)
531 g_return_val_if_fail (G_IS_FILE (file), NULL);
533 iface = G_FILE_GET_IFACE (file);
535 return (* iface->dup) (file);
540 * @file: #gconstpointer to a #GFile.
542 * Creates a hash value for a #GFile.
544 * This call does no blocking i/o.
547 * Returns: 0 if @file is not a valid #GFile, otherwise an
548 * integer that can be used as hash value for the #GFile.
549 * This function is intended for easily hashing a #GFile to
550 * add to a #GHashTable or similar data structure.
553 g_file_hash (gconstpointer file)
557 g_return_val_if_fail (G_IS_FILE (file), 0);
559 iface = G_FILE_GET_IFACE (file);
561 return (* iface->hash) ((GFile *)file);
566 * @file1: the first #GFile.
567 * @file2: the second #GFile.
569 * Checks equality of two given #GFile<!-- -->s. Note that two
570 * #GFile<!-- -->s that differ can still refer to the same
571 * file on the filesystem due to various forms of filename
574 * This call does no blocking i/o.
576 * Returns: %TRUE if @file1 and @file2 are equal.
577 * %FALSE if either is not a #GFile.
580 g_file_equal (GFile *file1,
585 g_return_val_if_fail (G_IS_FILE (file1), FALSE);
586 g_return_val_if_fail (G_IS_FILE (file2), FALSE);
588 if (G_TYPE_FROM_INSTANCE (file1) != G_TYPE_FROM_INSTANCE (file2))
591 iface = G_FILE_GET_IFACE (file1);
593 return (* iface->equal) (file1, file2);
599 * @file: input #GFile.
601 * Gets the parent directory for the @file.
602 * If the @file represents the root directory of the
603 * file system, then %NULL will be returned.
605 * This call does no blocking i/o.
607 * Returns: (transfer full): a #GFile structure to the parent of the given
608 * #GFile or %NULL if there is no parent.
609 * Free the returned object with g_object_unref().
612 g_file_get_parent (GFile *file)
616 g_return_val_if_fail (G_IS_FILE (file), NULL);
618 iface = G_FILE_GET_IFACE (file);
620 return (* iface->get_parent) (file);
625 * @file: input #GFile
626 * @parent: the parent to check for, or %NULL
628 * Checks if @file has a parent, and optionally, if it is @parent.
630 * If @parent is %NULL then this function returns %TRUE if @file has any
631 * parent at all. If @parent is non-%NULL then %TRUE is only returned
632 * if @file is a child of @parent.
634 * Returns: %TRUE if @file is a child of @parent (or any parent in the
635 * case that @parent is %NULL).
640 g_file_has_parent (GFile *file,
643 GFile *actual_parent;
646 g_return_val_if_fail (G_IS_FILE (file), FALSE);
647 g_return_val_if_fail (parent == NULL || G_IS_FILE (parent), FALSE);
649 actual_parent = g_file_get_parent (file);
651 if (actual_parent != NULL)
654 result = g_file_equal (parent, actual_parent);
658 g_object_unref (actual_parent);
668 * @file: input #GFile.
669 * @name: string containing the child's basename.
671 * Gets a child of @file with basename equal to @name.
673 * Note that the file with that specific name might not exist, but
674 * you can still have a #GFile that points to it. You can use this
675 * for instance to create that file.
677 * This call does no blocking i/o.
679 * Returns: (transfer full): a #GFile to a child specified by @name.
680 * Free the returned object with g_object_unref().
683 g_file_get_child (GFile *file,
686 g_return_val_if_fail (G_IS_FILE (file), NULL);
687 g_return_val_if_fail (name != NULL, NULL);
689 return g_file_resolve_relative_path (file, name);
693 * g_file_get_child_for_display_name:
694 * @file: input #GFile.
695 * @display_name: string to a possible child.
698 * Gets the child of @file for a given @display_name (i.e. a UTF8
699 * version of the name). If this function fails, it returns %NULL and @error will be
700 * set. This is very useful when constructing a GFile for a new file
701 * and the user entered the filename in the user interface, for instance
702 * when you select a directory and type a filename in the file selector.
704 * This call does no blocking i/o.
706 * Returns: (transfer full): a #GFile to the specified child, or
707 * %NULL if the display name couldn't be converted.
708 * Free the returned object with g_object_unref().
711 g_file_get_child_for_display_name (GFile *file,
712 const char *display_name,
717 g_return_val_if_fail (G_IS_FILE (file), NULL);
718 g_return_val_if_fail (display_name != NULL, NULL);
720 iface = G_FILE_GET_IFACE (file);
722 return (* iface->get_child_for_display_name) (file, display_name, error);
727 * @file: input #GFile.
728 * @prefix: input #GFile.
730 * Checks whether @file has the prefix specified by @prefix. In other word,
731 * if the names of inital elements of @file<!-- -->s pathname match @prefix.
732 * Only full pathname elements are matched, so a path like /foo is not
733 * considered a prefix of /foobar, only of /foo/bar.
735 * This call does no i/o, as it works purely on names. As such it can
736 * sometimes return %FALSE even if @file is inside a @prefix (from a
737 * filesystem point of view), because the prefix of @file is an alias
740 * Virtual: prefix_matches
741 * Returns: %TRUE if the @files's parent, grandparent, etc is @prefix.
745 g_file_has_prefix (GFile *file,
750 g_return_val_if_fail (G_IS_FILE (file), FALSE);
751 g_return_val_if_fail (G_IS_FILE (prefix), FALSE);
753 if (G_TYPE_FROM_INSTANCE (file) != G_TYPE_FROM_INSTANCE (prefix))
756 iface = G_FILE_GET_IFACE (file);
758 /* The vtable function differs in arg order since we're
759 using the old contains_file call */
760 return (* iface->prefix_matches) (prefix, file);
764 * g_file_get_relative_path:
765 * @parent: input #GFile.
766 * @descendant: input #GFile.
768 * Gets the path for @descendant relative to @parent.
770 * This call does no blocking i/o.
772 * Returns: string with the relative path from @descendant
773 * to @parent, or %NULL if @descendant doesn't have @parent as prefix.
774 * The returned string should be freed with g_free() when no longer needed.
777 g_file_get_relative_path (GFile *parent,
782 g_return_val_if_fail (G_IS_FILE (parent), NULL);
783 g_return_val_if_fail (G_IS_FILE (descendant), NULL);
785 if (G_TYPE_FROM_INSTANCE (parent) != G_TYPE_FROM_INSTANCE (descendant))
788 iface = G_FILE_GET_IFACE (parent);
790 return (* iface->get_relative_path) (parent, descendant);
794 * g_file_resolve_relative_path:
795 * @file: input #GFile.
796 * @relative_path: a given relative path string.
798 * Resolves a relative path for @file to an absolute path.
800 * This call does no blocking i/o.
802 * Returns: (transfer full): #GFile to the resolved path. %NULL if @relative_path
803 * is %NULL or if @file is invalid.
804 * Free the returned object with g_object_unref().
807 g_file_resolve_relative_path (GFile *file,
808 const char *relative_path)
812 g_return_val_if_fail (G_IS_FILE (file), NULL);
813 g_return_val_if_fail (relative_path != NULL, NULL);
815 iface = G_FILE_GET_IFACE (file);
817 return (* iface->resolve_relative_path) (file, relative_path);
821 * g_file_enumerate_children:
822 * @file: input #GFile.
823 * @attributes: an attribute query string.
824 * @flags: a set of #GFileQueryInfoFlags.
825 * @cancellable: optional #GCancellable object, %NULL to ignore.
826 * @error: #GError for error reporting.
828 * Gets the requested information about the files in a directory. The result
829 * is a #GFileEnumerator object that will give out #GFileInfo objects for
830 * all the files in the directory.
832 * The @attributes value is a string that specifies the file attributes that
833 * should be gathered. It is not an error if it's not possible to read a particular
834 * requested attribute from a file - it just won't be set. @attributes should
835 * be a comma-separated list of attributes or attribute wildcards. The wildcard "*"
836 * means all attributes, and a wildcard like "standard::*" means all attributes in the standard
837 * namespace. An example attribute query be "standard::*,owner::user".
838 * The standard attributes are available as defines, like #G_FILE_ATTRIBUTE_STANDARD_NAME.
840 * If @cancellable is not %NULL, then the operation can be cancelled by
841 * triggering the cancellable object from another thread. If the operation
842 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
844 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
845 * If the file is not a directory, the G_FILE_ERROR_NOTDIR error will be returned.
846 * Other errors are possible too.
848 * Returns: (transfer full): A #GFileEnumerator if successful, %NULL on error.
849 * Free the returned object with g_object_unref().
852 g_file_enumerate_children (GFile *file,
853 const char *attributes,
854 GFileQueryInfoFlags flags,
855 GCancellable *cancellable,
861 g_return_val_if_fail (G_IS_FILE (file), NULL);
863 if (g_cancellable_set_error_if_cancelled (cancellable, error))
866 iface = G_FILE_GET_IFACE (file);
868 if (iface->enumerate_children == NULL)
870 g_set_error_literal (error, G_IO_ERROR,
871 G_IO_ERROR_NOT_SUPPORTED,
872 _("Operation not supported"));
876 return (* iface->enumerate_children) (file, attributes, flags,
881 * g_file_enumerate_children_async:
882 * @file: input #GFile.
883 * @attributes: an attribute query string.
884 * @flags: a set of #GFileQueryInfoFlags.
885 * @io_priority: the <link linkend="io-priority">I/O priority</link>
887 * @cancellable: optional #GCancellable object, %NULL to ignore.
888 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
889 * @user_data: the data to pass to callback function
891 * Asynchronously gets the requested information about the files in a directory. The result
892 * is a #GFileEnumerator object that will give out #GFileInfo objects for
893 * all the files in the directory.
895 * For more details, see g_file_enumerate_children() which is
896 * the synchronous version of this call.
898 * When the operation is finished, @callback will be called. You can then call
899 * g_file_enumerate_children_finish() to get the result of the operation.
902 g_file_enumerate_children_async (GFile *file,
903 const char *attributes,
904 GFileQueryInfoFlags flags,
906 GCancellable *cancellable,
907 GAsyncReadyCallback callback,
912 g_return_if_fail (G_IS_FILE (file));
914 iface = G_FILE_GET_IFACE (file);
915 (* iface->enumerate_children_async) (file,
925 * g_file_enumerate_children_finish:
926 * @file: input #GFile.
927 * @res: a #GAsyncResult.
930 * Finishes an async enumerate children operation.
931 * See g_file_enumerate_children_async().
933 * Returns: (transfer full): a #GFileEnumerator or %NULL if an error occurred.
934 * Free the returned object with g_object_unref().
937 g_file_enumerate_children_finish (GFile *file,
943 g_return_val_if_fail (G_IS_FILE (file), NULL);
944 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
946 if (G_IS_SIMPLE_ASYNC_RESULT (res))
948 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
949 if (g_simple_async_result_propagate_error (simple, error))
953 iface = G_FILE_GET_IFACE (file);
954 return (* iface->enumerate_children_finish) (file, res, error);
958 * g_file_query_exists:
959 * @file: input #GFile.
960 * @cancellable: optional #GCancellable object, %NULL to ignore.
962 * Utility function to check if a particular file exists. This is
963 * implemented using g_file_query_info() and as such does blocking I/O.
965 * Note that in many cases it is racy to first check for file existence
966 * and then execute something based on the outcome of that, because the
967 * file might have been created or removed in between the operations. The
968 * general approach to handling that is to not check, but just do the
969 * operation and handle the errors as they come.
971 * As an example of race-free checking, take the case of reading a file, and
972 * if it doesn't exist, creating it. There are two racy versions: read it, and
973 * on error create it; and: check if it exists, if not create it. These
974 * can both result in two processes creating the file (with perhaps a partially
975 * written file as the result). The correct approach is to always try to create
976 * the file with g_file_create() which will either atomically create the file
977 * or fail with a G_IO_ERROR_EXISTS error.
979 * However, in many cases an existence check is useful in a user
980 * interface, for instance to make a menu item sensitive/insensitive, so that
981 * you don't have to fool users that something is possible and then just show
982 * and error dialog. If you do this, you should make sure to also handle the
983 * errors that can happen due to races when you execute the operation.
985 * Returns: %TRUE if the file exists (and can be detected without error), %FALSE otherwise (or if cancelled).
988 g_file_query_exists (GFile *file,
989 GCancellable *cancellable)
993 g_return_val_if_fail (G_IS_FILE(file), FALSE);
995 info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE,
996 G_FILE_QUERY_INFO_NONE, cancellable, NULL);
999 g_object_unref (info);
1007 * g_file_query_file_type:
1008 * @file: input #GFile.
1009 * @flags: a set of #GFileQueryInfoFlags passed to g_file_query_info().
1010 * @cancellable: optional #GCancellable object, %NULL to ignore.
1012 * Utility function to inspect the #GFileType of a file. This is
1013 * implemented using g_file_query_info() and as such does blocking I/O.
1015 * The primary use case of this method is to check if a file is a regular file,
1016 * directory, or symlink.
1018 * Returns: The #GFileType of the file and #G_FILE_TYPE_UNKNOWN if the file
1024 g_file_query_file_type (GFile *file,
1025 GFileQueryInfoFlags flags,
1026 GCancellable *cancellable)
1029 GFileType file_type;
1031 g_return_val_if_fail (G_IS_FILE(file), G_FILE_TYPE_UNKNOWN);
1032 info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, flags,
1036 file_type = g_file_info_get_file_type (info);
1037 g_object_unref (info);
1040 file_type = G_FILE_TYPE_UNKNOWN;
1046 * g_file_query_info:
1047 * @file: input #GFile.
1048 * @attributes: an attribute query string.
1049 * @flags: a set of #GFileQueryInfoFlags.
1050 * @cancellable: optional #GCancellable object, %NULL to ignore.
1051 * @error: a #GError.
1053 * Gets the requested information about specified @file. The result
1054 * is a #GFileInfo object that contains key-value attributes (such as
1055 * the type or size of the file).
1057 * The @attributes value is a string that specifies the file attributes that
1058 * should be gathered. It is not an error if it's not possible to read a particular
1059 * requested attribute from a file - it just won't be set. @attributes should
1060 * be a comma-separated list of attributes or attribute wildcards. The wildcard "*"
1061 * means all attributes, and a wildcard like "standard::*" means all attributes in the standard
1062 * namespace. An example attribute query be "standard::*,owner::user".
1063 * The standard attributes are available as defines, like #G_FILE_ATTRIBUTE_STANDARD_NAME.
1065 * If @cancellable is not %NULL, then the operation can be cancelled by
1066 * triggering the cancellable object from another thread. If the operation
1067 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1069 * For symlinks, normally the information about the target of the
1070 * symlink is returned, rather than information about the symlink itself.
1071 * However if you pass #G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS in @flags the
1072 * information about the symlink itself will be returned. Also, for symlinks
1073 * that point to non-existing files the information about the symlink itself
1076 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1077 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1079 * Returns: (transfer full): a #GFileInfo for the given @file, or %NULL on error.
1080 * Free the returned object with g_object_unref().
1083 g_file_query_info (GFile *file,
1084 const char *attributes,
1085 GFileQueryInfoFlags flags,
1086 GCancellable *cancellable,
1091 g_return_val_if_fail (G_IS_FILE (file), NULL);
1093 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1096 iface = G_FILE_GET_IFACE (file);
1098 if (iface->query_info == NULL)
1100 g_set_error_literal (error, G_IO_ERROR,
1101 G_IO_ERROR_NOT_SUPPORTED,
1102 _("Operation not supported"));
1106 return (* iface->query_info) (file, attributes, flags, cancellable, error);
1110 * g_file_query_info_async:
1111 * @file: input #GFile.
1112 * @attributes: an attribute query string.
1113 * @flags: a set of #GFileQueryInfoFlags.
1114 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1116 * @cancellable: optional #GCancellable object, %NULL to ignore.
1117 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1118 * @user_data: the data to pass to callback function
1120 * Asynchronously gets the requested information about specified @file. The result
1121 * is a #GFileInfo object that contains key-value attributes (such as type or size
1124 * For more details, see g_file_query_info() which is
1125 * the synchronous version of this call.
1127 * When the operation is finished, @callback will be called. You can then call
1128 * g_file_query_info_finish() to get the result of the operation.
1131 g_file_query_info_async (GFile *file,
1132 const char *attributes,
1133 GFileQueryInfoFlags flags,
1135 GCancellable *cancellable,
1136 GAsyncReadyCallback callback,
1141 g_return_if_fail (G_IS_FILE (file));
1143 iface = G_FILE_GET_IFACE (file);
1144 (* iface->query_info_async) (file,
1154 * g_file_query_info_finish:
1155 * @file: input #GFile.
1156 * @res: a #GAsyncResult.
1157 * @error: a #GError.
1159 * Finishes an asynchronous file info query.
1160 * See g_file_query_info_async().
1162 * Returns: (transfer full): #GFileInfo for given @file or %NULL on error.
1163 * Free the returned object with g_object_unref().
1166 g_file_query_info_finish (GFile *file,
1172 g_return_val_if_fail (G_IS_FILE (file), NULL);
1173 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1175 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1177 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1178 if (g_simple_async_result_propagate_error (simple, error))
1182 iface = G_FILE_GET_IFACE (file);
1183 return (* iface->query_info_finish) (file, res, error);
1187 * g_file_query_filesystem_info:
1188 * @file: input #GFile.
1189 * @attributes: an attribute query string.
1190 * @cancellable: optional #GCancellable object, %NULL to ignore.
1191 * @error: a #GError.
1193 * Similar to g_file_query_info(), but obtains information
1194 * about the filesystem the @file is on, rather than the file itself.
1195 * For instance the amount of space available and the type of
1198 * The @attributes value is a string that specifies the file attributes that
1199 * should be gathered. It is not an error if it's not possible to read a particular
1200 * requested attribute from a file - it just won't be set. @attributes should
1201 * be a comma-separated list of attributes or attribute wildcards. The wildcard "*"
1202 * means all attributes, and a wildcard like "fs:*" means all attributes in the fs
1203 * namespace. The standard namespace for filesystem attributes is "fs".
1204 * Common attributes of interest are #G_FILE_ATTRIBUTE_FILESYSTEM_SIZE
1205 * (the total size of the filesystem in bytes), #G_FILE_ATTRIBUTE_FILESYSTEM_FREE (number of
1206 * bytes available), and #G_FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).
1208 * If @cancellable is not %NULL, then the operation can be cancelled by
1209 * triggering the cancellable object from another thread. If the operation
1210 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1212 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1213 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1215 * Returns: (transfer full): a #GFileInfo or %NULL if there was an error.
1216 * Free the returned object with g_object_unref().
1219 g_file_query_filesystem_info (GFile *file,
1220 const char *attributes,
1221 GCancellable *cancellable,
1226 g_return_val_if_fail (G_IS_FILE (file), NULL);
1228 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1231 iface = G_FILE_GET_IFACE (file);
1233 if (iface->query_filesystem_info == NULL)
1235 g_set_error_literal (error, G_IO_ERROR,
1236 G_IO_ERROR_NOT_SUPPORTED,
1237 _("Operation not supported"));
1241 return (* iface->query_filesystem_info) (file, attributes, cancellable, error);
1245 * g_file_query_filesystem_info_async:
1246 * @file: input #GFile.
1247 * @attributes: an attribute query string.
1248 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1250 * @cancellable: optional #GCancellable object, %NULL to ignore.
1251 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1252 * @user_data: the data to pass to callback function
1254 * Asynchronously gets the requested information about the filesystem
1255 * that the specified @file is on. The result is a #GFileInfo object
1256 * that contains key-value attributes (such as type or size for the
1259 * For more details, see g_file_query_filesystem_info() which is the
1260 * synchronous version of this call.
1262 * When the operation is finished, @callback will be called. You can
1263 * then call g_file_query_info_finish() to get the result of the
1267 g_file_query_filesystem_info_async (GFile *file,
1268 const char *attributes,
1270 GCancellable *cancellable,
1271 GAsyncReadyCallback callback,
1276 g_return_if_fail (G_IS_FILE (file));
1278 iface = G_FILE_GET_IFACE (file);
1279 (* iface->query_filesystem_info_async) (file,
1288 * g_file_query_filesystem_info_finish:
1289 * @file: input #GFile.
1290 * @res: a #GAsyncResult.
1291 * @error: a #GError.
1293 * Finishes an asynchronous filesystem info query. See
1294 * g_file_query_filesystem_info_async().
1296 * Returns: (transfer full): #GFileInfo for given @file or %NULL on error.
1297 * Free the returned object with g_object_unref().
1300 g_file_query_filesystem_info_finish (GFile *file,
1306 g_return_val_if_fail (G_IS_FILE (file), NULL);
1307 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1309 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1311 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1312 if (g_simple_async_result_propagate_error (simple, error))
1316 iface = G_FILE_GET_IFACE (file);
1317 return (* iface->query_filesystem_info_finish) (file, res, error);
1321 * g_file_find_enclosing_mount:
1322 * @file: input #GFile.
1323 * @cancellable: optional #GCancellable object, %NULL to ignore.
1324 * @error: a #GError.
1326 * Gets a #GMount for the #GFile.
1328 * If the #GFileIface for @file does not have a mount (e.g. possibly a
1329 * remote share), @error will be set to %G_IO_ERROR_NOT_FOUND and %NULL
1332 * If @cancellable is not %NULL, then the operation can be cancelled by
1333 * triggering the cancellable object from another thread. If the operation
1334 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1336 * Returns: (transfer full): a #GMount where the @file is located or %NULL on error.
1337 * Free the returned object with g_object_unref().
1340 g_file_find_enclosing_mount (GFile *file,
1341 GCancellable *cancellable,
1346 g_return_val_if_fail (G_IS_FILE (file), NULL);
1348 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1351 iface = G_FILE_GET_IFACE (file);
1352 if (iface->find_enclosing_mount == NULL)
1355 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1356 /* Translators: This is an error message when trying to find the
1357 * enclosing (user visible) mount of a file, but none exists. */
1358 _("Containing mount does not exist"));
1362 return (* iface->find_enclosing_mount) (file, cancellable, error);
1366 * g_file_find_enclosing_mount_async:
1368 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1370 * @cancellable: optional #GCancellable object, %NULL to ignore.
1371 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1372 * @user_data: the data to pass to callback function
1374 * Asynchronously gets the mount for the file.
1376 * For more details, see g_file_find_enclosing_mount() which is
1377 * the synchronous version of this call.
1379 * When the operation is finished, @callback will be called. You can then call
1380 * g_file_find_enclosing_mount_finish() to get the result of the operation.
1383 g_file_find_enclosing_mount_async (GFile *file,
1385 GCancellable *cancellable,
1386 GAsyncReadyCallback callback,
1391 g_return_if_fail (G_IS_FILE (file));
1393 iface = G_FILE_GET_IFACE (file);
1394 (* iface->find_enclosing_mount_async) (file,
1402 * g_file_find_enclosing_mount_finish:
1404 * @res: a #GAsyncResult
1407 * Finishes an asynchronous find mount request.
1408 * See g_file_find_enclosing_mount_async().
1410 * Returns: (transfer full): #GMount for given @file or %NULL on error.
1411 * Free the returned object with g_object_unref().
1414 g_file_find_enclosing_mount_finish (GFile *file,
1420 g_return_val_if_fail (G_IS_FILE (file), NULL);
1421 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1423 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1425 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1426 if (g_simple_async_result_propagate_error (simple, error))
1430 iface = G_FILE_GET_IFACE (file);
1431 return (* iface->find_enclosing_mount_finish) (file, res, error);
1437 * @file: #GFile to read.
1438 * @cancellable: a #GCancellable
1439 * @error: a #GError, or %NULL
1441 * Opens a file for reading. The result is a #GFileInputStream that
1442 * can be used to read the contents of the file.
1444 * If @cancellable is not %NULL, then the operation can be cancelled by
1445 * triggering the cancellable object from another thread. If the operation
1446 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1448 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1449 * If the file is a directory, the G_IO_ERROR_IS_DIRECTORY error will be returned.
1450 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1453 * Returns: (transfer full): #GFileInputStream or %NULL on error.
1454 * Free the returned object with g_object_unref().
1457 g_file_read (GFile *file,
1458 GCancellable *cancellable,
1463 g_return_val_if_fail (G_IS_FILE (file), NULL);
1465 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1468 iface = G_FILE_GET_IFACE (file);
1470 if (iface->read_fn == NULL)
1472 g_set_error_literal (error, G_IO_ERROR,
1473 G_IO_ERROR_NOT_SUPPORTED,
1474 _("Operation not supported"));
1478 return (* iface->read_fn) (file, cancellable, error);
1483 * @file: input #GFile.
1484 * @flags: a set of #GFileCreateFlags.
1485 * @cancellable: optional #GCancellable object, %NULL to ignore.
1486 * @error: a #GError, or %NULL
1488 * Gets an output stream for appending data to the file. If
1489 * the file doesn't already exist it is created.
1491 * By default files created are generally readable by everyone,
1492 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1493 * will be made readable only to the current user, to the level that
1494 * is supported on the target filesystem.
1496 * If @cancellable is not %NULL, then the operation can be cancelled by
1497 * triggering the cancellable object from another thread. If the operation
1498 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1500 * Some file systems don't allow all file names, and may
1501 * return an %G_IO_ERROR_INVALID_FILENAME error.
1502 * If the file is a directory the %G_IO_ERROR_IS_DIRECTORY error will be
1503 * returned. Other errors are possible too, and depend on what kind of
1504 * filesystem the file is on.
1506 * Returns: (transfer full): a #GFileOutputStream, or %NULL on error.
1507 * Free the returned object with g_object_unref().
1510 g_file_append_to (GFile *file,
1511 GFileCreateFlags flags,
1512 GCancellable *cancellable,
1517 g_return_val_if_fail (G_IS_FILE (file), NULL);
1519 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1522 iface = G_FILE_GET_IFACE (file);
1524 if (iface->append_to == NULL)
1526 g_set_error_literal (error, G_IO_ERROR,
1527 G_IO_ERROR_NOT_SUPPORTED,
1528 _("Operation not supported"));
1532 return (* iface->append_to) (file, flags, cancellable, error);
1537 * @file: input #GFile.
1538 * @flags: a set of #GFileCreateFlags.
1539 * @cancellable: optional #GCancellable object, %NULL to ignore.
1540 * @error: a #GError, or %NULL
1542 * Creates a new file and returns an output stream for writing to it.
1543 * The file must not already exist.
1545 * By default files created are generally readable by everyone,
1546 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1547 * will be made readable only to the current user, to the level that
1548 * is supported on the target filesystem.
1550 * If @cancellable is not %NULL, then the operation can be cancelled by
1551 * triggering the cancellable object from another thread. If the operation
1552 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1554 * If a file or directory with this name already exists the G_IO_ERROR_EXISTS
1555 * error will be returned.
1556 * Some file systems don't allow all file names, and may
1557 * return an G_IO_ERROR_INVALID_FILENAME error, and if the name
1558 * is to long G_IO_ERROR_FILENAME_TOO_LONG will be returned.
1559 * Other errors are possible too, and depend on what kind of
1560 * filesystem the file is on.
1562 * Returns: (transfer full): a #GFileOutputStream for the newly created file, or
1564 * Free the returned object with g_object_unref().
1567 g_file_create (GFile *file,
1568 GFileCreateFlags flags,
1569 GCancellable *cancellable,
1574 g_return_val_if_fail (G_IS_FILE (file), NULL);
1576 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1579 iface = G_FILE_GET_IFACE (file);
1581 if (iface->create == NULL)
1583 g_set_error_literal (error, G_IO_ERROR,
1584 G_IO_ERROR_NOT_SUPPORTED,
1585 _("Operation not supported"));
1589 return (* iface->create) (file, flags, cancellable, error);
1594 * @file: input #GFile.
1595 * @etag: (allow-none): an optional <link linkend="gfile-etag">entity tag</link> for the
1596 * current #GFile, or #NULL to ignore.
1597 * @make_backup: %TRUE if a backup should be created.
1598 * @flags: a set of #GFileCreateFlags.
1599 * @cancellable: optional #GCancellable object, %NULL to ignore.
1600 * @error: a #GError, or %NULL
1602 * Returns an output stream for overwriting the file, possibly
1603 * creating a backup copy of the file first. If the file doesn't exist,
1604 * it will be created.
1606 * This will try to replace the file in the safest way possible so
1607 * that any errors during the writing will not affect an already
1608 * existing copy of the file. For instance, for local files it
1609 * may write to a temporary file and then atomically rename over
1610 * the destination when the stream is closed.
1612 * By default files created are generally readable by everyone,
1613 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1614 * will be made readable only to the current user, to the level that
1615 * is supported on the target filesystem.
1617 * If @cancellable is not %NULL, then the operation can be cancelled by
1618 * triggering the cancellable object from another thread. If the operation
1619 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1621 * If you pass in a non-#NULL @etag value, then this value is
1622 * compared to the current entity tag of the file, and if they differ
1623 * an G_IO_ERROR_WRONG_ETAG error is returned. This generally means
1624 * that the file has been changed since you last read it. You can get
1625 * the new etag from g_file_output_stream_get_etag() after you've
1626 * finished writing and closed the #GFileOutputStream. When you load
1627 * a new file you can use g_file_input_stream_query_info() to get
1628 * the etag of the file.
1630 * If @make_backup is %TRUE, this function will attempt to make a backup
1631 * of the current file before overwriting it. If this fails a G_IO_ERROR_CANT_CREATE_BACKUP
1632 * error will be returned. If you want to replace anyway, try again with
1633 * @make_backup set to %FALSE.
1635 * If the file is a directory the G_IO_ERROR_IS_DIRECTORY error will be returned,
1636 * and if the file is some other form of non-regular file then a
1637 * G_IO_ERROR_NOT_REGULAR_FILE error will be returned.
1638 * Some file systems don't allow all file names, and may
1639 * return an G_IO_ERROR_INVALID_FILENAME error, and if the name
1640 * is to long G_IO_ERROR_FILENAME_TOO_LONG will be returned.
1641 * Other errors are possible too, and depend on what kind of
1642 * filesystem the file is on.
1644 * Returns: (transfer full): a #GFileOutputStream or %NULL on error.
1645 * Free the returned object with g_object_unref().
1648 g_file_replace (GFile *file,
1650 gboolean make_backup,
1651 GFileCreateFlags flags,
1652 GCancellable *cancellable,
1657 g_return_val_if_fail (G_IS_FILE (file), NULL);
1659 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1662 iface = G_FILE_GET_IFACE (file);
1664 if (iface->replace == NULL)
1666 g_set_error_literal (error, G_IO_ERROR,
1667 G_IO_ERROR_NOT_SUPPORTED,
1668 _("Operation not supported"));
1673 /* Handle empty tag string as NULL in consistent way. */
1674 if (etag && *etag == 0)
1677 return (* iface->replace) (file, etag, make_backup, flags, cancellable, error);
1681 * g_file_open_readwrite:
1682 * @file: #GFile to open
1683 * @cancellable: a #GCancellable
1684 * @error: a #GError, or %NULL
1686 * Opens an existing file for reading and writing. The result is
1687 * a #GFileIOStream that can be used to read and write the contents of the file.
1689 * If @cancellable is not %NULL, then the operation can be cancelled by
1690 * triggering the cancellable object from another thread. If the operation
1691 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1693 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1694 * If the file is a directory, the G_IO_ERROR_IS_DIRECTORY error will be returned.
1695 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1696 * Note that in many non-local file cases read and write streams are not supported,
1697 * so make sure you really need to do read and write streaming, rather than
1698 * just opening for reading or writing.
1700 * Returns: (transfer full): #GFileIOStream or %NULL on error.
1701 * Free the returned object with g_object_unref().
1706 g_file_open_readwrite (GFile *file,
1707 GCancellable *cancellable,
1712 g_return_val_if_fail (G_IS_FILE (file), NULL);
1714 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1717 iface = G_FILE_GET_IFACE (file);
1719 if (iface->open_readwrite == NULL)
1721 g_set_error_literal (error, G_IO_ERROR,
1722 G_IO_ERROR_NOT_SUPPORTED,
1723 _("Operation not supported"));
1727 return (* iface->open_readwrite) (file, cancellable, error);
1731 * g_file_create_readwrite:
1733 * @flags: a set of #GFileCreateFlags
1734 * @cancellable: optional #GCancellable object, %NULL to ignore
1735 * @error: return location for a #GError, or %NULL
1737 * Creates a new file and returns a stream for reading and writing to it.
1738 * The file must not already exist.
1740 * By default files created are generally readable by everyone,
1741 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1742 * will be made readable only to the current user, to the level that
1743 * is supported on the target filesystem.
1745 * If @cancellable is not %NULL, then the operation can be cancelled by
1746 * triggering the cancellable object from another thread. If the operation
1747 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1749 * If a file or directory with this name already exists the %G_IO_ERROR_EXISTS
1750 * error will be returned. Some file systems don't allow all file names,
1751 * and may return an %G_IO_ERROR_INVALID_FILENAME error, and if the name
1752 * is too long, %G_IO_ERROR_FILENAME_TOO_LONG will be returned. Other errors
1753 * are possible too, and depend on what kind of filesystem the file is on.
1755 * Note that in many non-local file cases read and write streams are not
1756 * supported, so make sure you really need to do read and write streaming,
1757 * rather than just opening for reading or writing.
1759 * Returns: (transfer full): a #GFileIOStream for the newly created file, or %NULL on error.
1760 * Free the returned object with g_object_unref().
1765 g_file_create_readwrite (GFile *file,
1766 GFileCreateFlags flags,
1767 GCancellable *cancellable,
1772 g_return_val_if_fail (G_IS_FILE (file), NULL);
1774 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1777 iface = G_FILE_GET_IFACE (file);
1779 if (iface->create_readwrite == NULL)
1781 g_set_error_literal (error, G_IO_ERROR,
1782 G_IO_ERROR_NOT_SUPPORTED,
1783 _("Operation not supported"));
1787 return (* iface->create_readwrite) (file, flags, cancellable, error);
1791 * g_file_replace_readwrite:
1793 * @etag: (allow-none): an optional <link linkend="gfile-etag">entity tag</link> for the
1794 * current #GFile, or #NULL to ignore
1795 * @make_backup: %TRUE if a backup should be created
1796 * @flags: a set of #GFileCreateFlags
1797 * @cancellable: optional #GCancellable object, %NULL to ignore
1798 * @error: return location for a #GError, or %NULL
1800 * Returns an output stream for overwriting the file in readwrite mode,
1801 * possibly creating a backup copy of the file first. If the file doesn't
1802 * exist, it will be created.
1804 * For details about the behaviour, see g_file_replace() which does the same
1805 * thing but returns an output stream only.
1807 * Note that in many non-local file cases read and write streams are not
1808 * supported, so make sure you really need to do read and write streaming,
1809 * rather than just opening for reading or writing.
1811 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
1812 * Free the returned object with g_object_unref().
1817 g_file_replace_readwrite (GFile *file,
1819 gboolean make_backup,
1820 GFileCreateFlags flags,
1821 GCancellable *cancellable,
1826 g_return_val_if_fail (G_IS_FILE (file), NULL);
1828 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1831 iface = G_FILE_GET_IFACE (file);
1833 if (iface->replace_readwrite == NULL)
1835 g_set_error_literal (error, G_IO_ERROR,
1836 G_IO_ERROR_NOT_SUPPORTED,
1837 _("Operation not supported"));
1841 return (* iface->replace_readwrite) (file, etag, make_backup, flags, cancellable, error);
1845 * g_file_read_async:
1846 * @file: input #GFile
1847 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1849 * @cancellable: optional #GCancellable object, %NULL to ignore.
1850 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1851 * @user_data: the data to pass to callback function
1853 * Asynchronously opens @file for reading.
1855 * For more details, see g_file_read() which is
1856 * the synchronous version of this call.
1858 * When the operation is finished, @callback will be called. You can then call
1859 * g_file_read_finish() to get the result of the operation.
1862 g_file_read_async (GFile *file,
1864 GCancellable *cancellable,
1865 GAsyncReadyCallback callback,
1870 g_return_if_fail (G_IS_FILE (file));
1872 iface = G_FILE_GET_IFACE (file);
1873 (* iface->read_async) (file,
1881 * g_file_read_finish:
1882 * @file: input #GFile.
1883 * @res: a #GAsyncResult.
1884 * @error: a #GError, or %NULL
1886 * Finishes an asynchronous file read operation started with
1887 * g_file_read_async().
1889 * Returns: (transfer full): a #GFileInputStream or %NULL on error.
1890 * Free the returned object with g_object_unref().
1893 g_file_read_finish (GFile *file,
1899 g_return_val_if_fail (G_IS_FILE (file), NULL);
1900 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1902 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1904 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1905 if (g_simple_async_result_propagate_error (simple, error))
1909 iface = G_FILE_GET_IFACE (file);
1910 return (* iface->read_finish) (file, res, error);
1914 * g_file_append_to_async:
1915 * @file: input #GFile.
1916 * @flags: a set of #GFileCreateFlags.
1917 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1919 * @cancellable: optional #GCancellable object, %NULL to ignore.
1920 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1921 * @user_data: the data to pass to callback function
1923 * Asynchronously opens @file for appending.
1925 * For more details, see g_file_append_to() which is
1926 * the synchronous version of this call.
1928 * When the operation is finished, @callback will be called. You can then call
1929 * g_file_append_to_finish() to get the result of the operation.
1932 g_file_append_to_async (GFile *file,
1933 GFileCreateFlags flags,
1935 GCancellable *cancellable,
1936 GAsyncReadyCallback callback,
1941 g_return_if_fail (G_IS_FILE (file));
1943 iface = G_FILE_GET_IFACE (file);
1944 (* iface->append_to_async) (file,
1953 * g_file_append_to_finish:
1954 * @file: input #GFile.
1955 * @res: #GAsyncResult
1956 * @error: a #GError, or %NULL
1958 * Finishes an asynchronous file append operation started with
1959 * g_file_append_to_async().
1961 * Returns: (transfer full): a valid #GFileOutputStream or %NULL on error.
1962 * Free the returned object with g_object_unref().
1965 g_file_append_to_finish (GFile *file,
1971 g_return_val_if_fail (G_IS_FILE (file), NULL);
1972 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1974 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1976 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1977 if (g_simple_async_result_propagate_error (simple, error))
1981 iface = G_FILE_GET_IFACE (file);
1982 return (* iface->append_to_finish) (file, res, error);
1986 * g_file_create_async:
1987 * @file: input #GFile.
1988 * @flags: a set of #GFileCreateFlags.
1989 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1991 * @cancellable: optional #GCancellable object, %NULL to ignore.
1992 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
1993 * @user_data: the data to pass to callback function
1995 * Asynchronously creates a new file and returns an output stream for writing to it.
1996 * The file must not already exist.
1998 * For more details, see g_file_create() which is
1999 * the synchronous version of this call.
2001 * When the operation is finished, @callback will be called. You can then call
2002 * g_file_create_finish() to get the result of the operation.
2005 g_file_create_async (GFile *file,
2006 GFileCreateFlags flags,
2008 GCancellable *cancellable,
2009 GAsyncReadyCallback callback,
2014 g_return_if_fail (G_IS_FILE (file));
2016 iface = G_FILE_GET_IFACE (file);
2017 (* iface->create_async) (file,
2026 * g_file_create_finish:
2027 * @file: input #GFile.
2028 * @res: a #GAsyncResult.
2029 * @error: a #GError, or %NULL
2031 * Finishes an asynchronous file create operation started with
2032 * g_file_create_async().
2034 * Returns: (transfer full): a #GFileOutputStream or %NULL on error.
2035 * Free the returned object with g_object_unref().
2038 g_file_create_finish (GFile *file,
2044 g_return_val_if_fail (G_IS_FILE (file), NULL);
2045 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2047 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2049 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2050 if (g_simple_async_result_propagate_error (simple, error))
2054 iface = G_FILE_GET_IFACE (file);
2055 return (* iface->create_finish) (file, res, error);
2059 * g_file_replace_async:
2060 * @file: input #GFile.
2061 * @etag: (allow-none): an <link linkend="gfile-etag">entity tag</link> for the
2062 * current #GFile, or NULL to ignore.
2063 * @make_backup: %TRUE if a backup should be created.
2064 * @flags: a set of #GFileCreateFlags.
2065 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2067 * @cancellable: optional #GCancellable object, %NULL to ignore.
2068 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
2069 * @user_data: the data to pass to callback function
2071 * Asynchronously overwrites the file, replacing the contents, possibly
2072 * creating a backup copy of the file first.
2074 * For more details, see g_file_replace() which is
2075 * the synchronous version of this call.
2077 * When the operation is finished, @callback will be called. You can then call
2078 * g_file_replace_finish() to get the result of the operation.
2081 g_file_replace_async (GFile *file,
2083 gboolean make_backup,
2084 GFileCreateFlags flags,
2086 GCancellable *cancellable,
2087 GAsyncReadyCallback callback,
2092 g_return_if_fail (G_IS_FILE (file));
2094 iface = G_FILE_GET_IFACE (file);
2095 (* iface->replace_async) (file,
2106 * g_file_replace_finish:
2107 * @file: input #GFile.
2108 * @res: a #GAsyncResult.
2109 * @error: a #GError, or %NULL
2111 * Finishes an asynchronous file replace operation started with
2112 * g_file_replace_async().
2114 * Returns: (transfer full): a #GFileOutputStream, or %NULL on error.
2115 * Free the returned object with g_object_unref().
2118 g_file_replace_finish (GFile *file,
2124 g_return_val_if_fail (G_IS_FILE (file), NULL);
2125 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2127 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2129 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2130 if (g_simple_async_result_propagate_error (simple, error))
2134 iface = G_FILE_GET_IFACE (file);
2135 return (* iface->replace_finish) (file, res, error);
2140 * g_file_open_readwrite_async:
2141 * @file: input #GFile.
2142 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2144 * @cancellable: optional #GCancellable object, %NULL to ignore.
2145 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
2146 * @user_data: the data to pass to callback function
2148 * Asynchronously opens @file for reading and writing.
2150 * For more details, see g_file_open_readwrite() which is
2151 * the synchronous version of this call.
2153 * When the operation is finished, @callback will be called. You can then call
2154 * g_file_open_readwrite_finish() to get the result of the operation.
2159 g_file_open_readwrite_async (GFile *file,
2161 GCancellable *cancellable,
2162 GAsyncReadyCallback callback,
2167 g_return_if_fail (G_IS_FILE (file));
2169 iface = G_FILE_GET_IFACE (file);
2170 (* iface->open_readwrite_async) (file,
2178 * g_file_open_readwrite_finish:
2179 * @file: input #GFile.
2180 * @res: a #GAsyncResult.
2181 * @error: a #GError, or %NULL
2183 * Finishes an asynchronous file read operation started with
2184 * g_file_open_readwrite_async().
2186 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
2187 * Free the returned object with g_object_unref().
2192 g_file_open_readwrite_finish (GFile *file,
2198 g_return_val_if_fail (G_IS_FILE (file), NULL);
2199 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2201 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2203 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2204 if (g_simple_async_result_propagate_error (simple, error))
2208 iface = G_FILE_GET_IFACE (file);
2209 return (* iface->open_readwrite_finish) (file, res, error);
2214 * g_file_create_readwrite_async:
2215 * @file: input #GFile
2216 * @flags: a set of #GFileCreateFlags
2217 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2219 * @cancellable: optional #GCancellable object, %NULL to ignore
2220 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
2221 * @user_data: the data to pass to callback function
2223 * Asynchronously creates a new file and returns a stream for reading and
2224 * writing to it. The file must not already exist.
2226 * For more details, see g_file_create_readwrite() which is
2227 * the synchronous version of this call.
2229 * When the operation is finished, @callback will be called. You can then
2230 * call g_file_create_readwrite_finish() to get the result of the operation.
2235 g_file_create_readwrite_async (GFile *file,
2236 GFileCreateFlags flags,
2238 GCancellable *cancellable,
2239 GAsyncReadyCallback callback,
2244 g_return_if_fail (G_IS_FILE (file));
2246 iface = G_FILE_GET_IFACE (file);
2247 (* iface->create_readwrite_async) (file,
2256 * g_file_create_readwrite_finish:
2257 * @file: input #GFile
2258 * @res: a #GAsyncResult
2259 * @error: a #GError, or %NULL
2261 * Finishes an asynchronous file create operation started with
2262 * g_file_create_readwrite_async().
2264 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
2265 * Free the returned object with g_object_unref().
2270 g_file_create_readwrite_finish (GFile *file,
2276 g_return_val_if_fail (G_IS_FILE (file), NULL);
2277 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2279 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2281 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2282 if (g_simple_async_result_propagate_error (simple, error))
2286 iface = G_FILE_GET_IFACE (file);
2287 return (* iface->create_readwrite_finish) (file, res, error);
2291 * g_file_replace_readwrite_async:
2292 * @file: input #GFile.
2293 * @etag: (allow-none): an <link linkend="gfile-etag">entity tag</link> for the
2294 * current #GFile, or NULL to ignore.
2295 * @make_backup: %TRUE if a backup should be created.
2296 * @flags: a set of #GFileCreateFlags.
2297 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2299 * @cancellable: optional #GCancellable object, %NULL to ignore.
2300 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
2301 * @user_data: the data to pass to callback function
2303 * Asynchronously overwrites the file in read-write mode, replacing the
2304 * contents, possibly creating a backup copy of the file first.
2306 * For more details, see g_file_replace_readwrite() which is
2307 * the synchronous version of this call.
2309 * When the operation is finished, @callback will be called. You can then
2310 * call g_file_replace_readwrite_finish() to get the result of the operation.
2315 g_file_replace_readwrite_async (GFile *file,
2317 gboolean make_backup,
2318 GFileCreateFlags flags,
2320 GCancellable *cancellable,
2321 GAsyncReadyCallback callback,
2326 g_return_if_fail (G_IS_FILE (file));
2328 iface = G_FILE_GET_IFACE (file);
2329 (* iface->replace_readwrite_async) (file,
2340 * g_file_replace_readwrite_finish:
2341 * @file: input #GFile.
2342 * @res: a #GAsyncResult.
2343 * @error: a #GError, or %NULL
2345 * Finishes an asynchronous file replace operation started with
2346 * g_file_replace_readwrite_async().
2348 * Returns: (transfer full): a #GFileIOStream, or %NULL on error.
2349 * Free the returned object with g_object_unref().
2354 g_file_replace_readwrite_finish (GFile *file,
2360 g_return_val_if_fail (G_IS_FILE (file), NULL);
2361 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2363 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2365 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2366 if (g_simple_async_result_propagate_error (simple, error))
2370 iface = G_FILE_GET_IFACE (file);
2371 return (* iface->replace_readwrite_finish) (file, res, error);
2375 copy_symlink (GFile *destination,
2376 GFileCopyFlags flags,
2377 GCancellable *cancellable,
2382 gboolean tried_delete;
2384 GFileType file_type;
2386 tried_delete = FALSE;
2390 if (!g_file_make_symbolic_link (destination, target, cancellable, &my_error))
2392 /* Maybe it already existed, and we want to overwrite? */
2393 if (!tried_delete && (flags & G_FILE_COPY_OVERWRITE) &&
2394 my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_EXISTS)
2396 g_error_free (my_error);
2399 /* Don't overwrite if the destination is a directory */
2400 info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
2401 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2402 cancellable, &my_error);
2405 file_type = g_file_info_get_file_type (info);
2406 g_object_unref (info);
2408 if (file_type == G_FILE_TYPE_DIRECTORY)
2410 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY,
2411 _("Can't copy over directory"));
2416 if (!g_file_delete (destination, cancellable, error))
2419 tried_delete = TRUE;
2423 g_propagate_error (error, my_error);
2430 static GInputStream *
2431 open_source_for_copy (GFile *source,
2433 GFileCopyFlags flags,
2434 GCancellable *cancellable,
2440 GFileType file_type;
2443 in = (GInputStream *)g_file_read (source, cancellable, &my_error);
2447 /* There was an error opening the source, try to set a good error for it: */
2449 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_IS_DIRECTORY)
2451 /* The source is a directory, don't fail with WOULD_RECURSE immediately,
2452 * as that is less useful to the app. Better check for errors on the
2455 g_error_free (my_error);
2458 info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
2459 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2460 cancellable, &my_error);
2462 g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_TYPE))
2464 file_type = g_file_info_get_file_type (info);
2465 g_object_unref (info);
2467 if (flags & G_FILE_COPY_OVERWRITE)
2469 if (file_type == G_FILE_TYPE_DIRECTORY)
2471 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_MERGE,
2472 _("Can't copy directory over directory"));
2475 /* continue to would_recurse error */
2479 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
2480 _("Target file exists"));
2486 /* Error getting info from target, return that error
2487 * (except for NOT_FOUND, which is no error here)
2489 if (my_error != NULL && !g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
2491 g_propagate_error (error, my_error);
2494 g_clear_error (&my_error);
2497 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_RECURSE,
2498 _("Can't recursively copy directory"));
2502 g_propagate_error (error, my_error);
2507 should_copy (GFileAttributeInfo *info,
2509 gboolean skip_perms)
2511 if (skip_perms && strcmp(info->name, "unix::mode") == 0)
2515 return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED;
2516 return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE;
2520 build_attribute_list_for_copy (GFileAttributeInfoList *attributes,
2521 GFileAttributeInfoList *namespaces,
2523 gboolean skip_perms)
2530 s = g_string_new ("");
2534 for (i = 0; i < attributes->n_infos; i++)
2536 if (should_copy (&attributes->infos[i], as_move, skip_perms))
2541 g_string_append_c (s, ',');
2543 g_string_append (s, attributes->infos[i].name);
2550 for (i = 0; i < namespaces->n_infos; i++)
2552 if (should_copy (&namespaces->infos[i], as_move, FALSE))
2557 g_string_append_c (s, ',');
2559 g_string_append (s, namespaces->infos[i].name);
2560 g_string_append (s, "::*");
2565 return g_string_free (s, FALSE);
2569 * g_file_copy_attributes:
2570 * @source: a #GFile with attributes.
2571 * @destination: a #GFile to copy attributes to.
2572 * @flags: a set of #GFileCopyFlags.
2573 * @cancellable: optional #GCancellable object, %NULL to ignore.
2574 * @error: a #GError, %NULL to ignore.
2576 * Copies the file attributes from @source to @destination.
2578 * Normally only a subset of the file attributes are copied,
2579 * those that are copies in a normal file copy operation
2580 * (which for instance does not include e.g. owner). However
2581 * if #G_FILE_COPY_ALL_METADATA is specified in @flags, then
2582 * all the metadata that is possible to copy is copied. This
2583 * is useful when implementing move by copy + delete source.
2585 * Returns: %TRUE if the attributes were copied successfully, %FALSE otherwise.
2588 g_file_copy_attributes (GFile *source,
2590 GFileCopyFlags flags,
2591 GCancellable *cancellable,
2594 GFileAttributeInfoList *attributes, *namespaces;
2595 char *attrs_to_read;
2599 gboolean source_nofollow_symlinks;
2600 gboolean skip_perms;
2602 as_move = flags & G_FILE_COPY_ALL_METADATA;
2603 source_nofollow_symlinks = flags & G_FILE_COPY_NOFOLLOW_SYMLINKS;
2604 skip_perms = (flags & G_FILE_COPY_TARGET_DEFAULT_PERMS) != 0;
2606 /* Ignore errors here, if the target supports no attributes there is nothing to copy */
2607 attributes = g_file_query_settable_attributes (destination, cancellable, NULL);
2608 namespaces = g_file_query_writable_namespaces (destination, cancellable, NULL);
2610 if (attributes == NULL && namespaces == NULL)
2613 attrs_to_read = build_attribute_list_for_copy (attributes, namespaces, as_move, skip_perms);
2615 /* Ignore errors here, if we can't read some info (e.g. if it doesn't exist)
2616 * we just don't copy it.
2618 info = g_file_query_info (source, attrs_to_read,
2619 source_nofollow_symlinks ? G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS:0,
2623 g_free (attrs_to_read);
2628 res = g_file_set_attributes_from_info (destination,
2630 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2633 g_object_unref (info);
2636 g_file_attribute_info_list_unref (attributes);
2637 g_file_attribute_info_list_unref (namespaces);
2643 copy_stream_with_progress (GInputStream *in,
2646 GCancellable *cancellable,
2647 GFileProgressCallback progress_callback,
2648 gpointer progress_callback_data,
2651 gssize n_read, n_written;
2652 goffset current_size;
2653 char buffer[1024*64], *p;
2659 /* avoid performance impact of querying total size when it's not needed */
2660 if (progress_callback)
2662 info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (in),
2663 G_FILE_ATTRIBUTE_STANDARD_SIZE,
2667 if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
2668 total_size = g_file_info_get_size (info);
2669 g_object_unref (info);
2672 if (total_size == -1)
2674 info = g_file_query_info (source,
2675 G_FILE_ATTRIBUTE_STANDARD_SIZE,
2676 G_FILE_QUERY_INFO_NONE,
2680 if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
2681 total_size = g_file_info_get_size (info);
2682 g_object_unref (info);
2687 if (total_size == -1)
2694 n_read = g_input_stream_read (in, buffer, sizeof (buffer), cancellable, error);
2704 current_size += n_read;
2709 n_written = g_output_stream_write (out, p, n_read, cancellable, error);
2710 if (n_written == -1)
2717 n_read -= n_written;
2723 if (progress_callback)
2724 progress_callback (current_size, total_size, progress_callback_data);
2727 /* Make sure we send full copied size */
2728 if (progress_callback)
2729 progress_callback (current_size, total_size, progress_callback_data);
2737 do_splice (int fd_in,
2742 long *bytes_transferd,
2748 result = splice (fd_in, off_in, fd_out, off_out, len, SPLICE_F_MORE);
2756 else if (errsv == ENOSYS || errsv == EINVAL)
2757 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2758 _("Splice not supported"));
2760 g_set_error (error, G_IO_ERROR,
2761 g_io_error_from_errno (errsv),
2762 _("Error splicing file: %s"),
2763 g_strerror (errsv));
2768 *bytes_transferd = result;
2773 splice_stream_with_progress (GInputStream *in,
2775 GCancellable *cancellable,
2776 GFileProgressCallback progress_callback,
2777 gpointer progress_callback_data,
2787 fd_in = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (in));
2788 fd_out = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (out));
2790 if (pipe (buffer) != 0)
2792 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2793 "Pipe creation failed");
2798 /* avoid performance impact of querying total size when it's not needed */
2799 if (progress_callback)
2803 if (fstat (fd_in, &sbuf) == 0)
2804 total_size = sbuf.st_size;
2807 if (total_size == -1)
2810 offset_in = offset_out = 0;
2817 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2820 if (!do_splice (fd_in, &offset_in, buffer[1], NULL, 1024*64, &n_read, error))
2831 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2834 if (!do_splice (buffer[0], NULL, fd_out, &offset_out, n_read, &n_written, error))
2837 n_read -= n_written;
2840 if (progress_callback)
2841 progress_callback (offset_in, total_size, progress_callback_data);
2844 /* Make sure we send full copied size */
2845 if (progress_callback)
2846 progress_callback (offset_in, total_size, progress_callback_data);
2857 file_copy_fallback (GFile *source,
2859 GFileCopyFlags flags,
2860 GCancellable *cancellable,
2861 GFileProgressCallback progress_callback,
2862 gpointer progress_callback_data,
2871 gboolean fallback = TRUE;
2874 /* need to know the file type */
2875 info = g_file_query_info (source,
2876 G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
2877 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2884 /* Maybe copy the symlink? */
2885 if ((flags & G_FILE_COPY_NOFOLLOW_SYMLINKS) &&
2886 g_file_info_get_file_type (info) == G_FILE_TYPE_SYMBOLIC_LINK)
2888 target = g_file_info_get_symlink_target (info);
2891 if (!copy_symlink (destination, flags, cancellable, target, error))
2893 g_object_unref (info);
2897 g_object_unref (info);
2900 /* ... else fall back on a regular file copy */
2901 g_object_unref (info);
2903 /* Handle "special" files (pipes, device nodes, ...)? */
2904 else if (g_file_info_get_file_type (info) == G_FILE_TYPE_SPECIAL)
2906 /* FIXME: could try to recreate device nodes and others? */
2908 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2909 _("Can't copy special file"));
2910 g_object_unref (info);
2913 /* Everything else should just fall back on a regular copy. */
2915 g_object_unref (info);
2917 in = open_source_for_copy (source, destination, flags, cancellable, error);
2921 if (flags & G_FILE_COPY_OVERWRITE)
2923 out = (GOutputStream *)g_file_replace (destination,
2925 flags & G_FILE_COPY_BACKUP,
2926 G_FILE_CREATE_REPLACE_DESTINATION,
2927 cancellable, error);
2931 out = (GOutputStream *)g_file_create (destination, 0, cancellable, error);
2936 g_object_unref (in);
2941 if (G_IS_FILE_DESCRIPTOR_BASED (in) && G_IS_FILE_DESCRIPTOR_BASED (out))
2943 GError *splice_err = NULL;
2945 result = splice_stream_with_progress (in, out, cancellable,
2946 progress_callback, progress_callback_data,
2949 if (result || !g_error_matches (splice_err, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
2953 g_propagate_error (error, splice_err);
2956 g_clear_error (&splice_err);
2961 result = copy_stream_with_progress (in, out, source, cancellable,
2962 progress_callback, progress_callback_data,
2965 /* Don't care about errors in source here */
2966 g_input_stream_close (in, cancellable, NULL);
2968 /* But write errors on close are bad! */
2969 if (!g_output_stream_close (out, cancellable, result ? error : NULL))
2972 g_object_unref (in);
2973 g_object_unref (out);
2975 if (result == FALSE)
2979 /* Ignore errors here. Failure to copy metadata is not a hard error */
2980 g_file_copy_attributes (source, destination,
2981 flags, cancellable, NULL);
2988 * @source: input #GFile.
2989 * @destination: destination #GFile
2990 * @flags: set of #GFileCopyFlags
2991 * @cancellable: optional #GCancellable object, %NULL to ignore.
2992 * @progress_callback: function to callback with progress information
2993 * @progress_callback_data: user data to pass to @progress_callback
2994 * @error: #GError to set on error, or %NULL
2996 * Copies the file @source to the location specified by @destination.
2997 * Can not handle recursive copies of directories.
2999 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
3000 * existing @destination file is overwritten.
3002 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
3003 * will be copied as symlinks, otherwise the target of the
3004 * @source symlink will be copied.
3006 * If @cancellable is not %NULL, then the operation can be cancelled by
3007 * triggering the cancellable object from another thread. If the operation
3008 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3010 * If @progress_callback is not %NULL, then the operation can be monitored by
3011 * setting this to a #GFileProgressCallback function. @progress_callback_data
3012 * will be passed to this function. It is guaranteed that this callback will
3013 * be called after all data has been transferred with the total number of bytes
3014 * copied during the operation.
3016 * If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
3017 * error is returned, independent on the status of the @destination.
3019 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then the
3020 * error G_IO_ERROR_EXISTS is returned.
3022 * If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY
3023 * error is returned. If trying to overwrite a directory with a directory the
3024 * G_IO_ERROR_WOULD_MERGE error is returned.
3026 * If the source is a directory and the target does not exist, or #G_FILE_COPY_OVERWRITE is
3027 * specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error
3030 * If you are interested in copying the #GFile object itself (not the on-disk
3031 * file), see g_file_dup().
3033 * Returns: %TRUE on success, %FALSE otherwise.
3036 g_file_copy (GFile *source,
3038 GFileCopyFlags flags,
3039 GCancellable *cancellable,
3040 GFileProgressCallback progress_callback,
3041 gpointer progress_callback_data,
3048 g_return_val_if_fail (G_IS_FILE (source), FALSE);
3049 g_return_val_if_fail (G_IS_FILE (destination), FALSE);
3051 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3054 iface = G_FILE_GET_IFACE (destination);
3058 res = (* iface->copy) (source, destination,
3060 progress_callback, progress_callback_data,
3066 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3068 g_propagate_error (error, my_error);
3072 g_clear_error (&my_error);
3075 /* If the types are different, and the destination method failed
3076 also try the source method */
3077 if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
3079 iface = G_FILE_GET_IFACE (source);
3084 res = (* iface->copy) (source, destination,
3086 progress_callback, progress_callback_data,
3092 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3094 g_propagate_error (error, my_error);
3098 g_clear_error (&my_error);
3102 return file_copy_fallback (source, destination, flags, cancellable,
3103 progress_callback, progress_callback_data,
3108 * g_file_copy_async:
3109 * @source: input #GFile.
3110 * @destination: destination #GFile
3111 * @flags: set of #GFileCopyFlags
3112 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3114 * @cancellable: optional #GCancellable object, %NULL to ignore.
3115 * @progress_callback: function to callback with progress information
3116 * @progress_callback_data: user data to pass to @progress_callback
3117 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
3118 * @user_data: the data to pass to callback function
3120 * Copies the file @source to the location specified by @destination
3121 * asynchronously. For details of the behaviour, see g_file_copy().
3123 * If @progress_callback is not %NULL, then that function that will be called
3124 * just like in g_file_copy(), however the callback will run in the main loop,
3125 * not in the thread that is doing the I/O operation.
3127 * When the operation is finished, @callback will be called. You can then call
3128 * g_file_copy_finish() to get the result of the operation.
3131 g_file_copy_async (GFile *source,
3133 GFileCopyFlags flags,
3135 GCancellable *cancellable,
3136 GFileProgressCallback progress_callback,
3137 gpointer progress_callback_data,
3138 GAsyncReadyCallback callback,
3143 g_return_if_fail (G_IS_FILE (source));
3144 g_return_if_fail (G_IS_FILE (destination));
3146 iface = G_FILE_GET_IFACE (source);
3147 (* iface->copy_async) (source,
3153 progress_callback_data,
3159 * g_file_copy_finish:
3160 * @file: input #GFile.
3161 * @res: a #GAsyncResult.
3162 * @error: a #GError, or %NULL
3164 * Finishes copying the file started with
3165 * g_file_copy_async().
3167 * Returns: a %TRUE on success, %FALSE on error.
3170 g_file_copy_finish (GFile *file,
3176 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3177 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
3179 if (G_IS_SIMPLE_ASYNC_RESULT (res))
3181 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
3183 if (g_simple_async_result_propagate_error (simple, error))
3187 iface = G_FILE_GET_IFACE (file);
3188 return (* iface->copy_finish) (file, res, error);
3193 * @source: #GFile pointing to the source location.
3194 * @destination: #GFile pointing to the destination location.
3195 * @flags: set of #GFileCopyFlags.
3196 * @cancellable: optional #GCancellable object, %NULL to ignore.
3197 * @progress_callback: #GFileProgressCallback function for updates.
3198 * @progress_callback_data: gpointer to user data for the callback function.
3199 * @error: #GError for returning error conditions, or %NULL
3202 * Tries to move the file or directory @source to the location specified by @destination.
3203 * If native move operations are supported then this is used, otherwise a copy + delete
3204 * fallback is used. The native implementation may support moving directories (for instance
3205 * on moves inside the same filesystem), but the fallback code does not.
3207 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
3208 * existing @destination file is overwritten.
3210 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
3211 * will be copied as symlinks, otherwise the target of the
3212 * @source symlink will be copied.
3214 * If @cancellable is not %NULL, then the operation can be cancelled by
3215 * triggering the cancellable object from another thread. If the operation
3216 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3218 * If @progress_callback is not %NULL, then the operation can be monitored by
3219 * setting this to a #GFileProgressCallback function. @progress_callback_data
3220 * will be passed to this function. It is guaranteed that this callback will
3221 * be called after all data has been transferred with the total number of bytes
3222 * copied during the operation.
3224 * If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
3225 * error is returned, independent on the status of the @destination.
3227 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then the
3228 * error G_IO_ERROR_EXISTS is returned.
3230 * If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY
3231 * error is returned. If trying to overwrite a directory with a directory the
3232 * G_IO_ERROR_WOULD_MERGE error is returned.
3234 * If the source is a directory and the target does not exist, or #G_FILE_COPY_OVERWRITE is
3235 * specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error
3236 * may be returned (if the native move operation isn't available).
3238 * Returns: %TRUE on successful move, %FALSE otherwise.
3241 g_file_move (GFile *source,
3243 GFileCopyFlags flags,
3244 GCancellable *cancellable,
3245 GFileProgressCallback progress_callback,
3246 gpointer progress_callback_data,
3253 g_return_val_if_fail (G_IS_FILE (source), FALSE);
3254 g_return_val_if_fail (G_IS_FILE (destination), FALSE);
3256 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3259 iface = G_FILE_GET_IFACE (destination);
3263 res = (* iface->move) (source, destination,
3265 progress_callback, progress_callback_data,
3271 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3273 g_propagate_error (error, my_error);
3278 /* If the types are different, and the destination method failed
3279 also try the source method */
3280 if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
3282 iface = G_FILE_GET_IFACE (source);
3287 res = (* iface->move) (source, destination,
3289 progress_callback, progress_callback_data,
3295 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3297 g_propagate_error (error, my_error);
3303 if (flags & G_FILE_COPY_NO_FALLBACK_FOR_MOVE)
3305 g_set_error_literal (error, G_IO_ERROR,
3306 G_IO_ERROR_NOT_SUPPORTED,
3307 _("Operation not supported"));
3311 flags |= G_FILE_COPY_ALL_METADATA;
3312 if (!g_file_copy (source, destination, flags, cancellable,
3313 progress_callback, progress_callback_data,
3317 return g_file_delete (source, cancellable, error);
3321 * g_file_make_directory
3322 * @file: input #GFile.
3323 * @cancellable: optional #GCancellable object, %NULL to ignore.
3324 * @error: a #GError, or %NULL
3326 * Creates a directory. Note that this will only create a child directory of
3327 * the immediate parent directory of the path or URI given by the #GFile. To
3328 * recursively create directories, see g_file_make_directory_with_parents().
3329 * This function will fail if the parent directory does not exist, setting
3330 * @error to %G_IO_ERROR_NOT_FOUND. If the file system doesn't support creating
3331 * directories, this function will fail, setting @error to
3332 * %G_IO_ERROR_NOT_SUPPORTED.
3334 * For a local #GFile the newly created directory will have the default
3335 * (current) ownership and permissions of the current process.
3337 * If @cancellable is not %NULL, then the operation can be cancelled by
3338 * triggering the cancellable object from another thread. If the operation
3339 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3341 * Returns: %TRUE on successful creation, %FALSE otherwise.
3344 g_file_make_directory (GFile *file,
3345 GCancellable *cancellable,
3350 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3352 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3355 iface = G_FILE_GET_IFACE (file);
3357 if (iface->make_directory == NULL)
3359 g_set_error_literal (error, G_IO_ERROR,
3360 G_IO_ERROR_NOT_SUPPORTED,
3361 _("Operation not supported"));
3365 return (* iface->make_directory) (file, cancellable, error);
3369 * g_file_make_directory_with_parents:
3370 * @file: input #GFile.
3371 * @cancellable: optional #GCancellable object, %NULL to ignore.
3372 * @error: a #GError, or %NULL
3374 * Creates a directory and any parent directories that may not exist similar to
3375 * 'mkdir -p'. If the file system does not support creating directories, this
3376 * function will fail, setting @error to %G_IO_ERROR_NOT_SUPPORTED.
3378 * For a local #GFile the newly created directories will have the default
3379 * (current) ownership and permissions of the current process.
3381 * If @cancellable is not %NULL, then the operation can be cancelled by
3382 * triggering the cancellable object from another thread. If the operation
3383 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3385 * Returns: %TRUE if all directories have been successfully created, %FALSE
3391 g_file_make_directory_with_parents (GFile *file,
3392 GCancellable *cancellable,
3396 GFile *parent_file, *work_file;
3397 GList *list = NULL, *l;
3398 GError *my_error = NULL;
3400 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3403 result = g_file_make_directory (file, cancellable, &my_error);
3404 if (result || my_error->code != G_IO_ERROR_NOT_FOUND)
3407 g_propagate_error (error, my_error);
3413 while (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
3415 g_clear_error (&my_error);
3417 parent_file = g_file_get_parent (work_file);
3418 if (parent_file == NULL)
3420 result = g_file_make_directory (parent_file, cancellable, &my_error);
3422 if (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
3423 list = g_list_prepend (list, parent_file);
3425 work_file = parent_file;
3428 for (l = list; result && l; l = l->next)
3430 result = g_file_make_directory ((GFile *) l->data, cancellable, &my_error);
3434 while (list != NULL)
3436 g_object_unref ((GFile *) list->data);
3437 list = g_list_remove (list, list->data);
3442 g_propagate_error (error, my_error);
3446 return g_file_make_directory (file, cancellable, error);
3450 * g_file_make_symbolic_link:
3451 * @file: a #GFile with the name of the symlink to create
3452 * @symlink_value: a string with the path for the target of the new symlink
3453 * @cancellable: optional #GCancellable object, %NULL to ignore.
3454 * @error: a #GError.
3456 * Creates a symbolic link named @file which contains the string
3459 * If @cancellable is not %NULL, then the operation can be cancelled by
3460 * triggering the cancellable object from another thread. If the operation
3461 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3463 * Returns: %TRUE on the creation of a new symlink, %FALSE otherwise.
3466 g_file_make_symbolic_link (GFile *file,
3467 const char *symlink_value,
3468 GCancellable *cancellable,
3473 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3474 g_return_val_if_fail (symlink_value != NULL, FALSE);
3476 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3479 if (*symlink_value == '\0')
3481 g_set_error_literal (error, G_IO_ERROR,
3482 G_IO_ERROR_INVALID_ARGUMENT,
3483 _("Invalid symlink value given"));
3487 iface = G_FILE_GET_IFACE (file);
3489 if (iface->make_symbolic_link == NULL)
3491 g_set_error_literal (error, G_IO_ERROR,
3492 G_IO_ERROR_NOT_SUPPORTED,
3493 _("Operation not supported"));
3497 return (* iface->make_symbolic_link) (file, symlink_value, cancellable, error);
3502 * @file: input #GFile.
3503 * @cancellable: optional #GCancellable object, %NULL to ignore.
3504 * @error: a #GError, or %NULL
3506 * Deletes a file. If the @file is a directory, it will only be deleted if it
3509 * If @cancellable is not %NULL, then the operation can be cancelled by
3510 * triggering the cancellable object from another thread. If the operation
3511 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3513 * Virtual: delete_file
3514 * Returns: %TRUE if the file was deleted. %FALSE otherwise.
3517 g_file_delete (GFile *file,
3518 GCancellable *cancellable,
3523 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3525 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3528 iface = G_FILE_GET_IFACE (file);
3530 if (iface->delete_file == NULL)
3532 g_set_error_literal (error, G_IO_ERROR,
3533 G_IO_ERROR_NOT_SUPPORTED,
3534 _("Operation not supported"));
3538 return (* iface->delete_file) (file, cancellable, error);
3543 * @file: #GFile to send to trash.
3544 * @cancellable: optional #GCancellable object, %NULL to ignore.
3545 * @error: a #GError, or %NULL
3547 * Sends @file to the "Trashcan", if possible. This is similar to
3548 * deleting it, but the user can recover it before emptying the trashcan.
3549 * Not all file systems support trashing, so this call can return the
3550 * %G_IO_ERROR_NOT_SUPPORTED error.
3553 * If @cancellable is not %NULL, then the operation can be cancelled by
3554 * triggering the cancellable object from another thread. If the operation
3555 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3557 * Returns: %TRUE on successful trash, %FALSE otherwise.
3560 g_file_trash (GFile *file,
3561 GCancellable *cancellable,
3566 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3568 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3571 iface = G_FILE_GET_IFACE (file);
3573 if (iface->trash == NULL)
3575 g_set_error_literal (error,
3576 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
3577 _("Trash not supported"));
3581 return (* iface->trash) (file, cancellable, error);
3585 * g_file_set_display_name:
3586 * @file: input #GFile.
3587 * @display_name: a string.
3588 * @cancellable: optional #GCancellable object, %NULL to ignore.
3589 * @error: a #GError, or %NULL
3591 * Renames @file to the specified display name.
3593 * The display name is converted from UTF8 to the correct encoding for the target
3594 * filesystem if possible and the @file is renamed to this.
3596 * If you want to implement a rename operation in the user interface the edit name
3597 * (#G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the initial value in the rename
3598 * widget, and then the result after editing should be passed to g_file_set_display_name().
3600 * On success the resulting converted filename is returned.
3602 * If @cancellable is not %NULL, then the operation can be cancelled by
3603 * triggering the cancellable object from another thread. If the operation
3604 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3606 * Returns: (transfer full): a #GFile specifying what @file was renamed to, or %NULL
3607 * if there was an error.
3608 * Free the returned object with g_object_unref().
3611 g_file_set_display_name (GFile *file,
3612 const char *display_name,
3613 GCancellable *cancellable,
3618 g_return_val_if_fail (G_IS_FILE (file), NULL);
3619 g_return_val_if_fail (display_name != NULL, NULL);
3621 if (strchr (display_name, G_DIR_SEPARATOR) != NULL)
3625 G_IO_ERROR_INVALID_ARGUMENT,
3626 _("File names cannot contain '%c'"), G_DIR_SEPARATOR);
3630 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3633 iface = G_FILE_GET_IFACE (file);
3635 return (* iface->set_display_name) (file, display_name, cancellable, error);
3639 * g_file_set_display_name_async:
3640 * @file: input #GFile.
3641 * @display_name: a string.
3642 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3644 * @cancellable: optional #GCancellable object, %NULL to ignore.
3645 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
3646 * @user_data: the data to pass to callback function
3648 * Asynchronously sets the display name for a given #GFile.
3650 * For more details, see g_file_set_display_name() which is
3651 * the synchronous version of this call.
3653 * When the operation is finished, @callback will be called. You can then call
3654 * g_file_set_display_name_finish() to get the result of the operation.
3657 g_file_set_display_name_async (GFile *file,
3658 const char *display_name,
3660 GCancellable *cancellable,
3661 GAsyncReadyCallback callback,
3666 g_return_if_fail (G_IS_FILE (file));
3667 g_return_if_fail (display_name != NULL);
3669 iface = G_FILE_GET_IFACE (file);
3670 (* iface->set_display_name_async) (file,
3679 * g_file_set_display_name_finish:
3680 * @file: input #GFile.
3681 * @res: a #GAsyncResult.
3682 * @error: a #GError, or %NULL
3684 * Finishes setting a display name started with
3685 * g_file_set_display_name_async().
3687 * Returns: (transfer full): a #GFile or %NULL on error.
3688 * Free the returned object with g_object_unref().
3691 g_file_set_display_name_finish (GFile *file,
3697 g_return_val_if_fail (G_IS_FILE (file), NULL);
3698 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
3700 if (G_IS_SIMPLE_ASYNC_RESULT (res))
3702 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
3703 if (g_simple_async_result_propagate_error (simple, error))
3707 iface = G_FILE_GET_IFACE (file);
3708 return (* iface->set_display_name_finish) (file, res, error);
3712 * g_file_query_settable_attributes:
3713 * @file: input #GFile.
3714 * @cancellable: optional #GCancellable object, %NULL to ignore.
3715 * @error: a #GError, or %NULL
3717 * Obtain the list of settable attributes for the file.
3719 * Returns the type and full attribute name of all the attributes
3720 * that can be set on this file. This doesn't mean setting it will always
3721 * succeed though, you might get an access failure, or some specific
3722 * file may not support a specific attribute.
3724 * If @cancellable is not %NULL, then the operation can be cancelled by
3725 * triggering the cancellable object from another thread. If the operation
3726 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3728 * Returns: a #GFileAttributeInfoList describing the settable attributes.
3729 * When you are done with it, release it with g_file_attribute_info_list_unref()
3731 GFileAttributeInfoList *
3732 g_file_query_settable_attributes (GFile *file,
3733 GCancellable *cancellable,
3738 GFileAttributeInfoList *list;
3740 g_return_val_if_fail (G_IS_FILE (file), NULL);
3742 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3745 iface = G_FILE_GET_IFACE (file);
3747 if (iface->query_settable_attributes == NULL)
3748 return g_file_attribute_info_list_new ();
3751 list = (* iface->query_settable_attributes) (file, cancellable, &my_error);
3755 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
3757 list = g_file_attribute_info_list_new ();
3758 g_error_free (my_error);
3761 g_propagate_error (error, my_error);
3768 * g_file_query_writable_namespaces:
3769 * @file: input #GFile.
3770 * @cancellable: optional #GCancellable object, %NULL to ignore.
3771 * @error: a #GError, or %NULL
3773 * Obtain the list of attribute namespaces where new attributes
3774 * can be created by a user. An example of this is extended
3775 * attributes (in the "xattr" namespace).
3777 * If @cancellable is not %NULL, then the operation can be cancelled by
3778 * triggering the cancellable object from another thread. If the operation
3779 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3781 * Returns: a #GFileAttributeInfoList describing the writable namespaces.
3782 * When you are done with it, release it with g_file_attribute_info_list_unref()
3784 GFileAttributeInfoList *
3785 g_file_query_writable_namespaces (GFile *file,
3786 GCancellable *cancellable,
3791 GFileAttributeInfoList *list;
3793 g_return_val_if_fail (G_IS_FILE (file), NULL);
3795 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3798 iface = G_FILE_GET_IFACE (file);
3800 if (iface->query_writable_namespaces == NULL)
3801 return g_file_attribute_info_list_new ();
3804 list = (* iface->query_writable_namespaces) (file, cancellable, &my_error);
3808 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
3810 list = g_file_attribute_info_list_new ();
3811 g_error_free (my_error);
3814 g_propagate_error (error, my_error);
3821 * g_file_set_attribute:
3822 * @file: input #GFile.
3823 * @attribute: a string containing the attribute's name.
3824 * @type: The type of the attribute
3825 * @value_p: a pointer to the value (or the pointer itself if the type is a pointer type)
3826 * @flags: a set of #GFileQueryInfoFlags.
3827 * @cancellable: optional #GCancellable object, %NULL to ignore.
3828 * @error: a #GError, or %NULL
3830 * Sets an attribute in the file with attribute name @attribute to @value.
3832 * If @cancellable is not %NULL, then the operation can be cancelled by
3833 * triggering the cancellable object from another thread. If the operation
3834 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3836 * Returns: %TRUE if the attribute was set, %FALSE otherwise.
3839 g_file_set_attribute (GFile *file,
3840 const char *attribute,
3841 GFileAttributeType type,
3843 GFileQueryInfoFlags flags,
3844 GCancellable *cancellable,
3849 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3850 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
3852 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3855 iface = G_FILE_GET_IFACE (file);
3857 if (iface->set_attribute == NULL)
3859 g_set_error_literal (error, G_IO_ERROR,
3860 G_IO_ERROR_NOT_SUPPORTED,
3861 _("Operation not supported"));
3865 return (* iface->set_attribute) (file, attribute, type, value_p, flags, cancellable, error);
3869 * g_file_set_attributes_from_info:
3870 * @file: input #GFile.
3871 * @info: a #GFileInfo.
3872 * @flags: #GFileQueryInfoFlags
3873 * @cancellable: optional #GCancellable object, %NULL to ignore.
3874 * @error: a #GError, or %NULL
3876 * Tries to set all attributes in the #GFileInfo on the target values,
3877 * not stopping on the first error.
3879 * If there is any error during this operation then @error will be set to
3880 * the first error. Error on particular fields are flagged by setting
3881 * the "status" field in the attribute value to
3882 * %G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can also detect
3885 * If @cancellable is not %NULL, then the operation can be cancelled by
3886 * triggering the cancellable object from another thread. If the operation
3887 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3889 * Returns: %TRUE if there was any error, %FALSE otherwise.
3892 g_file_set_attributes_from_info (GFile *file,
3894 GFileQueryInfoFlags flags,
3895 GCancellable *cancellable,
3900 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3901 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
3903 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3906 g_file_info_clear_status (info);
3908 iface = G_FILE_GET_IFACE (file);
3910 return (* iface->set_attributes_from_info) (file,
3919 g_file_real_set_attributes_from_info (GFile *file,
3921 GFileQueryInfoFlags flags,
3922 GCancellable *cancellable,
3928 GFileAttributeValue *value;
3932 attributes = g_file_info_list_attributes (info, NULL);
3934 for (i = 0; attributes[i] != NULL; i++)
3936 value = _g_file_info_get_attribute_value (info, attributes[i]);
3938 if (value->status != G_FILE_ATTRIBUTE_STATUS_UNSET)
3941 if (!g_file_set_attribute (file, attributes[i],
3942 value->type, _g_file_attribute_value_peek_as_pointer (value),
3943 flags, cancellable, error))
3945 value->status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
3947 /* Don't set error multiple times */
3951 value->status = G_FILE_ATTRIBUTE_STATUS_SET;
3954 g_strfreev (attributes);
3960 * g_file_set_attributes_async:
3961 * @file: input #GFile.
3962 * @info: a #GFileInfo.
3963 * @flags: a #GFileQueryInfoFlags.
3964 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3966 * @cancellable: optional #GCancellable object, %NULL to ignore.
3967 * @callback: a #GAsyncReadyCallback.
3968 * @user_data: a #gpointer.
3970 * Asynchronously sets the attributes of @file with @info.
3972 * For more details, see g_file_set_attributes_from_info() which is
3973 * the synchronous version of this call.
3975 * When the operation is finished, @callback will be called. You can then call
3976 * g_file_set_attributes_finish() to get the result of the operation.
3979 g_file_set_attributes_async (GFile *file,
3981 GFileQueryInfoFlags flags,
3983 GCancellable *cancellable,
3984 GAsyncReadyCallback callback,
3989 g_return_if_fail (G_IS_FILE (file));
3990 g_return_if_fail (G_IS_FILE_INFO (info));
3992 iface = G_FILE_GET_IFACE (file);
3993 (* iface->set_attributes_async) (file,
4003 * g_file_set_attributes_finish:
4004 * @file: input #GFile.
4005 * @result: a #GAsyncResult.
4006 * @info: (out) (transfer full): a #GFileInfo.
4007 * @error: a #GError, or %NULL
4009 * Finishes setting an attribute started in g_file_set_attributes_async().
4011 * Returns: %TRUE if the attributes were set correctly, %FALSE otherwise.
4014 g_file_set_attributes_finish (GFile *file,
4015 GAsyncResult *result,
4021 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4022 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4024 /* No standard handling of errors here, as we must set info even
4027 iface = G_FILE_GET_IFACE (file);
4028 return (* iface->set_attributes_finish) (file, result, info, error);
4032 * g_file_set_attribute_string:
4033 * @file: input #GFile.
4034 * @attribute: a string containing the attribute's name.
4035 * @value: a string containing the attribute's value.
4036 * @flags: #GFileQueryInfoFlags.
4037 * @cancellable: optional #GCancellable object, %NULL to ignore.
4038 * @error: a #GError, or %NULL
4040 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value.
4041 * 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, %FALSE otherwise.
4050 g_file_set_attribute_string (GFile *file,
4051 const char *attribute,
4053 GFileQueryInfoFlags flags,
4054 GCancellable *cancellable,
4057 return g_file_set_attribute (file, attribute,
4058 G_FILE_ATTRIBUTE_TYPE_STRING, (gpointer)value,
4059 flags, cancellable, error);
4063 * g_file_set_attribute_byte_string:
4064 * @file: input #GFile.
4065 * @attribute: a string containing the attribute's name.
4066 * @value: a string containing the attribute's new value.
4067 * @flags: a #GFileQueryInfoFlags.
4068 * @cancellable: optional #GCancellable object, %NULL to ignore.
4069 * @error: a #GError, or %NULL
4071 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value.
4072 * 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_byte_string (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_BYTE_STRING, (gpointer)value,
4092 flags, cancellable, error);
4096 * g_file_set_attribute_uint32:
4097 * @file: input #GFile.
4098 * @attribute: a string containing the attribute's name.
4099 * @value: a #guint32 containing the attribute's new value.
4100 * @flags: a #GFileQueryInfoFlags.
4101 * @cancellable: optional #GCancellable object, %NULL to ignore.
4102 * @error: a #GError, or %NULL
4104 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 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_uint32 (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_UINT32, &value,
4124 flags, cancellable, error);
4128 * g_file_set_attribute_int32:
4129 * @file: input #GFile.
4130 * @attribute: a string containing the attribute's name.
4131 * @value: a #gint32 containing the attribute's new value.
4132 * @flags: a #GFileQueryInfoFlags.
4133 * @cancellable: optional #GCancellable object, %NULL to ignore.
4134 * @error: a #GError, or %NULL
4136 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 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_int32 (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_INT32, &value,
4156 flags, cancellable, error);
4160 * g_file_set_attribute_uint64:
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: optional #GCancellable object, %NULL to ignore.
4166 * @error: a #GError, or %NULL
4168 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 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 to @value
4176 * in the @file, %FALSE otherwise.
4179 g_file_set_attribute_uint64 (GFile *file,
4180 const char *attribute,
4182 GFileQueryInfoFlags flags,
4183 GCancellable *cancellable,
4186 return g_file_set_attribute (file, attribute,
4187 G_FILE_ATTRIBUTE_TYPE_UINT64, &value,
4188 flags, cancellable, error);
4192 * g_file_set_attribute_int64:
4193 * @file: input #GFile.
4194 * @attribute: a string containing the attribute's name.
4195 * @value: a #guint64 containing the attribute's new value.
4196 * @flags: a #GFileQueryInfoFlags.
4197 * @cancellable: optional #GCancellable object, %NULL to ignore.
4198 * @error: a #GError, or %NULL
4200 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value.
4201 * If @attribute is of a different type, this operation will fail.
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 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
4210 g_file_set_attribute_int64 (GFile *file,
4211 const char *attribute,
4213 GFileQueryInfoFlags flags,
4214 GCancellable *cancellable,
4217 return g_file_set_attribute (file, attribute,
4218 G_FILE_ATTRIBUTE_TYPE_INT64, &value,
4219 flags, cancellable, error);
4223 * g_file_mount_mountable:
4224 * @file: input #GFile.
4225 * @flags: flags affecting the operation
4226 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
4227 * @cancellable: optional #GCancellable object, %NULL to ignore.
4228 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4229 * @user_data: the data to pass to callback function
4231 * Mounts a file of type G_FILE_TYPE_MOUNTABLE.
4232 * Using @mount_operation, you can request callbacks when, for instance,
4233 * passwords are needed during authentication.
4235 * If @cancellable is not %NULL, then the operation can be cancelled by
4236 * triggering the cancellable object from another thread. If the operation
4237 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4239 * When the operation is finished, @callback will be called. You can then call
4240 * g_file_mount_mountable_finish() to get the result of the operation.
4243 g_file_mount_mountable (GFile *file,
4244 GMountMountFlags flags,
4245 GMountOperation *mount_operation,
4246 GCancellable *cancellable,
4247 GAsyncReadyCallback callback,
4252 g_return_if_fail (G_IS_FILE (file));
4254 iface = G_FILE_GET_IFACE (file);
4256 if (iface->mount_mountable == NULL)
4258 g_simple_async_report_error_in_idle (G_OBJECT (file),
4262 G_IO_ERROR_NOT_SUPPORTED,
4263 _("Operation not supported"));
4267 (* iface->mount_mountable) (file,
4276 * g_file_mount_mountable_finish:
4277 * @file: input #GFile.
4278 * @result: a #GAsyncResult.
4279 * @error: a #GError, or %NULL
4281 * Finishes a mount operation. See g_file_mount_mountable() for details.
4283 * Finish an asynchronous mount operation that was started
4284 * with g_file_mount_mountable().
4286 * Returns: (transfer full): a #GFile or %NULL on error.
4287 * Free the returned object with g_object_unref().
4290 g_file_mount_mountable_finish (GFile *file,
4291 GAsyncResult *result,
4296 g_return_val_if_fail (G_IS_FILE (file), NULL);
4297 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
4299 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4301 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4302 if (g_simple_async_result_propagate_error (simple, error))
4306 iface = G_FILE_GET_IFACE (file);
4307 return (* iface->mount_mountable_finish) (file, result, error);
4311 * g_file_unmount_mountable:
4312 * @file: input #GFile.
4313 * @flags: flags affecting the operation
4314 * @cancellable: optional #GCancellable object, %NULL to ignore.
4315 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4316 * @user_data: the data to pass to callback function
4318 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
4320 * If @cancellable is not %NULL, then the operation can be cancelled by
4321 * triggering the cancellable object from another thread. If the operation
4322 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4324 * When the operation is finished, @callback will be called. You can then call
4325 * g_file_unmount_mountable_finish() to get the result of the operation.
4327 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation() instead.
4330 g_file_unmount_mountable (GFile *file,
4331 GMountUnmountFlags flags,
4332 GCancellable *cancellable,
4333 GAsyncReadyCallback callback,
4338 g_return_if_fail (G_IS_FILE (file));
4340 iface = G_FILE_GET_IFACE (file);
4342 if (iface->unmount_mountable == NULL)
4344 g_simple_async_report_error_in_idle (G_OBJECT (file),
4348 G_IO_ERROR_NOT_SUPPORTED,
4349 _("Operation not supported"));
4353 (* iface->unmount_mountable) (file,
4361 * g_file_unmount_mountable_finish:
4362 * @file: input #GFile.
4363 * @result: a #GAsyncResult.
4364 * @error: a #GError, or %NULL
4366 * Finishes an unmount operation, see g_file_unmount_mountable() for details.
4368 * Finish an asynchronous unmount operation that was started
4369 * with g_file_unmount_mountable().
4371 * Returns: %TRUE if the operation finished successfully. %FALSE
4374 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation_finish() instead.
4377 g_file_unmount_mountable_finish (GFile *file,
4378 GAsyncResult *result,
4383 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4384 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4386 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4388 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4389 if (g_simple_async_result_propagate_error (simple, error))
4393 iface = G_FILE_GET_IFACE (file);
4394 return (* iface->unmount_mountable_finish) (file, result, error);
4398 * g_file_unmount_mountable_with_operation:
4399 * @file: input #GFile.
4400 * @flags: flags affecting the operation
4401 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
4402 * @cancellable: optional #GCancellable object, %NULL to ignore.
4403 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4404 * @user_data: the data to pass to callback function
4406 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
4408 * If @cancellable is not %NULL, then the operation can be cancelled by
4409 * triggering the cancellable object from another thread. If the operation
4410 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4412 * When the operation is finished, @callback will be called. You can then call
4413 * g_file_unmount_mountable_finish() to get the result of the operation.
4418 g_file_unmount_mountable_with_operation (GFile *file,
4419 GMountUnmountFlags flags,
4420 GMountOperation *mount_operation,
4421 GCancellable *cancellable,
4422 GAsyncReadyCallback callback,
4427 g_return_if_fail (G_IS_FILE (file));
4429 iface = G_FILE_GET_IFACE (file);
4431 if (iface->unmount_mountable == NULL && iface->unmount_mountable_with_operation == NULL)
4433 g_simple_async_report_error_in_idle (G_OBJECT (file),
4437 G_IO_ERROR_NOT_SUPPORTED,
4438 _("Operation not supported"));
4442 if (iface->unmount_mountable_with_operation != NULL)
4443 (* iface->unmount_mountable_with_operation) (file,
4450 (* iface->unmount_mountable) (file,
4458 * g_file_unmount_mountable_with_operation_finish:
4459 * @file: input #GFile.
4460 * @result: a #GAsyncResult.
4461 * @error: a #GError, or %NULL
4463 * Finishes an unmount operation, see g_file_unmount_mountable_with_operation() for details.
4465 * Finish an asynchronous unmount operation that was started
4466 * with g_file_unmount_mountable_with_operation().
4468 * Returns: %TRUE if the operation finished successfully. %FALSE
4474 g_file_unmount_mountable_with_operation_finish (GFile *file,
4475 GAsyncResult *result,
4480 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4481 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4483 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4485 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4486 if (g_simple_async_result_propagate_error (simple, error))
4490 iface = G_FILE_GET_IFACE (file);
4491 if (iface->unmount_mountable_with_operation_finish != NULL)
4492 return (* iface->unmount_mountable_with_operation_finish) (file, result, error);
4494 return (* iface->unmount_mountable_finish) (file, result, error);
4498 * g_file_eject_mountable:
4499 * @file: input #GFile.
4500 * @flags: flags affecting the operation
4501 * @cancellable: optional #GCancellable object, %NULL to ignore.
4502 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4503 * @user_data: the data to pass to callback function
4505 * Starts an asynchronous eject on a mountable.
4506 * When this operation has completed, @callback will be called with
4507 * @user_user data, and the operation can be finalized with
4508 * g_file_eject_mountable_finish().
4510 * If @cancellable is not %NULL, then the operation can be cancelled by
4511 * triggering the cancellable object from another thread. If the operation
4512 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4514 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation() instead.
4517 g_file_eject_mountable (GFile *file,
4518 GMountUnmountFlags flags,
4519 GCancellable *cancellable,
4520 GAsyncReadyCallback callback,
4525 g_return_if_fail (G_IS_FILE (file));
4527 iface = G_FILE_GET_IFACE (file);
4529 if (iface->eject_mountable == NULL)
4531 g_simple_async_report_error_in_idle (G_OBJECT (file),
4535 G_IO_ERROR_NOT_SUPPORTED,
4536 _("Operation not supported"));
4540 (* iface->eject_mountable) (file,
4548 * g_file_eject_mountable_finish:
4549 * @file: input #GFile.
4550 * @result: a #GAsyncResult.
4551 * @error: a #GError, or %NULL
4553 * Finishes an asynchronous eject operation started by
4554 * g_file_eject_mountable().
4556 * Returns: %TRUE if the @file was ejected successfully. %FALSE
4559 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation_finish() instead.
4562 g_file_eject_mountable_finish (GFile *file,
4563 GAsyncResult *result,
4568 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4569 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4571 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4573 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4574 if (g_simple_async_result_propagate_error (simple, error))
4578 iface = G_FILE_GET_IFACE (file);
4579 return (* iface->eject_mountable_finish) (file, result, error);
4583 * g_file_eject_mountable_with_operation:
4584 * @file: input #GFile.
4585 * @flags: flags affecting the operation
4586 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
4587 * @cancellable: optional #GCancellable object, %NULL to ignore.
4588 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4589 * @user_data: the data to pass to callback function
4591 * Starts an asynchronous eject on a mountable.
4592 * When this operation has completed, @callback will be called with
4593 * @user_user data, and the operation can be finalized with
4594 * g_file_eject_mountable_with_operation_finish().
4596 * If @cancellable is not %NULL, then the operation can be cancelled by
4597 * triggering the cancellable object from another thread. If the operation
4598 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4603 g_file_eject_mountable_with_operation (GFile *file,
4604 GMountUnmountFlags flags,
4605 GMountOperation *mount_operation,
4606 GCancellable *cancellable,
4607 GAsyncReadyCallback callback,
4612 g_return_if_fail (G_IS_FILE (file));
4614 iface = G_FILE_GET_IFACE (file);
4616 if (iface->eject_mountable == NULL && iface->eject_mountable_with_operation == NULL)
4618 g_simple_async_report_error_in_idle (G_OBJECT (file),
4622 G_IO_ERROR_NOT_SUPPORTED,
4623 _("Operation not supported"));
4627 if (iface->eject_mountable_with_operation != NULL)
4628 (* iface->eject_mountable_with_operation) (file,
4635 (* iface->eject_mountable) (file,
4643 * g_file_eject_mountable_with_operation_finish:
4644 * @file: input #GFile.
4645 * @result: a #GAsyncResult.
4646 * @error: a #GError, or %NULL
4648 * Finishes an asynchronous eject operation started by
4649 * g_file_eject_mountable_with_operation().
4651 * Returns: %TRUE if the @file was ejected successfully. %FALSE
4657 g_file_eject_mountable_with_operation_finish (GFile *file,
4658 GAsyncResult *result,
4663 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4664 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4666 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4668 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4669 if (g_simple_async_result_propagate_error (simple, error))
4673 iface = G_FILE_GET_IFACE (file);
4674 if (iface->eject_mountable_with_operation_finish != NULL)
4675 return (* iface->eject_mountable_with_operation_finish) (file, result, error);
4677 return (* iface->eject_mountable_finish) (file, result, error);
4681 * g_file_monitor_directory:
4682 * @file: input #GFile.
4683 * @flags: a set of #GFileMonitorFlags.
4684 * @cancellable: optional #GCancellable object, %NULL to ignore.
4685 * @error: a #GError, or %NULL.
4687 * Obtains a directory monitor for the given file.
4688 * This may fail if directory monitoring is not supported.
4690 * If @cancellable is not %NULL, then the operation can be cancelled by
4691 * triggering the cancellable object from another thread. If the operation
4692 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4694 * Virtual: monitor_dir
4695 * Returns: (transfer full): a #GFileMonitor for the given @file, or %NULL on error.
4696 * Free the returned object with g_object_unref().
4699 g_file_monitor_directory (GFile *file,
4700 GFileMonitorFlags flags,
4701 GCancellable *cancellable,
4706 g_return_val_if_fail (G_IS_FILE (file), NULL);
4708 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4711 iface = G_FILE_GET_IFACE (file);
4713 if (iface->monitor_dir == NULL)
4715 g_set_error_literal (error, G_IO_ERROR,
4716 G_IO_ERROR_NOT_SUPPORTED,
4717 _("Operation not supported"));
4721 return (* iface->monitor_dir) (file, flags, cancellable, error);
4725 * g_file_monitor_file:
4726 * @file: input #GFile.
4727 * @flags: a set of #GFileMonitorFlags.
4728 * @cancellable: optional #GCancellable object, %NULL to ignore.
4729 * @error: a #GError, or %NULL.
4731 * Obtains a file monitor for the given file. If no file notification
4732 * mechanism exists, then regular polling of the file is used.
4734 * If @cancellable is not %NULL, then the operation can be cancelled by
4735 * triggering the cancellable object from another thread. If the operation
4736 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4738 * Returns: (transfer full): a #GFileMonitor for the given @file, or %NULL on error.
4739 * Free the returned object with g_object_unref().
4742 g_file_monitor_file (GFile *file,
4743 GFileMonitorFlags flags,
4744 GCancellable *cancellable,
4748 GFileMonitor *monitor;
4750 g_return_val_if_fail (G_IS_FILE (file), NULL);
4752 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4755 iface = G_FILE_GET_IFACE (file);
4759 if (iface->monitor_file)
4760 monitor = (* iface->monitor_file) (file, flags, cancellable, NULL);
4762 /* Fallback to polling */
4763 if (monitor == NULL)
4764 monitor = _g_poll_file_monitor_new (file);
4771 * @file: input #GFile
4772 * @flags: a set of #GFileMonitorFlags
4773 * @cancellable: optional #GCancellable object, %NULL to ignore
4774 * @error: a #GError, or %NULL
4776 * Obtains a file or directory monitor for the given file, depending
4777 * on the type of the file.
4779 * If @cancellable is not %NULL, then the operation can be cancelled by
4780 * triggering the cancellable object from another thread. If the operation
4781 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4783 * Returns: (transfer full): a #GFileMonitor for the given @file, or %NULL on error.
4784 * Free the returned object with g_object_unref().
4789 g_file_monitor (GFile *file,
4790 GFileMonitorFlags flags,
4791 GCancellable *cancellable,
4794 if (g_file_query_file_type (file, 0, cancellable) == G_FILE_TYPE_DIRECTORY)
4795 return g_file_monitor_directory (file, flags, cancellable, error);
4797 return g_file_monitor_file (file, flags, cancellable, error);
4800 /********************************************
4801 * Default implementation of async ops *
4802 ********************************************/
4806 GFileQueryInfoFlags flags;
4808 } QueryInfoAsyncData;
4811 query_info_data_free (QueryInfoAsyncData *data)
4814 g_object_unref (data->info);
4815 g_free (data->attributes);
4820 query_info_async_thread (GSimpleAsyncResult *res,
4822 GCancellable *cancellable)
4824 GError *error = NULL;
4825 QueryInfoAsyncData *data;
4828 data = g_simple_async_result_get_op_res_gpointer (res);
4830 info = g_file_query_info (G_FILE (object), data->attributes, data->flags, cancellable, &error);
4834 g_simple_async_result_set_from_error (res, error);
4835 g_error_free (error);
4842 g_file_real_query_info_async (GFile *file,
4843 const char *attributes,
4844 GFileQueryInfoFlags flags,
4846 GCancellable *cancellable,
4847 GAsyncReadyCallback callback,
4850 GSimpleAsyncResult *res;
4851 QueryInfoAsyncData *data;
4853 data = g_new0 (QueryInfoAsyncData, 1);
4854 data->attributes = g_strdup (attributes);
4855 data->flags = flags;
4857 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_query_info_async);
4858 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_info_data_free);
4860 g_simple_async_result_run_in_thread (res, query_info_async_thread, io_priority, cancellable);
4861 g_object_unref (res);
4865 g_file_real_query_info_finish (GFile *file,
4869 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4870 QueryInfoAsyncData *data;
4872 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_info_async);
4874 data = g_simple_async_result_get_op_res_gpointer (simple);
4876 return g_object_ref (data->info);
4884 } QueryFilesystemInfoAsyncData;
4887 query_filesystem_info_data_free (QueryFilesystemInfoAsyncData *data)
4890 g_object_unref (data->info);
4891 g_free (data->attributes);
4896 query_filesystem_info_async_thread (GSimpleAsyncResult *res,
4898 GCancellable *cancellable)
4900 GError *error = NULL;
4901 QueryFilesystemInfoAsyncData *data;
4904 data = g_simple_async_result_get_op_res_gpointer (res);
4906 info = g_file_query_filesystem_info (G_FILE (object), data->attributes, cancellable, &error);
4910 g_simple_async_result_set_from_error (res, error);
4911 g_error_free (error);
4918 g_file_real_query_filesystem_info_async (GFile *file,
4919 const char *attributes,
4921 GCancellable *cancellable,
4922 GAsyncReadyCallback callback,
4925 GSimpleAsyncResult *res;
4926 QueryFilesystemInfoAsyncData *data;
4928 data = g_new0 (QueryFilesystemInfoAsyncData, 1);
4929 data->attributes = g_strdup (attributes);
4931 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_query_filesystem_info_async);
4932 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_filesystem_info_data_free);
4934 g_simple_async_result_run_in_thread (res, query_filesystem_info_async_thread, io_priority, cancellable);
4935 g_object_unref (res);
4939 g_file_real_query_filesystem_info_finish (GFile *file,
4943 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4944 QueryFilesystemInfoAsyncData *data;
4946 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_filesystem_info_async);
4948 data = g_simple_async_result_get_op_res_gpointer (simple);
4950 return g_object_ref (data->info);
4957 GFileQueryInfoFlags flags;
4958 GFileEnumerator *enumerator;
4959 } EnumerateChildrenAsyncData;
4962 enumerate_children_data_free (EnumerateChildrenAsyncData *data)
4964 if (data->enumerator)
4965 g_object_unref (data->enumerator);
4966 g_free (data->attributes);
4971 enumerate_children_async_thread (GSimpleAsyncResult *res,
4973 GCancellable *cancellable)
4975 GError *error = NULL;
4976 EnumerateChildrenAsyncData *data;
4977 GFileEnumerator *enumerator;
4979 data = g_simple_async_result_get_op_res_gpointer (res);
4981 enumerator = g_file_enumerate_children (G_FILE (object), data->attributes, data->flags, cancellable, &error);
4983 if (enumerator == NULL)
4985 g_simple_async_result_set_from_error (res, error);
4986 g_error_free (error);
4989 data->enumerator = enumerator;
4993 g_file_real_enumerate_children_async (GFile *file,
4994 const char *attributes,
4995 GFileQueryInfoFlags flags,
4997 GCancellable *cancellable,
4998 GAsyncReadyCallback callback,
5001 GSimpleAsyncResult *res;
5002 EnumerateChildrenAsyncData *data;
5004 data = g_new0 (EnumerateChildrenAsyncData, 1);
5005 data->attributes = g_strdup (attributes);
5006 data->flags = flags;
5008 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_enumerate_children_async);
5009 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)enumerate_children_data_free);
5011 g_simple_async_result_run_in_thread (res, enumerate_children_async_thread, io_priority, cancellable);
5012 g_object_unref (res);
5015 static GFileEnumerator *
5016 g_file_real_enumerate_children_finish (GFile *file,
5020 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5021 EnumerateChildrenAsyncData *data;
5023 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_enumerate_children_async);
5025 data = g_simple_async_result_get_op_res_gpointer (simple);
5026 if (data->enumerator)
5027 return g_object_ref (data->enumerator);
5033 open_read_async_thread (GSimpleAsyncResult *res,
5035 GCancellable *cancellable)
5038 GFileInputStream *stream;
5039 GError *error = NULL;
5041 iface = G_FILE_GET_IFACE (object);
5043 if (iface->read_fn == NULL)
5045 g_set_error_literal (&error, G_IO_ERROR,
5046 G_IO_ERROR_NOT_SUPPORTED,
5047 _("Operation not supported"));
5049 g_simple_async_result_set_from_error (res, error);
5050 g_error_free (error);
5055 stream = iface->read_fn (G_FILE (object), cancellable, &error);
5059 g_simple_async_result_set_from_error (res, error);
5060 g_error_free (error);
5063 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5067 g_file_real_read_async (GFile *file,
5069 GCancellable *cancellable,
5070 GAsyncReadyCallback callback,
5073 GSimpleAsyncResult *res;
5075 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_read_async);
5077 g_simple_async_result_run_in_thread (res, open_read_async_thread, io_priority, cancellable);
5078 g_object_unref (res);
5081 static GFileInputStream *
5082 g_file_real_read_finish (GFile *file,
5086 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5089 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_read_async);
5091 op = g_simple_async_result_get_op_res_gpointer (simple);
5093 return g_object_ref (op);
5099 append_to_async_thread (GSimpleAsyncResult *res,
5101 GCancellable *cancellable)
5104 GFileCreateFlags *data;
5105 GFileOutputStream *stream;
5106 GError *error = NULL;
5108 iface = G_FILE_GET_IFACE (object);
5110 data = g_simple_async_result_get_op_res_gpointer (res);
5112 stream = iface->append_to (G_FILE (object), *data, cancellable, &error);
5116 g_simple_async_result_set_from_error (res, error);
5117 g_error_free (error);
5120 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5124 g_file_real_append_to_async (GFile *file,
5125 GFileCreateFlags flags,
5127 GCancellable *cancellable,
5128 GAsyncReadyCallback callback,
5131 GFileCreateFlags *data;
5132 GSimpleAsyncResult *res;
5134 data = g_new0 (GFileCreateFlags, 1);
5137 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_append_to_async);
5138 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
5140 g_simple_async_result_run_in_thread (res, append_to_async_thread, io_priority, cancellable);
5141 g_object_unref (res);
5144 static GFileOutputStream *
5145 g_file_real_append_to_finish (GFile *file,
5149 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5152 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_append_to_async);
5154 op = g_simple_async_result_get_op_res_gpointer (simple);
5156 return g_object_ref (op);
5162 create_async_thread (GSimpleAsyncResult *res,
5164 GCancellable *cancellable)
5167 GFileCreateFlags *data;
5168 GFileOutputStream *stream;
5169 GError *error = NULL;
5171 iface = G_FILE_GET_IFACE (object);
5173 data = g_simple_async_result_get_op_res_gpointer (res);
5175 stream = iface->create (G_FILE (object), *data, cancellable, &error);
5179 g_simple_async_result_set_from_error (res, error);
5180 g_error_free (error);
5183 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5187 g_file_real_create_async (GFile *file,
5188 GFileCreateFlags flags,
5190 GCancellable *cancellable,
5191 GAsyncReadyCallback callback,
5194 GFileCreateFlags *data;
5195 GSimpleAsyncResult *res;
5197 data = g_new0 (GFileCreateFlags, 1);
5200 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_create_async);
5201 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
5203 g_simple_async_result_run_in_thread (res, create_async_thread, io_priority, cancellable);
5204 g_object_unref (res);
5207 static GFileOutputStream *
5208 g_file_real_create_finish (GFile *file,
5212 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5215 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_async);
5217 op = g_simple_async_result_get_op_res_gpointer (simple);
5219 return g_object_ref (op);
5225 GFileOutputStream *stream;
5227 gboolean make_backup;
5228 GFileCreateFlags flags;
5232 replace_async_data_free (ReplaceAsyncData *data)
5235 g_object_unref (data->stream);
5236 g_free (data->etag);
5241 replace_async_thread (GSimpleAsyncResult *res,
5243 GCancellable *cancellable)
5246 GFileOutputStream *stream;
5247 GError *error = NULL;
5248 ReplaceAsyncData *data;
5250 iface = G_FILE_GET_IFACE (object);
5252 data = g_simple_async_result_get_op_res_gpointer (res);
5254 stream = iface->replace (G_FILE (object),
5263 g_simple_async_result_set_from_error (res, error);
5264 g_error_free (error);
5267 data->stream = stream;
5271 g_file_real_replace_async (GFile *file,
5273 gboolean make_backup,
5274 GFileCreateFlags flags,
5276 GCancellable *cancellable,
5277 GAsyncReadyCallback callback,
5280 GSimpleAsyncResult *res;
5281 ReplaceAsyncData *data;
5283 data = g_new0 (ReplaceAsyncData, 1);
5284 data->etag = g_strdup (etag);
5285 data->make_backup = make_backup;
5286 data->flags = flags;
5288 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_replace_async);
5289 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_async_data_free);
5291 g_simple_async_result_run_in_thread (res, replace_async_thread, io_priority, cancellable);
5292 g_object_unref (res);
5295 static GFileOutputStream *
5296 g_file_real_replace_finish (GFile *file,
5300 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5301 ReplaceAsyncData *data;
5303 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_async);
5305 data = g_simple_async_result_get_op_res_gpointer (simple);
5307 return g_object_ref (data->stream);
5313 open_readwrite_async_thread (GSimpleAsyncResult *res,
5315 GCancellable *cancellable)
5318 GFileIOStream *stream;
5319 GError *error = NULL;
5321 iface = G_FILE_GET_IFACE (object);
5323 if (iface->open_readwrite == NULL)
5325 g_set_error_literal (&error, G_IO_ERROR,
5326 G_IO_ERROR_NOT_SUPPORTED,
5327 _("Operation not supported"));
5329 g_simple_async_result_set_from_error (res, error);
5330 g_error_free (error);
5335 stream = iface->open_readwrite (G_FILE (object), cancellable, &error);
5339 g_simple_async_result_set_from_error (res, error);
5340 g_error_free (error);
5343 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5347 g_file_real_open_readwrite_async (GFile *file,
5349 GCancellable *cancellable,
5350 GAsyncReadyCallback callback,
5353 GSimpleAsyncResult *res;
5355 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_open_readwrite_async);
5357 g_simple_async_result_run_in_thread (res, open_readwrite_async_thread, io_priority, cancellable);
5358 g_object_unref (res);
5361 static GFileIOStream *
5362 g_file_real_open_readwrite_finish (GFile *file,
5366 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5369 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_open_readwrite_async);
5371 op = g_simple_async_result_get_op_res_gpointer (simple);
5373 return g_object_ref (op);
5379 create_readwrite_async_thread (GSimpleAsyncResult *res,
5381 GCancellable *cancellable)
5384 GFileCreateFlags *data;
5385 GFileIOStream *stream;
5386 GError *error = NULL;
5388 iface = G_FILE_GET_IFACE (object);
5390 data = g_simple_async_result_get_op_res_gpointer (res);
5392 if (iface->create_readwrite == NULL)
5394 g_set_error_literal (&error, G_IO_ERROR,
5395 G_IO_ERROR_NOT_SUPPORTED,
5396 _("Operation not supported"));
5398 g_simple_async_result_set_from_error (res, error);
5399 g_error_free (error);
5404 stream = iface->create_readwrite (G_FILE (object), *data, cancellable, &error);
5408 g_simple_async_result_set_from_error (res, error);
5409 g_error_free (error);
5412 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5416 g_file_real_create_readwrite_async (GFile *file,
5417 GFileCreateFlags flags,
5419 GCancellable *cancellable,
5420 GAsyncReadyCallback callback,
5423 GFileCreateFlags *data;
5424 GSimpleAsyncResult *res;
5426 data = g_new0 (GFileCreateFlags, 1);
5429 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_create_readwrite_async);
5430 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
5432 g_simple_async_result_run_in_thread (res, create_readwrite_async_thread, io_priority, cancellable);
5433 g_object_unref (res);
5436 static GFileIOStream *
5437 g_file_real_create_readwrite_finish (GFile *file,
5441 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5444 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_readwrite_async);
5446 op = g_simple_async_result_get_op_res_gpointer (simple);
5448 return g_object_ref (op);
5454 GFileIOStream *stream;
5456 gboolean make_backup;
5457 GFileCreateFlags flags;
5458 } ReplaceRWAsyncData;
5461 replace_rw_async_data_free (ReplaceRWAsyncData *data)
5464 g_object_unref (data->stream);
5465 g_free (data->etag);
5470 replace_readwrite_async_thread (GSimpleAsyncResult *res,
5472 GCancellable *cancellable)
5475 GFileIOStream *stream;
5476 GError *error = NULL;
5477 ReplaceRWAsyncData *data;
5479 iface = G_FILE_GET_IFACE (object);
5481 data = g_simple_async_result_get_op_res_gpointer (res);
5483 stream = iface->replace_readwrite (G_FILE (object),
5492 g_simple_async_result_set_from_error (res, error);
5493 g_error_free (error);
5496 data->stream = stream;
5500 g_file_real_replace_readwrite_async (GFile *file,
5502 gboolean make_backup,
5503 GFileCreateFlags flags,
5505 GCancellable *cancellable,
5506 GAsyncReadyCallback callback,
5509 GSimpleAsyncResult *res;
5510 ReplaceRWAsyncData *data;
5512 data = g_new0 (ReplaceRWAsyncData, 1);
5513 data->etag = g_strdup (etag);
5514 data->make_backup = make_backup;
5515 data->flags = flags;
5517 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_replace_readwrite_async);
5518 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_rw_async_data_free);
5520 g_simple_async_result_run_in_thread (res, replace_readwrite_async_thread, io_priority, cancellable);
5521 g_object_unref (res);
5524 static GFileIOStream *
5525 g_file_real_replace_readwrite_finish (GFile *file,
5529 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5530 ReplaceRWAsyncData *data;
5532 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_readwrite_async);
5534 data = g_simple_async_result_get_op_res_gpointer (simple);
5536 return g_object_ref (data->stream);
5544 } SetDisplayNameAsyncData;
5547 set_display_name_data_free (SetDisplayNameAsyncData *data)
5549 g_free (data->name);
5551 g_object_unref (data->file);
5556 set_display_name_async_thread (GSimpleAsyncResult *res,
5558 GCancellable *cancellable)
5560 GError *error = NULL;
5561 SetDisplayNameAsyncData *data;
5564 data = g_simple_async_result_get_op_res_gpointer (res);
5566 file = g_file_set_display_name (G_FILE (object), data->name, cancellable, &error);
5570 g_simple_async_result_set_from_error (res, error);
5571 g_error_free (error);
5578 g_file_real_set_display_name_async (GFile *file,
5579 const char *display_name,
5581 GCancellable *cancellable,
5582 GAsyncReadyCallback callback,
5585 GSimpleAsyncResult *res;
5586 SetDisplayNameAsyncData *data;
5588 data = g_new0 (SetDisplayNameAsyncData, 1);
5589 data->name = g_strdup (display_name);
5591 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_set_display_name_async);
5592 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)set_display_name_data_free);
5594 g_simple_async_result_run_in_thread (res, set_display_name_async_thread, io_priority, cancellable);
5595 g_object_unref (res);
5599 g_file_real_set_display_name_finish (GFile *file,
5603 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5604 SetDisplayNameAsyncData *data;
5606 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_display_name_async);
5608 data = g_simple_async_result_get_op_res_gpointer (simple);
5610 return g_object_ref (data->file);
5616 GFileQueryInfoFlags flags;
5623 set_info_data_free (SetInfoAsyncData *data)
5626 g_object_unref (data->info);
5628 g_error_free (data->error);
5633 set_info_async_thread (GSimpleAsyncResult *res,
5635 GCancellable *cancellable)
5637 SetInfoAsyncData *data;
5639 data = g_simple_async_result_get_op_res_gpointer (res);
5642 data->res = g_file_set_attributes_from_info (G_FILE (object),
5650 g_file_real_set_attributes_async (GFile *file,
5652 GFileQueryInfoFlags flags,
5654 GCancellable *cancellable,
5655 GAsyncReadyCallback callback,
5658 GSimpleAsyncResult *res;
5659 SetInfoAsyncData *data;
5661 data = g_new0 (SetInfoAsyncData, 1);
5662 data->info = g_file_info_dup (info);
5663 data->flags = flags;
5665 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_set_attributes_async);
5666 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)set_info_data_free);
5668 g_simple_async_result_run_in_thread (res, set_info_async_thread, io_priority, cancellable);
5669 g_object_unref (res);
5673 g_file_real_set_attributes_finish (GFile *file,
5678 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5679 SetInfoAsyncData *data;
5681 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_attributes_async);
5683 data = g_simple_async_result_get_op_res_gpointer (simple);
5686 *info = g_object_ref (data->info);
5688 if (error != NULL && data->error)
5689 *error = g_error_copy (data->error);
5695 find_enclosing_mount_async_thread (GSimpleAsyncResult *res,
5697 GCancellable *cancellable)
5699 GError *error = NULL;
5702 mount = g_file_find_enclosing_mount (G_FILE (object), cancellable, &error);
5706 g_simple_async_result_set_from_error (res, error);
5707 g_error_free (error);
5710 g_simple_async_result_set_op_res_gpointer (res, mount, (GDestroyNotify)g_object_unref);
5714 g_file_real_find_enclosing_mount_async (GFile *file,
5716 GCancellable *cancellable,
5717 GAsyncReadyCallback callback,
5720 GSimpleAsyncResult *res;
5722 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_find_enclosing_mount_async);
5724 g_simple_async_result_run_in_thread (res, find_enclosing_mount_async_thread, io_priority, cancellable);
5725 g_object_unref (res);
5729 g_file_real_find_enclosing_mount_finish (GFile *file,
5733 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5736 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_find_enclosing_mount_async);
5738 mount = g_simple_async_result_get_op_res_gpointer (simple);
5739 return g_object_ref (mount);
5746 GFileCopyFlags flags;
5747 GFileProgressCallback progress_cb;
5748 gpointer progress_cb_data;
5749 GIOSchedulerJob *job;
5753 copy_async_data_free (CopyAsyncData *data)
5755 g_object_unref (data->source);
5756 g_object_unref (data->destination);
5761 CopyAsyncData *data;
5762 goffset current_num_bytes;
5763 goffset total_num_bytes;
5767 copy_async_progress_in_main (gpointer user_data)
5769 ProgressData *progress = user_data;
5770 CopyAsyncData *data = progress->data;
5772 data->progress_cb (progress->current_num_bytes,
5773 progress->total_num_bytes,
5774 data->progress_cb_data);
5780 mainloop_barrier (gpointer user_data)
5782 /* Does nothing, but ensures all queued idles before
5789 copy_async_progress_callback (goffset current_num_bytes,
5790 goffset total_num_bytes,
5793 CopyAsyncData *data = user_data;
5794 ProgressData *progress;
5796 progress = g_new (ProgressData, 1);
5797 progress->data = data;
5798 progress->current_num_bytes = current_num_bytes;
5799 progress->total_num_bytes = total_num_bytes;
5801 g_io_scheduler_job_send_to_mainloop_async (data->job,
5802 copy_async_progress_in_main,
5808 copy_async_thread (GIOSchedulerJob *job,
5809 GCancellable *cancellable,
5812 GSimpleAsyncResult *res;
5813 CopyAsyncData *data;
5818 data = g_simple_async_result_get_op_res_gpointer (res);
5822 result = g_file_copy (data->source,
5826 (data->progress_cb != NULL) ? copy_async_progress_callback : NULL,
5830 /* Ensure all progress callbacks are done running in main thread */
5831 if (data->progress_cb != NULL)
5832 g_io_scheduler_job_send_to_mainloop (job,
5838 g_simple_async_result_set_from_error (res, error);
5839 g_error_free (error);
5842 g_simple_async_result_complete_in_idle (res);
5848 g_file_real_copy_async (GFile *source,
5850 GFileCopyFlags flags,
5852 GCancellable *cancellable,
5853 GFileProgressCallback progress_callback,
5854 gpointer progress_callback_data,
5855 GAsyncReadyCallback callback,
5858 GSimpleAsyncResult *res;
5859 CopyAsyncData *data;
5861 data = g_new0 (CopyAsyncData, 1);
5862 data->source = g_object_ref (source);
5863 data->destination = g_object_ref (destination);
5864 data->flags = flags;
5865 data->progress_cb = progress_callback;
5866 data->progress_cb_data = progress_callback_data;
5868 res = g_simple_async_result_new (G_OBJECT (source), callback, user_data, g_file_real_copy_async);
5869 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)copy_async_data_free);
5871 g_io_scheduler_push_job (copy_async_thread, res, g_object_unref, io_priority, cancellable);
5875 g_file_real_copy_finish (GFile *file,
5879 /* Error handled in g_file_copy_finish() */
5884 /********************************************
5885 * Default VFS operations *
5886 ********************************************/
5889 * g_file_new_for_path:
5890 * @path: a string containing a relative or absolute path. The string
5891 * must be encoded in the glib filename encoding.
5893 * Constructs a #GFile for a given path. This operation never
5894 * fails, but the returned object might not support any I/O
5895 * operation if @path is malformed.
5897 * Returns: (transfer full): a new #GFile for the given @path.
5900 g_file_new_for_path (const char *path)
5902 g_return_val_if_fail (path != NULL, NULL);
5904 return g_vfs_get_file_for_path (g_vfs_get_default (), path);
5908 * g_file_new_for_uri:
5909 * @uri: a UTF8 string containing a URI.
5911 * Constructs a #GFile for a given URI. This operation never
5912 * fails, but the returned object might not support any I/O
5913 * operation if @uri is malformed or if the uri type is
5916 * Returns: (transfer full): a #GFile for the given @uri.
5919 g_file_new_for_uri (const char *uri)
5921 g_return_val_if_fail (uri != NULL, NULL);
5923 return g_vfs_get_file_for_uri (g_vfs_get_default (), uri);
5927 * g_file_parse_name:
5928 * @parse_name: a file name or path to be parsed.
5930 * Constructs a #GFile with the given @parse_name (i.e. something given by g_file_get_parse_name()).
5931 * This operation never fails, but the returned object might not support any I/O
5932 * operation if the @parse_name cannot be parsed.
5934 * Returns: (transfer full): a new #GFile.
5937 g_file_parse_name (const char *parse_name)
5939 g_return_val_if_fail (parse_name != NULL, NULL);
5941 return g_vfs_parse_name (g_vfs_get_default (), parse_name);
5945 is_valid_scheme_character (char c)
5947 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
5950 /* Following RFC 2396, valid schemes are built like:
5951 * scheme = alpha *( alpha | digit | "+" | "-" | "." )
5954 has_valid_scheme (const char *uri)
5960 if (!g_ascii_isalpha (*p))
5965 } while (is_valid_scheme_character (*p));
5971 * g_file_new_for_commandline_arg:
5972 * @arg: a command line string.
5974 * Creates a #GFile with the given argument from the command line. The value of
5975 * @arg can be either a URI, an absolute path or a relative path resolved
5976 * relative to the current working directory.
5977 * This operation never fails, but the returned object might not support any
5978 * I/O operation if @arg points to a malformed path.
5980 * Returns: (transfer full): a new #GFile.
5983 g_file_new_for_commandline_arg (const char *arg)
5989 g_return_val_if_fail (arg != NULL, NULL);
5991 if (g_path_is_absolute (arg))
5992 return g_file_new_for_path (arg);
5994 if (has_valid_scheme (arg))
5995 return g_file_new_for_uri (arg);
5997 current_dir = g_get_current_dir ();
5998 filename = g_build_filename (current_dir, arg, NULL);
5999 g_free (current_dir);
6001 file = g_file_new_for_path (filename);
6008 * g_file_mount_enclosing_volume:
6009 * @location: input #GFile.
6010 * @flags: flags affecting the operation
6011 * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
6012 * @cancellable: optional #GCancellable object, %NULL to ignore.
6013 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
6014 * @user_data: the data to pass to callback function
6016 * Starts a @mount_operation, mounting the volume that contains the file @location.
6018 * When this operation has completed, @callback will be called with
6019 * @user_user data, and the operation can be finalized with
6020 * g_file_mount_enclosing_volume_finish().
6022 * If @cancellable is not %NULL, then the operation can be cancelled by
6023 * triggering the cancellable object from another thread. If the operation
6024 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6027 g_file_mount_enclosing_volume (GFile *location,
6028 GMountMountFlags flags,
6029 GMountOperation *mount_operation,
6030 GCancellable *cancellable,
6031 GAsyncReadyCallback callback,
6036 g_return_if_fail (G_IS_FILE (location));
6038 iface = G_FILE_GET_IFACE (location);
6040 if (iface->mount_enclosing_volume == NULL)
6042 g_simple_async_report_error_in_idle (G_OBJECT (location),
6043 callback, user_data,
6044 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
6045 _("volume doesn't implement mount"));
6050 (* iface->mount_enclosing_volume) (location, flags, mount_operation, cancellable, callback, user_data);
6055 * g_file_mount_enclosing_volume_finish:
6056 * @location: input #GFile.
6057 * @result: a #GAsyncResult.
6058 * @error: a #GError, or %NULL
6060 * Finishes a mount operation started by g_file_mount_enclosing_volume().
6062 * Returns: %TRUE if successful. If an error
6063 * has occurred, this function will return %FALSE and set @error
6064 * appropriately if present.
6067 g_file_mount_enclosing_volume_finish (GFile *location,
6068 GAsyncResult *result,
6073 g_return_val_if_fail (G_IS_FILE (location), FALSE);
6074 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
6076 if (G_IS_SIMPLE_ASYNC_RESULT (result))
6078 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
6079 if (g_simple_async_result_propagate_error (simple, error))
6083 iface = G_FILE_GET_IFACE (location);
6085 return (* iface->mount_enclosing_volume_finish) (location, result, error);
6088 /********************************************
6089 * Utility functions *
6090 ********************************************/
6093 * g_file_query_default_handler:
6094 * @file: a #GFile to open.
6095 * @cancellable: optional #GCancellable object, %NULL to ignore.
6096 * @error: a #GError, or %NULL
6098 * Returns the #GAppInfo that is registered as the default
6099 * application to handle the file specified by @file.
6101 * If @cancellable is not %NULL, then the operation can be cancelled by
6102 * triggering the cancellable object from another thread. If the operation
6103 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6105 * Returns: (transfer full): a #GAppInfo if the handle was found, %NULL if there were errors.
6106 * When you are done with it, release it with g_object_unref()
6109 g_file_query_default_handler (GFile *file,
6110 GCancellable *cancellable,
6114 const char *content_type;
6119 uri_scheme = g_file_get_uri_scheme (file);
6120 if (uri_scheme && uri_scheme[0] != '\0')
6122 appinfo = g_app_info_get_default_for_uri_scheme (uri_scheme);
6123 g_free (uri_scheme);
6125 if (appinfo != NULL)
6129 info = g_file_query_info (file,
6130 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
6139 content_type = g_file_info_get_content_type (info);
6142 /* Don't use is_native(), as we want to support fuse paths if availible */
6143 path = g_file_get_path (file);
6144 appinfo = g_app_info_get_default_for_type (content_type,
6149 g_object_unref (info);
6151 if (appinfo != NULL)
6154 g_set_error_literal (error, G_IO_ERROR,
6155 G_IO_ERROR_NOT_SUPPORTED,
6156 _("No application is registered as handling this file"));
6162 #define GET_CONTENT_BLOCK_SIZE 8192
6165 * g_file_load_contents:
6166 * @file: input #GFile.
6167 * @cancellable: optional #GCancellable object, %NULL to ignore.
6168 * @contents: (out) (transfer full): a location to place the contents of the file.
6169 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6170 * or %NULL if the length is not needed
6171 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6172 * or %NULL if the entity tag is not needed
6173 * @error: a #GError, or %NULL
6175 * Loads the content of the file into memory. The data is always
6176 * zero-terminated, but this is not included in the resultant @length.
6177 * The returned @content should be freed with g_free() when no longer
6180 * If @cancellable is not %NULL, then the operation can be cancelled by
6181 * triggering the cancellable object from another thread. If the operation
6182 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6184 * Returns: %TRUE if the @file's contents were successfully loaded.
6185 * %FALSE if there were errors.
6188 g_file_load_contents (GFile *file,
6189 GCancellable *cancellable,
6195 GFileInputStream *in;
6196 GByteArray *content;
6201 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6202 g_return_val_if_fail (contents != NULL, FALSE);
6204 in = g_file_read (file, cancellable, error);
6208 content = g_byte_array_new ();
6211 g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
6212 while ((res = g_input_stream_read (G_INPUT_STREAM (in),
6213 content->data + pos,
6214 GET_CONTENT_BLOCK_SIZE,
6215 cancellable, error)) > 0)
6218 g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
6225 info = g_file_input_stream_query_info (in,
6226 G_FILE_ATTRIBUTE_ETAG_VALUE,
6231 *etag_out = g_strdup (g_file_info_get_etag (info));
6232 g_object_unref (info);
6236 /* Ignore errors on close */
6237 g_input_stream_close (G_INPUT_STREAM (in), cancellable, NULL);
6238 g_object_unref (in);
6242 /* error is set already */
6243 g_byte_array_free (content, TRUE);
6250 /* Zero terminate (we got an extra byte allocated for this */
6251 content->data[pos] = 0;
6253 *contents = (char *)g_byte_array_free (content, FALSE);
6261 GCancellable *cancellable;
6262 GFileReadMoreCallback read_more_callback;
6263 GAsyncReadyCallback callback;
6265 GByteArray *content;
6272 load_contents_data_free (LoadContentsData *data)
6275 g_error_free (data->error);
6276 if (data->cancellable)
6277 g_object_unref (data->cancellable);
6279 g_byte_array_free (data->content, TRUE);
6280 g_free (data->etag);
6281 g_object_unref (data->file);
6286 load_contents_close_callback (GObject *obj,
6287 GAsyncResult *close_res,
6290 GInputStream *stream = G_INPUT_STREAM (obj);
6291 LoadContentsData *data = user_data;
6292 GSimpleAsyncResult *res;
6294 /* Ignore errors here, we're only reading anyway */
6295 g_input_stream_close_finish (stream, close_res, NULL);
6296 g_object_unref (stream);
6298 res = g_simple_async_result_new (G_OBJECT (data->file),
6301 g_file_load_contents_async);
6302 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)load_contents_data_free);
6303 g_simple_async_result_complete (res);
6304 g_object_unref (res);
6308 load_contents_fstat_callback (GObject *obj,
6309 GAsyncResult *stat_res,
6312 GInputStream *stream = G_INPUT_STREAM (obj);
6313 LoadContentsData *data = user_data;
6316 info = g_file_input_stream_query_info_finish (G_FILE_INPUT_STREAM (stream),
6320 data->etag = g_strdup (g_file_info_get_etag (info));
6321 g_object_unref (info);
6324 g_input_stream_close_async (stream, 0,
6326 load_contents_close_callback, data);
6330 load_contents_read_callback (GObject *obj,
6331 GAsyncResult *read_res,
6334 GInputStream *stream = G_INPUT_STREAM (obj);
6335 LoadContentsData *data = user_data;
6336 GError *error = NULL;
6339 read_size = g_input_stream_read_finish (stream, read_res, &error);
6343 /* Error or EOF, close the file */
6344 data->error = error;
6345 g_input_stream_close_async (stream, 0,
6347 load_contents_close_callback, data);
6349 else if (read_size == 0)
6351 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
6352 G_FILE_ATTRIBUTE_ETAG_VALUE,
6355 load_contents_fstat_callback,
6358 else if (read_size > 0)
6360 data->pos += read_size;
6362 g_byte_array_set_size (data->content,
6363 data->pos + GET_CONTENT_BLOCK_SIZE);
6366 if (data->read_more_callback &&
6367 !data->read_more_callback ((char *)data->content->data, data->pos, data->user_data))
6368 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
6369 G_FILE_ATTRIBUTE_ETAG_VALUE,
6372 load_contents_fstat_callback,
6375 g_input_stream_read_async (stream,
6376 data->content->data + data->pos,
6377 GET_CONTENT_BLOCK_SIZE,
6380 load_contents_read_callback,
6386 load_contents_open_callback (GObject *obj,
6387 GAsyncResult *open_res,
6390 GFile *file = G_FILE (obj);
6391 GFileInputStream *stream;
6392 LoadContentsData *data = user_data;
6393 GError *error = NULL;
6394 GSimpleAsyncResult *res;
6396 stream = g_file_read_finish (file, open_res, &error);
6400 g_byte_array_set_size (data->content,
6401 data->pos + GET_CONTENT_BLOCK_SIZE);
6402 g_input_stream_read_async (G_INPUT_STREAM (stream),
6403 data->content->data + data->pos,
6404 GET_CONTENT_BLOCK_SIZE,
6407 load_contents_read_callback,
6413 res = g_simple_async_result_new_from_error (G_OBJECT (data->file),
6417 g_simple_async_result_complete (res);
6418 g_error_free (error);
6419 load_contents_data_free (data);
6420 g_object_unref (res);
6425 * g_file_load_partial_contents_async:
6426 * @file: input #GFile.
6427 * @cancellable: optional #GCancellable object, %NULL to ignore.
6428 * @read_more_callback: a #GFileReadMoreCallback to receive partial data and to specify whether further data should be read.
6429 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6430 * @user_data: the data to pass to the callback functions.
6432 * Reads the partial contents of a file. A #GFileReadMoreCallback should be
6433 * used to stop reading from the file when appropriate, else this function
6434 * will behave exactly as g_file_load_contents_async(). This operation
6435 * can be finished by g_file_load_partial_contents_finish().
6437 * Users of this function should be aware that @user_data is passed to
6438 * both the @read_more_callback and the @callback.
6440 * If @cancellable is not %NULL, then the operation can be cancelled by
6441 * triggering the cancellable object from another thread. If the operation
6442 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6445 g_file_load_partial_contents_async (GFile *file,
6446 GCancellable *cancellable,
6447 GFileReadMoreCallback read_more_callback,
6448 GAsyncReadyCallback callback,
6451 LoadContentsData *data;
6453 g_return_if_fail (G_IS_FILE (file));
6455 data = g_new0 (LoadContentsData, 1);
6458 data->cancellable = g_object_ref (cancellable);
6459 data->read_more_callback = read_more_callback;
6460 data->callback = callback;
6461 data->user_data = user_data;
6462 data->content = g_byte_array_new ();
6463 data->file = g_object_ref (file);
6465 g_file_read_async (file,
6468 load_contents_open_callback,
6473 * g_file_load_partial_contents_finish:
6474 * @file: input #GFile.
6475 * @res: a #GAsyncResult.
6476 * @contents: (out) (transfer full): a location to place the contents of the file.
6477 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6478 * or %NULL if the length is not needed
6479 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6480 * or %NULL if the entity tag is not needed
6481 * @error: a #GError, or %NULL
6483 * Finishes an asynchronous partial load operation that was started
6484 * with g_file_load_partial_contents_async(). The data is always
6485 * zero-terminated, but this is not included in the resultant @length.
6486 * The returned @content should be freed with g_free() when no longer
6489 * Returns: %TRUE if the load was successful. If %FALSE and @error is
6490 * present, it will be set appropriately.
6493 g_file_load_partial_contents_finish (GFile *file,
6500 GSimpleAsyncResult *simple;
6501 LoadContentsData *data;
6503 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6504 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE);
6505 g_return_val_if_fail (contents != NULL, FALSE);
6507 simple = G_SIMPLE_ASYNC_RESULT (res);
6509 if (g_simple_async_result_propagate_error (simple, error))
6512 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_load_contents_async);
6514 data = g_simple_async_result_get_op_res_gpointer (simple);
6518 g_propagate_error (error, data->error);
6527 *length = data->pos;
6531 *etag_out = data->etag;
6535 /* Zero terminate */
6536 g_byte_array_set_size (data->content, data->pos + 1);
6537 data->content->data[data->pos] = 0;
6539 *contents = (char *)g_byte_array_free (data->content, FALSE);
6540 data->content = NULL;
6546 * g_file_load_contents_async:
6547 * @file: input #GFile.
6548 * @cancellable: optional #GCancellable object, %NULL to ignore.
6549 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6550 * @user_data: the data to pass to callback function
6552 * Starts an asynchronous load of the @file's contents.
6554 * For more details, see g_file_load_contents() which is
6555 * the synchronous version of this call.
6557 * When the load operation has completed, @callback will be called
6558 * with @user data. To finish the operation, call
6559 * g_file_load_contents_finish() with the #GAsyncResult returned by
6562 * If @cancellable is not %NULL, then the operation can be cancelled by
6563 * triggering the cancellable object from another thread. If the operation
6564 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6567 g_file_load_contents_async (GFile *file,
6568 GCancellable *cancellable,
6569 GAsyncReadyCallback callback,
6572 g_file_load_partial_contents_async (file,
6575 callback, user_data);
6579 * g_file_load_contents_finish:
6580 * @file: input #GFile.
6581 * @res: a #GAsyncResult.
6582 * @contents: (out) (transfer full): a location to place the contents of the file.
6583 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6584 * or %NULL if the length is not needed
6585 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6586 * or %NULL if the entity tag is not needed
6587 * @error: a #GError, or %NULL
6589 * Finishes an asynchronous load of the @file's contents.
6590 * The contents are placed in @contents, and @length is set to the
6591 * size of the @contents string. The @content should be freed with
6592 * g_free() when no longer needed. If @etag_out is present, it will be
6593 * set to the new entity tag for the @file.
6595 * Returns: %TRUE if the load was successful. If %FALSE and @error is
6596 * present, it will be set appropriately.
6599 g_file_load_contents_finish (GFile *file,
6606 return g_file_load_partial_contents_finish (file,
6615 * g_file_replace_contents:
6616 * @file: input #GFile.
6617 * @contents: a string containing the new contents for @file.
6618 * @length: the length of @contents in bytes.
6619 * @etag: (allow-none): the old <link linkend="gfile-etag">entity tag</link>
6620 * for the document, or %NULL
6621 * @make_backup: %TRUE if a backup should be created.
6622 * @flags: a set of #GFileCreateFlags.
6623 * @new_etag: (allow-none) (out): a location to a new <link linkend="gfile-etag">entity tag</link>
6624 * for the document. This should be freed with g_free() when no longer
6626 * @cancellable: optional #GCancellable object, %NULL to ignore.
6627 * @error: a #GError, or %NULL
6629 * Replaces the contents of @file with @contents of @length bytes.
6631 * If @etag is specified (not %NULL) any existing file must have that etag, or
6632 * the error %G_IO_ERROR_WRONG_ETAG will be returned.
6634 * If @make_backup is %TRUE, this function will attempt to make a backup of @file.
6636 * If @cancellable is not %NULL, then the operation can be cancelled by
6637 * triggering the cancellable object from another thread. If the operation
6638 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6640 * The returned @new_etag can be used to verify that the file hasn't changed the
6641 * next time it is saved over.
6643 * Returns: %TRUE if successful. If an error
6644 * has occurred, this function will return %FALSE and set @error
6645 * appropriately if present.
6648 g_file_replace_contents (GFile *file,
6649 const char *contents,
6652 gboolean make_backup,
6653 GFileCreateFlags flags,
6655 GCancellable *cancellable,
6658 GFileOutputStream *out;
6659 gsize pos, remainder;
6663 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6664 g_return_val_if_fail (contents != NULL, FALSE);
6666 out = g_file_replace (file, etag, make_backup, flags, cancellable, error);
6672 while (remainder > 0 &&
6673 (res = g_output_stream_write (G_OUTPUT_STREAM (out),
6675 MIN (remainder, GET_CONTENT_BLOCK_SIZE),
6683 if (remainder > 0 && res < 0)
6685 /* Ignore errors on close */
6686 g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, NULL);
6687 g_object_unref (out);
6689 /* error is set already */
6693 ret = g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, error);
6696 *new_etag = g_file_output_stream_get_etag (out);
6698 g_object_unref (out);
6706 GCancellable *cancellable;
6707 GAsyncReadyCallback callback;
6709 const char *content;
6713 } ReplaceContentsData;
6716 replace_contents_data_free (ReplaceContentsData *data)
6719 g_error_free (data->error);
6720 if (data->cancellable)
6721 g_object_unref (data->cancellable);
6722 g_object_unref (data->file);
6723 g_free (data->etag);
6728 replace_contents_close_callback (GObject *obj,
6729 GAsyncResult *close_res,
6732 GOutputStream *stream = G_OUTPUT_STREAM (obj);
6733 ReplaceContentsData *data = user_data;
6734 GSimpleAsyncResult *res;
6736 /* Ignore errors here, we're only reading anyway */
6737 g_output_stream_close_finish (stream, close_res, NULL);
6738 g_object_unref (stream);
6740 data->etag = g_file_output_stream_get_etag (G_FILE_OUTPUT_STREAM (stream));
6742 res = g_simple_async_result_new (G_OBJECT (data->file),
6745 g_file_replace_contents_async);
6746 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_contents_data_free);
6747 g_simple_async_result_complete (res);
6748 g_object_unref (res);
6752 replace_contents_write_callback (GObject *obj,
6753 GAsyncResult *read_res,
6756 GOutputStream *stream = G_OUTPUT_STREAM (obj);
6757 ReplaceContentsData *data = user_data;
6758 GError *error = NULL;
6761 write_size = g_output_stream_write_finish (stream, read_res, &error);
6763 if (write_size <= 0)
6765 /* Error or EOF, close the file */
6767 data->error = error;
6768 g_output_stream_close_async (stream, 0,
6770 replace_contents_close_callback, data);
6772 else if (write_size > 0)
6774 data->pos += write_size;
6776 if (data->pos >= data->length)
6777 g_output_stream_close_async (stream, 0,
6779 replace_contents_close_callback, data);
6781 g_output_stream_write_async (stream,
6782 data->content + data->pos,
6783 data->length - data->pos,
6786 replace_contents_write_callback,
6792 replace_contents_open_callback (GObject *obj,
6793 GAsyncResult *open_res,
6796 GFile *file = G_FILE (obj);
6797 GFileOutputStream *stream;
6798 ReplaceContentsData *data = user_data;
6799 GError *error = NULL;
6800 GSimpleAsyncResult *res;
6802 stream = g_file_replace_finish (file, open_res, &error);
6806 g_output_stream_write_async (G_OUTPUT_STREAM (stream),
6807 data->content + data->pos,
6808 data->length - data->pos,
6811 replace_contents_write_callback,
6817 res = g_simple_async_result_new_from_error (G_OBJECT (data->file),
6821 g_simple_async_result_complete (res);
6822 g_error_free (error);
6823 replace_contents_data_free (data);
6824 g_object_unref (res);
6829 * g_file_replace_contents_async:
6830 * @file: input #GFile.
6831 * @contents: string of contents to replace the file with.
6832 * @length: the length of @contents in bytes.
6833 * @etag: (allow-none): a new <link linkend="gfile-etag">entity tag</link> for the @file, or %NULL
6834 * @make_backup: %TRUE if a backup should be created.
6835 * @flags: a set of #GFileCreateFlags.
6836 * @cancellable: optional #GCancellable object, %NULL to ignore.
6837 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6838 * @user_data: the data to pass to callback function
6840 * Starts an asynchronous replacement of @file with the given
6841 * @contents of @length bytes. @etag will replace the document's
6842 * current entity tag.
6844 * When this operation has completed, @callback will be called with
6845 * @user_user data, and the operation can be finalized with
6846 * g_file_replace_contents_finish().
6848 * If @cancellable is not %NULL, then the operation can be cancelled by
6849 * triggering the cancellable object from another thread. If the operation
6850 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6852 * If @make_backup is %TRUE, this function will attempt to
6853 * make a backup of @file.
6856 g_file_replace_contents_async (GFile *file,
6857 const char *contents,
6860 gboolean make_backup,
6861 GFileCreateFlags flags,
6862 GCancellable *cancellable,
6863 GAsyncReadyCallback callback,
6866 ReplaceContentsData *data;
6868 g_return_if_fail (G_IS_FILE (file));
6869 g_return_if_fail (contents != NULL);
6871 data = g_new0 (ReplaceContentsData, 1);
6874 data->cancellable = g_object_ref (cancellable);
6875 data->callback = callback;
6876 data->user_data = user_data;
6877 data->content = contents;
6878 data->length = length;
6880 data->file = g_object_ref (file);
6882 g_file_replace_async (file,
6888 replace_contents_open_callback,
6893 * g_file_replace_contents_finish:
6894 * @file: input #GFile.
6895 * @res: a #GAsyncResult.
6896 * @new_etag: (out) (allow-none): a location of a new <link linkend="gfile-etag">entity tag</link>
6897 * for the document. This should be freed with g_free() when it is no
6898 * longer needed, or %NULL
6899 * @error: a #GError, or %NULL
6901 * Finishes an asynchronous replace of the given @file. See
6902 * g_file_replace_contents_async(). Sets @new_etag to the new entity
6903 * tag for the document, if present.
6905 * Returns: %TRUE on success, %FALSE on failure.
6908 g_file_replace_contents_finish (GFile *file,
6913 GSimpleAsyncResult *simple;
6914 ReplaceContentsData *data;
6916 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6917 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE);
6919 simple = G_SIMPLE_ASYNC_RESULT (res);
6921 if (g_simple_async_result_propagate_error (simple, error))
6924 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_replace_contents_async);
6926 data = g_simple_async_result_get_op_res_gpointer (simple);
6930 g_propagate_error (error, data->error);
6938 *new_etag = data->etag;
6939 data->etag = NULL; /* Take ownership */
6946 * g_file_start_mountable:
6947 * @file: input #GFile.
6948 * @flags: flags affecting the operation
6949 * @start_operation: a #GMountOperation, or %NULL to avoid user interaction.
6950 * @cancellable: optional #GCancellable object, %NULL to ignore.
6951 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
6952 * @user_data: the data to pass to callback function
6954 * Starts a file of type G_FILE_TYPE_MOUNTABLE.
6955 * Using @start_operation, you can request callbacks when, for instance,
6956 * passwords are needed during authentication.
6958 * If @cancellable is not %NULL, then the operation can be cancelled by
6959 * triggering the cancellable object from another thread. If the operation
6960 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6962 * When the operation is finished, @callback will be called. You can then call
6963 * g_file_mount_mountable_finish() to get the result of the operation.
6968 g_file_start_mountable (GFile *file,
6969 GDriveStartFlags flags,
6970 GMountOperation *start_operation,
6971 GCancellable *cancellable,
6972 GAsyncReadyCallback callback,
6977 g_return_if_fail (G_IS_FILE (file));
6979 iface = G_FILE_GET_IFACE (file);
6981 if (iface->start_mountable == NULL)
6983 g_simple_async_report_error_in_idle (G_OBJECT (file),
6987 G_IO_ERROR_NOT_SUPPORTED,
6988 _("Operation not supported"));
6992 (* iface->start_mountable) (file,
7001 * g_file_start_mountable_finish:
7002 * @file: input #GFile.
7003 * @result: a #GAsyncResult.
7004 * @error: a #GError, or %NULL
7006 * Finishes a start operation. See g_file_start_mountable() for details.
7008 * Finish an asynchronous start operation that was started
7009 * with g_file_start_mountable().
7011 * Returns: %TRUE if the operation finished successfully. %FALSE
7017 g_file_start_mountable_finish (GFile *file,
7018 GAsyncResult *result,
7023 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7024 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7026 if (G_IS_SIMPLE_ASYNC_RESULT (result))
7028 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
7029 if (g_simple_async_result_propagate_error (simple, error))
7033 iface = G_FILE_GET_IFACE (file);
7034 return (* iface->start_mountable_finish) (file, result, error);
7038 * g_file_stop_mountable:
7039 * @file: input #GFile.
7040 * @flags: flags affecting the operation
7041 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
7042 * @cancellable: optional #GCancellable object, %NULL to ignore.
7043 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
7044 * @user_data: the data to pass to callback function
7046 * Stops a file of type G_FILE_TYPE_MOUNTABLE.
7048 * If @cancellable is not %NULL, then the operation can be cancelled by
7049 * triggering the cancellable object from another thread. If the operation
7050 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7052 * When the operation is finished, @callback will be called. You can then call
7053 * g_file_stop_mountable_finish() to get the result of the operation.
7058 g_file_stop_mountable (GFile *file,
7059 GMountUnmountFlags flags,
7060 GMountOperation *mount_operation,
7061 GCancellable *cancellable,
7062 GAsyncReadyCallback callback,
7067 g_return_if_fail (G_IS_FILE (file));
7069 iface = G_FILE_GET_IFACE (file);
7071 if (iface->stop_mountable == NULL)
7073 g_simple_async_report_error_in_idle (G_OBJECT (file),
7077 G_IO_ERROR_NOT_SUPPORTED,
7078 _("Operation not supported"));
7082 (* iface->stop_mountable) (file,
7091 * g_file_stop_mountable_finish:
7092 * @file: input #GFile.
7093 * @result: a #GAsyncResult.
7094 * @error: a #GError, or %NULL
7096 * Finishes an stop operation, see g_file_stop_mountable() for details.
7098 * Finish an asynchronous stop operation that was started
7099 * with g_file_stop_mountable().
7101 * Returns: %TRUE if the operation finished successfully. %FALSE
7107 g_file_stop_mountable_finish (GFile *file,
7108 GAsyncResult *result,
7113 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7114 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7116 if (G_IS_SIMPLE_ASYNC_RESULT (result))
7118 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
7119 if (g_simple_async_result_propagate_error (simple, error))
7123 iface = G_FILE_GET_IFACE (file);
7124 return (* iface->stop_mountable_finish) (file, result, error);
7128 * g_file_poll_mountable:
7129 * @file: input #GFile.
7130 * @cancellable: optional #GCancellable object, %NULL to ignore.
7131 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
7132 * @user_data: the data to pass to callback function
7134 * Polls a file of type G_FILE_TYPE_MOUNTABLE.
7136 * If @cancellable is not %NULL, then the operation can be cancelled by
7137 * triggering the cancellable object from another thread. If the operation
7138 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7140 * When the operation is finished, @callback will be called. You can then call
7141 * g_file_mount_mountable_finish() to get the result of the operation.
7146 g_file_poll_mountable (GFile *file,
7147 GCancellable *cancellable,
7148 GAsyncReadyCallback callback,
7153 g_return_if_fail (G_IS_FILE (file));
7155 iface = G_FILE_GET_IFACE (file);
7157 if (iface->poll_mountable == NULL)
7159 g_simple_async_report_error_in_idle (G_OBJECT (file),
7163 G_IO_ERROR_NOT_SUPPORTED,
7164 _("Operation not supported"));
7168 (* iface->poll_mountable) (file,
7175 * g_file_poll_mountable_finish:
7176 * @file: input #GFile.
7177 * @result: a #GAsyncResult.
7178 * @error: a #GError, or %NULL
7180 * Finishes a poll operation. See g_file_poll_mountable() for details.
7182 * Finish an asynchronous poll operation that was polled
7183 * with g_file_poll_mountable().
7185 * Returns: %TRUE if the operation finished successfully. %FALSE
7191 g_file_poll_mountable_finish (GFile *file,
7192 GAsyncResult *result,
7197 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7198 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7200 if (G_IS_SIMPLE_ASYNC_RESULT (result))
7202 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
7203 if (g_simple_async_result_propagate_error (simple, error))
7207 iface = G_FILE_GET_IFACE (file);
7208 return (* iface->poll_mountable_finish) (file, result, error);
7212 * g_file_supports_thread_contexts:
7215 * Checks if @file supports <link
7216 * linkend="g-main-context-push-thread-default-context">thread-default
7217 * contexts</link>. If this returns %FALSE, you cannot perform
7218 * asynchronous operations on @file in a thread that has a
7219 * thread-default context.
7221 * Returns: Whether or not @file supports thread-default contexts.
7226 g_file_supports_thread_contexts (GFile *file)
7230 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7232 iface = G_FILE_GET_IFACE (file);
7233 return iface->supports_thread_contexts;