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: (allow-none): 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: (allow-none): optional #GCancellable object, %NULL to ignore.
888 * @callback: (scope async): a #GAsyncReadyCallback to call when the
889 * request is satisfied
890 * @user_data: (closure): the data to pass to callback function
892 * Asynchronously gets the requested information about the files in a directory. The result
893 * is a #GFileEnumerator object that will give out #GFileInfo objects for
894 * all the files in the directory.
896 * For more details, see g_file_enumerate_children() which is
897 * the synchronous version of this call.
899 * When the operation is finished, @callback will be called. You can then call
900 * g_file_enumerate_children_finish() to get the result of the operation.
903 g_file_enumerate_children_async (GFile *file,
904 const char *attributes,
905 GFileQueryInfoFlags flags,
907 GCancellable *cancellable,
908 GAsyncReadyCallback callback,
913 g_return_if_fail (G_IS_FILE (file));
915 iface = G_FILE_GET_IFACE (file);
916 (* iface->enumerate_children_async) (file,
926 * g_file_enumerate_children_finish:
927 * @file: input #GFile.
928 * @res: a #GAsyncResult.
931 * Finishes an async enumerate children operation.
932 * See g_file_enumerate_children_async().
934 * Returns: (transfer full): a #GFileEnumerator or %NULL if an error occurred.
935 * Free the returned object with g_object_unref().
938 g_file_enumerate_children_finish (GFile *file,
944 g_return_val_if_fail (G_IS_FILE (file), NULL);
945 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
947 if (G_IS_SIMPLE_ASYNC_RESULT (res))
949 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
950 if (g_simple_async_result_propagate_error (simple, error))
954 iface = G_FILE_GET_IFACE (file);
955 return (* iface->enumerate_children_finish) (file, res, error);
959 * g_file_query_exists:
960 * @file: input #GFile.
961 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
963 * Utility function to check if a particular file exists. This is
964 * implemented using g_file_query_info() and as such does blocking I/O.
966 * Note that in many cases it is racy to first check for file existence
967 * and then execute something based on the outcome of that, because the
968 * file might have been created or removed in between the operations. The
969 * general approach to handling that is to not check, but just do the
970 * operation and handle the errors as they come.
972 * As an example of race-free checking, take the case of reading a file, and
973 * if it doesn't exist, creating it. There are two racy versions: read it, and
974 * on error create it; and: check if it exists, if not create it. These
975 * can both result in two processes creating the file (with perhaps a partially
976 * written file as the result). The correct approach is to always try to create
977 * the file with g_file_create() which will either atomically create the file
978 * or fail with a G_IO_ERROR_EXISTS error.
980 * However, in many cases an existence check is useful in a user
981 * interface, for instance to make a menu item sensitive/insensitive, so that
982 * you don't have to fool users that something is possible and then just show
983 * and error dialog. If you do this, you should make sure to also handle the
984 * errors that can happen due to races when you execute the operation.
986 * Returns: %TRUE if the file exists (and can be detected without error), %FALSE otherwise (or if cancelled).
989 g_file_query_exists (GFile *file,
990 GCancellable *cancellable)
994 g_return_val_if_fail (G_IS_FILE(file), FALSE);
996 info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE,
997 G_FILE_QUERY_INFO_NONE, cancellable, NULL);
1000 g_object_unref (info);
1008 * g_file_query_file_type:
1009 * @file: input #GFile.
1010 * @flags: a set of #GFileQueryInfoFlags passed to g_file_query_info().
1011 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1013 * Utility function to inspect the #GFileType of a file. This is
1014 * implemented using g_file_query_info() and as such does blocking I/O.
1016 * The primary use case of this method is to check if a file is a regular file,
1017 * directory, or symlink.
1019 * Returns: The #GFileType of the file and #G_FILE_TYPE_UNKNOWN if the file
1025 g_file_query_file_type (GFile *file,
1026 GFileQueryInfoFlags flags,
1027 GCancellable *cancellable)
1030 GFileType file_type;
1032 g_return_val_if_fail (G_IS_FILE(file), G_FILE_TYPE_UNKNOWN);
1033 info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, flags,
1037 file_type = g_file_info_get_file_type (info);
1038 g_object_unref (info);
1041 file_type = G_FILE_TYPE_UNKNOWN;
1047 * g_file_query_info:
1048 * @file: input #GFile.
1049 * @attributes: an attribute query string.
1050 * @flags: a set of #GFileQueryInfoFlags.
1051 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1052 * @error: a #GError.
1054 * Gets the requested information about specified @file. The result
1055 * is a #GFileInfo object that contains key-value attributes (such as
1056 * the type or size of the file).
1058 * The @attributes value is a string that specifies the file attributes that
1059 * should be gathered. It is not an error if it's not possible to read a particular
1060 * requested attribute from a file - it just won't be set. @attributes should
1061 * be a comma-separated list of attributes or attribute wildcards. The wildcard "*"
1062 * means all attributes, and a wildcard like "standard::*" means all attributes in the standard
1063 * namespace. An example attribute query be "standard::*,owner::user".
1064 * The standard attributes are available as defines, like #G_FILE_ATTRIBUTE_STANDARD_NAME.
1066 * If @cancellable is not %NULL, then the operation can be cancelled by
1067 * triggering the cancellable object from another thread. If the operation
1068 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1070 * For symlinks, normally the information about the target of the
1071 * symlink is returned, rather than information about the symlink itself.
1072 * However if you pass #G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS in @flags the
1073 * information about the symlink itself will be returned. Also, for symlinks
1074 * that point to non-existing files the information about the symlink itself
1077 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1078 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1080 * Returns: (transfer full): a #GFileInfo for the given @file, or %NULL on error.
1081 * Free the returned object with g_object_unref().
1084 g_file_query_info (GFile *file,
1085 const char *attributes,
1086 GFileQueryInfoFlags flags,
1087 GCancellable *cancellable,
1092 g_return_val_if_fail (G_IS_FILE (file), NULL);
1094 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1097 iface = G_FILE_GET_IFACE (file);
1099 if (iface->query_info == NULL)
1101 g_set_error_literal (error, G_IO_ERROR,
1102 G_IO_ERROR_NOT_SUPPORTED,
1103 _("Operation not supported"));
1107 return (* iface->query_info) (file, attributes, flags, cancellable, error);
1111 * g_file_query_info_async:
1112 * @file: input #GFile.
1113 * @attributes: an attribute query string.
1114 * @flags: a set of #GFileQueryInfoFlags.
1115 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1117 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1118 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1119 * @user_data: (closure): the data to pass to callback function
1121 * Asynchronously gets the requested information about specified @file. The result
1122 * is a #GFileInfo object that contains key-value attributes (such as type or size
1125 * For more details, see g_file_query_info() which is
1126 * the synchronous version of this call.
1128 * When the operation is finished, @callback will be called. You can then call
1129 * g_file_query_info_finish() to get the result of the operation.
1132 g_file_query_info_async (GFile *file,
1133 const char *attributes,
1134 GFileQueryInfoFlags flags,
1136 GCancellable *cancellable,
1137 GAsyncReadyCallback callback,
1142 g_return_if_fail (G_IS_FILE (file));
1144 iface = G_FILE_GET_IFACE (file);
1145 (* iface->query_info_async) (file,
1155 * g_file_query_info_finish:
1156 * @file: input #GFile.
1157 * @res: a #GAsyncResult.
1158 * @error: a #GError.
1160 * Finishes an asynchronous file info query.
1161 * See g_file_query_info_async().
1163 * Returns: (transfer full): #GFileInfo for given @file or %NULL on error.
1164 * Free the returned object with g_object_unref().
1167 g_file_query_info_finish (GFile *file,
1173 g_return_val_if_fail (G_IS_FILE (file), NULL);
1174 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1176 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1178 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1179 if (g_simple_async_result_propagate_error (simple, error))
1183 iface = G_FILE_GET_IFACE (file);
1184 return (* iface->query_info_finish) (file, res, error);
1188 * g_file_query_filesystem_info:
1189 * @file: input #GFile.
1190 * @attributes: an attribute query string.
1191 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1192 * @error: a #GError.
1194 * Similar to g_file_query_info(), but obtains information
1195 * about the filesystem the @file is on, rather than the file itself.
1196 * For instance the amount of space available and the type of
1199 * The @attributes value is a string that specifies the file attributes that
1200 * should be gathered. It is not an error if it's not possible to read a particular
1201 * requested attribute from a file - it just won't be set. @attributes should
1202 * be a comma-separated list of attributes or attribute wildcards. The wildcard "*"
1203 * means all attributes, and a wildcard like "fs:*" means all attributes in the fs
1204 * namespace. The standard namespace for filesystem attributes is "fs".
1205 * Common attributes of interest are #G_FILE_ATTRIBUTE_FILESYSTEM_SIZE
1206 * (the total size of the filesystem in bytes), #G_FILE_ATTRIBUTE_FILESYSTEM_FREE (number of
1207 * bytes available), and #G_FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).
1209 * If @cancellable is not %NULL, then the operation can be cancelled by
1210 * triggering the cancellable object from another thread. If the operation
1211 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1213 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1214 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1216 * Returns: (transfer full): a #GFileInfo or %NULL if there was an error.
1217 * Free the returned object with g_object_unref().
1220 g_file_query_filesystem_info (GFile *file,
1221 const char *attributes,
1222 GCancellable *cancellable,
1227 g_return_val_if_fail (G_IS_FILE (file), NULL);
1229 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1232 iface = G_FILE_GET_IFACE (file);
1234 if (iface->query_filesystem_info == NULL)
1236 g_set_error_literal (error, G_IO_ERROR,
1237 G_IO_ERROR_NOT_SUPPORTED,
1238 _("Operation not supported"));
1242 return (* iface->query_filesystem_info) (file, attributes, cancellable, error);
1246 * g_file_query_filesystem_info_async:
1247 * @file: input #GFile.
1248 * @attributes: an attribute query string.
1249 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1251 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1252 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1253 * @user_data: (closure): the data to pass to callback function
1255 * Asynchronously gets the requested information about the filesystem
1256 * that the specified @file is on. The result is a #GFileInfo object
1257 * that contains key-value attributes (such as type or size for the
1260 * For more details, see g_file_query_filesystem_info() which is the
1261 * synchronous version of this call.
1263 * When the operation is finished, @callback will be called. You can
1264 * then call g_file_query_info_finish() to get the result of the
1268 g_file_query_filesystem_info_async (GFile *file,
1269 const char *attributes,
1271 GCancellable *cancellable,
1272 GAsyncReadyCallback callback,
1277 g_return_if_fail (G_IS_FILE (file));
1279 iface = G_FILE_GET_IFACE (file);
1280 (* iface->query_filesystem_info_async) (file,
1289 * g_file_query_filesystem_info_finish:
1290 * @file: input #GFile.
1291 * @res: a #GAsyncResult.
1292 * @error: a #GError.
1294 * Finishes an asynchronous filesystem info query. See
1295 * g_file_query_filesystem_info_async().
1297 * Returns: (transfer full): #GFileInfo for given @file or %NULL on error.
1298 * Free the returned object with g_object_unref().
1301 g_file_query_filesystem_info_finish (GFile *file,
1307 g_return_val_if_fail (G_IS_FILE (file), NULL);
1308 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1310 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1312 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1313 if (g_simple_async_result_propagate_error (simple, error))
1317 iface = G_FILE_GET_IFACE (file);
1318 return (* iface->query_filesystem_info_finish) (file, res, error);
1322 * g_file_find_enclosing_mount:
1323 * @file: input #GFile.
1324 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1325 * @error: a #GError.
1327 * Gets a #GMount for the #GFile.
1329 * If the #GFileIface for @file does not have a mount (e.g. possibly a
1330 * remote share), @error will be set to %G_IO_ERROR_NOT_FOUND and %NULL
1333 * If @cancellable is not %NULL, then the operation can be cancelled by
1334 * triggering the cancellable object from another thread. If the operation
1335 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1337 * Returns: (transfer full): a #GMount where the @file is located or %NULL on error.
1338 * Free the returned object with g_object_unref().
1341 g_file_find_enclosing_mount (GFile *file,
1342 GCancellable *cancellable,
1347 g_return_val_if_fail (G_IS_FILE (file), NULL);
1349 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1352 iface = G_FILE_GET_IFACE (file);
1353 if (iface->find_enclosing_mount == NULL)
1356 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1357 /* Translators: This is an error message when trying to find the
1358 * enclosing (user visible) mount of a file, but none exists. */
1359 _("Containing mount does not exist"));
1363 return (* iface->find_enclosing_mount) (file, cancellable, error);
1367 * g_file_find_enclosing_mount_async:
1369 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1371 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1372 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1373 * @user_data: (closure): the data to pass to callback function
1375 * Asynchronously gets the mount for the file.
1377 * For more details, see g_file_find_enclosing_mount() which is
1378 * the synchronous version of this call.
1380 * When the operation is finished, @callback will be called. You can then call
1381 * g_file_find_enclosing_mount_finish() to get the result of the operation.
1384 g_file_find_enclosing_mount_async (GFile *file,
1386 GCancellable *cancellable,
1387 GAsyncReadyCallback callback,
1392 g_return_if_fail (G_IS_FILE (file));
1394 iface = G_FILE_GET_IFACE (file);
1395 (* iface->find_enclosing_mount_async) (file,
1403 * g_file_find_enclosing_mount_finish:
1405 * @res: a #GAsyncResult
1408 * Finishes an asynchronous find mount request.
1409 * See g_file_find_enclosing_mount_async().
1411 * Returns: (transfer full): #GMount for given @file or %NULL on error.
1412 * Free the returned object with g_object_unref().
1415 g_file_find_enclosing_mount_finish (GFile *file,
1421 g_return_val_if_fail (G_IS_FILE (file), NULL);
1422 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1424 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1426 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1427 if (g_simple_async_result_propagate_error (simple, error))
1431 iface = G_FILE_GET_IFACE (file);
1432 return (* iface->find_enclosing_mount_finish) (file, res, error);
1438 * @file: #GFile to read.
1439 * @cancellable: (allow-none): a #GCancellable
1440 * @error: a #GError, or %NULL
1442 * Opens a file for reading. The result is a #GFileInputStream that
1443 * can be used to read the contents of the file.
1445 * If @cancellable is not %NULL, then the operation can be cancelled by
1446 * triggering the cancellable object from another thread. If the operation
1447 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1449 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1450 * If the file is a directory, the G_IO_ERROR_IS_DIRECTORY error will be returned.
1451 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1454 * Returns: (transfer full): #GFileInputStream or %NULL on error.
1455 * Free the returned object with g_object_unref().
1458 g_file_read (GFile *file,
1459 GCancellable *cancellable,
1464 g_return_val_if_fail (G_IS_FILE (file), NULL);
1466 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1469 iface = G_FILE_GET_IFACE (file);
1471 if (iface->read_fn == NULL)
1473 g_set_error_literal (error, G_IO_ERROR,
1474 G_IO_ERROR_NOT_SUPPORTED,
1475 _("Operation not supported"));
1479 return (* iface->read_fn) (file, cancellable, error);
1484 * @file: input #GFile.
1485 * @flags: a set of #GFileCreateFlags.
1486 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1487 * @error: a #GError, or %NULL
1489 * Gets an output stream for appending data to the file. If
1490 * the file doesn't already exist it is created.
1492 * By default files created are generally readable by everyone,
1493 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1494 * will be made readable only to the current user, to the level that
1495 * is supported on the target filesystem.
1497 * If @cancellable is not %NULL, then the operation can be cancelled by
1498 * triggering the cancellable object from another thread. If the operation
1499 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1501 * Some file systems don't allow all file names, and may
1502 * return an %G_IO_ERROR_INVALID_FILENAME error.
1503 * If the file is a directory the %G_IO_ERROR_IS_DIRECTORY error will be
1504 * returned. Other errors are possible too, and depend on what kind of
1505 * filesystem the file is on.
1507 * Returns: (transfer full): a #GFileOutputStream, or %NULL on error.
1508 * Free the returned object with g_object_unref().
1511 g_file_append_to (GFile *file,
1512 GFileCreateFlags flags,
1513 GCancellable *cancellable,
1518 g_return_val_if_fail (G_IS_FILE (file), NULL);
1520 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1523 iface = G_FILE_GET_IFACE (file);
1525 if (iface->append_to == NULL)
1527 g_set_error_literal (error, G_IO_ERROR,
1528 G_IO_ERROR_NOT_SUPPORTED,
1529 _("Operation not supported"));
1533 return (* iface->append_to) (file, flags, cancellable, error);
1538 * @file: input #GFile.
1539 * @flags: a set of #GFileCreateFlags.
1540 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1541 * @error: a #GError, or %NULL
1543 * Creates a new file and returns an output stream for writing to it.
1544 * The file must not already exist.
1546 * By default files created are generally readable by everyone,
1547 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1548 * will be made readable only to the current user, to the level that
1549 * is supported on the target filesystem.
1551 * If @cancellable is not %NULL, then the operation can be cancelled by
1552 * triggering the cancellable object from another thread. If the operation
1553 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1555 * If a file or directory with this name already exists the G_IO_ERROR_EXISTS
1556 * error will be returned.
1557 * Some file systems don't allow all file names, and may
1558 * return an G_IO_ERROR_INVALID_FILENAME error, and if the name
1559 * is to long G_IO_ERROR_FILENAME_TOO_LONG will be returned.
1560 * Other errors are possible too, and depend on what kind of
1561 * filesystem the file is on.
1563 * Returns: (transfer full): a #GFileOutputStream for the newly created file, or
1565 * Free the returned object with g_object_unref().
1568 g_file_create (GFile *file,
1569 GFileCreateFlags flags,
1570 GCancellable *cancellable,
1575 g_return_val_if_fail (G_IS_FILE (file), NULL);
1577 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1580 iface = G_FILE_GET_IFACE (file);
1582 if (iface->create == NULL)
1584 g_set_error_literal (error, G_IO_ERROR,
1585 G_IO_ERROR_NOT_SUPPORTED,
1586 _("Operation not supported"));
1590 return (* iface->create) (file, flags, cancellable, error);
1595 * @file: input #GFile.
1596 * @etag: (allow-none): an optional <link linkend="gfile-etag">entity tag</link> for the
1597 * current #GFile, or #NULL to ignore.
1598 * @make_backup: %TRUE if a backup should be created.
1599 * @flags: a set of #GFileCreateFlags.
1600 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1601 * @error: a #GError, or %NULL
1603 * Returns an output stream for overwriting the file, possibly
1604 * creating a backup copy of the file first. If the file doesn't exist,
1605 * it will be created.
1607 * This will try to replace the file in the safest way possible so
1608 * that any errors during the writing will not affect an already
1609 * existing copy of the file. For instance, for local files it
1610 * may write to a temporary file and then atomically rename over
1611 * the destination when the stream is closed.
1613 * By default files created are generally readable by everyone,
1614 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1615 * will be made readable only to the current user, to the level that
1616 * is supported on the target filesystem.
1618 * If @cancellable is not %NULL, then the operation can be cancelled by
1619 * triggering the cancellable object from another thread. If the operation
1620 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1622 * If you pass in a non-#NULL @etag value, then this value is
1623 * compared to the current entity tag of the file, and if they differ
1624 * an G_IO_ERROR_WRONG_ETAG error is returned. This generally means
1625 * that the file has been changed since you last read it. You can get
1626 * the new etag from g_file_output_stream_get_etag() after you've
1627 * finished writing and closed the #GFileOutputStream. When you load
1628 * a new file you can use g_file_input_stream_query_info() to get
1629 * the etag of the file.
1631 * If @make_backup is %TRUE, this function will attempt to make a backup
1632 * of the current file before overwriting it. If this fails a G_IO_ERROR_CANT_CREATE_BACKUP
1633 * error will be returned. If you want to replace anyway, try again with
1634 * @make_backup set to %FALSE.
1636 * If the file is a directory the G_IO_ERROR_IS_DIRECTORY error will be returned,
1637 * and if the file is some other form of non-regular file then a
1638 * G_IO_ERROR_NOT_REGULAR_FILE error will be returned.
1639 * Some file systems don't allow all file names, and may
1640 * return an G_IO_ERROR_INVALID_FILENAME error, and if the name
1641 * is to long G_IO_ERROR_FILENAME_TOO_LONG will be returned.
1642 * Other errors are possible too, and depend on what kind of
1643 * filesystem the file is on.
1645 * Returns: (transfer full): a #GFileOutputStream or %NULL on error.
1646 * Free the returned object with g_object_unref().
1649 g_file_replace (GFile *file,
1651 gboolean make_backup,
1652 GFileCreateFlags flags,
1653 GCancellable *cancellable,
1658 g_return_val_if_fail (G_IS_FILE (file), NULL);
1660 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1663 iface = G_FILE_GET_IFACE (file);
1665 if (iface->replace == NULL)
1667 g_set_error_literal (error, G_IO_ERROR,
1668 G_IO_ERROR_NOT_SUPPORTED,
1669 _("Operation not supported"));
1674 /* Handle empty tag string as NULL in consistent way. */
1675 if (etag && *etag == 0)
1678 return (* iface->replace) (file, etag, make_backup, flags, cancellable, error);
1682 * g_file_open_readwrite:
1683 * @file: #GFile to open
1684 * @cancellable: (allow-none): a #GCancellable
1685 * @error: a #GError, or %NULL
1687 * Opens an existing file for reading and writing. The result is
1688 * a #GFileIOStream that can be used to read and write the contents of the file.
1690 * If @cancellable is not %NULL, then the operation can be cancelled by
1691 * triggering the cancellable object from another thread. If the operation
1692 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1694 * If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
1695 * If the file is a directory, the G_IO_ERROR_IS_DIRECTORY error will be returned.
1696 * Other errors are possible too, and depend on what kind of filesystem the file is on.
1697 * Note that in many non-local file cases read and write streams are not supported,
1698 * so make sure you really need to do read and write streaming, rather than
1699 * just opening for reading or writing.
1701 * Returns: (transfer full): #GFileIOStream or %NULL on error.
1702 * Free the returned object with g_object_unref().
1707 g_file_open_readwrite (GFile *file,
1708 GCancellable *cancellable,
1713 g_return_val_if_fail (G_IS_FILE (file), NULL);
1715 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1718 iface = G_FILE_GET_IFACE (file);
1720 if (iface->open_readwrite == NULL)
1722 g_set_error_literal (error, G_IO_ERROR,
1723 G_IO_ERROR_NOT_SUPPORTED,
1724 _("Operation not supported"));
1728 return (* iface->open_readwrite) (file, cancellable, error);
1732 * g_file_create_readwrite:
1734 * @flags: a set of #GFileCreateFlags
1735 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
1736 * @error: return location for a #GError, or %NULL
1738 * Creates a new file and returns a stream for reading and writing to it.
1739 * The file must not already exist.
1741 * By default files created are generally readable by everyone,
1742 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1743 * will be made readable only to the current user, to the level that
1744 * is supported on the target filesystem.
1746 * If @cancellable is not %NULL, then the operation can be cancelled by
1747 * triggering the cancellable object from another thread. If the operation
1748 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1750 * If a file or directory with this name already exists the %G_IO_ERROR_EXISTS
1751 * error will be returned. Some file systems don't allow all file names,
1752 * and may return an %G_IO_ERROR_INVALID_FILENAME error, and if the name
1753 * is too long, %G_IO_ERROR_FILENAME_TOO_LONG will be returned. Other errors
1754 * are possible too, and depend on what kind of filesystem the file is on.
1756 * Note that in many non-local file cases read and write streams are not
1757 * supported, so make sure you really need to do read and write streaming,
1758 * rather than just opening for reading or writing.
1760 * Returns: (transfer full): a #GFileIOStream for the newly created file, or %NULL on error.
1761 * Free the returned object with g_object_unref().
1766 g_file_create_readwrite (GFile *file,
1767 GFileCreateFlags flags,
1768 GCancellable *cancellable,
1773 g_return_val_if_fail (G_IS_FILE (file), NULL);
1775 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1778 iface = G_FILE_GET_IFACE (file);
1780 if (iface->create_readwrite == NULL)
1782 g_set_error_literal (error, G_IO_ERROR,
1783 G_IO_ERROR_NOT_SUPPORTED,
1784 _("Operation not supported"));
1788 return (* iface->create_readwrite) (file, flags, cancellable, error);
1792 * g_file_replace_readwrite:
1794 * @etag: (allow-none): an optional <link linkend="gfile-etag">entity tag</link> for the
1795 * current #GFile, or #NULL to ignore
1796 * @make_backup: %TRUE if a backup should be created
1797 * @flags: a set of #GFileCreateFlags
1798 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
1799 * @error: return location for a #GError, or %NULL
1801 * Returns an output stream for overwriting the file in readwrite mode,
1802 * possibly creating a backup copy of the file first. If the file doesn't
1803 * exist, it will be created.
1805 * For details about the behaviour, see g_file_replace() which does the same
1806 * thing but returns an output stream only.
1808 * Note that in many non-local file cases read and write streams are not
1809 * supported, so make sure you really need to do read and write streaming,
1810 * rather than just opening for reading or writing.
1812 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
1813 * Free the returned object with g_object_unref().
1818 g_file_replace_readwrite (GFile *file,
1820 gboolean make_backup,
1821 GFileCreateFlags flags,
1822 GCancellable *cancellable,
1827 g_return_val_if_fail (G_IS_FILE (file), NULL);
1829 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1832 iface = G_FILE_GET_IFACE (file);
1834 if (iface->replace_readwrite == NULL)
1836 g_set_error_literal (error, G_IO_ERROR,
1837 G_IO_ERROR_NOT_SUPPORTED,
1838 _("Operation not supported"));
1842 return (* iface->replace_readwrite) (file, etag, make_backup, flags, cancellable, error);
1846 * g_file_read_async:
1847 * @file: input #GFile
1848 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1850 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1851 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1852 * @user_data: (closure): the data to pass to callback function
1854 * Asynchronously opens @file for reading.
1856 * For more details, see g_file_read() which is
1857 * the synchronous version of this call.
1859 * When the operation is finished, @callback will be called. You can then call
1860 * g_file_read_finish() to get the result of the operation.
1863 g_file_read_async (GFile *file,
1865 GCancellable *cancellable,
1866 GAsyncReadyCallback callback,
1871 g_return_if_fail (G_IS_FILE (file));
1873 iface = G_FILE_GET_IFACE (file);
1874 (* iface->read_async) (file,
1882 * g_file_read_finish:
1883 * @file: input #GFile.
1884 * @res: a #GAsyncResult.
1885 * @error: a #GError, or %NULL
1887 * Finishes an asynchronous file read operation started with
1888 * g_file_read_async().
1890 * Returns: (transfer full): a #GFileInputStream or %NULL on error.
1891 * Free the returned object with g_object_unref().
1894 g_file_read_finish (GFile *file,
1900 g_return_val_if_fail (G_IS_FILE (file), NULL);
1901 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1903 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1905 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1906 if (g_simple_async_result_propagate_error (simple, error))
1910 iface = G_FILE_GET_IFACE (file);
1911 return (* iface->read_finish) (file, res, error);
1915 * g_file_append_to_async:
1916 * @file: input #GFile.
1917 * @flags: a set of #GFileCreateFlags.
1918 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1920 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1921 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1922 * @user_data: (closure): the data to pass to callback function
1924 * Asynchronously opens @file for appending.
1926 * For more details, see g_file_append_to() which is
1927 * the synchronous version of this call.
1929 * When the operation is finished, @callback will be called. You can then call
1930 * g_file_append_to_finish() to get the result of the operation.
1933 g_file_append_to_async (GFile *file,
1934 GFileCreateFlags flags,
1936 GCancellable *cancellable,
1937 GAsyncReadyCallback callback,
1942 g_return_if_fail (G_IS_FILE (file));
1944 iface = G_FILE_GET_IFACE (file);
1945 (* iface->append_to_async) (file,
1954 * g_file_append_to_finish:
1955 * @file: input #GFile.
1956 * @res: #GAsyncResult
1957 * @error: a #GError, or %NULL
1959 * Finishes an asynchronous file append operation started with
1960 * g_file_append_to_async().
1962 * Returns: (transfer full): a valid #GFileOutputStream or %NULL on error.
1963 * Free the returned object with g_object_unref().
1966 g_file_append_to_finish (GFile *file,
1972 g_return_val_if_fail (G_IS_FILE (file), NULL);
1973 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1975 if (G_IS_SIMPLE_ASYNC_RESULT (res))
1977 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
1978 if (g_simple_async_result_propagate_error (simple, error))
1982 iface = G_FILE_GET_IFACE (file);
1983 return (* iface->append_to_finish) (file, res, error);
1987 * g_file_create_async:
1988 * @file: input #GFile.
1989 * @flags: a set of #GFileCreateFlags.
1990 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1992 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
1993 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
1994 * @user_data: (closure): the data to pass to callback function
1996 * Asynchronously creates a new file and returns an output stream for writing to it.
1997 * The file must not already exist.
1999 * For more details, see g_file_create() which is
2000 * the synchronous version of this call.
2002 * When the operation is finished, @callback will be called. You can then call
2003 * g_file_create_finish() to get the result of the operation.
2006 g_file_create_async (GFile *file,
2007 GFileCreateFlags flags,
2009 GCancellable *cancellable,
2010 GAsyncReadyCallback callback,
2015 g_return_if_fail (G_IS_FILE (file));
2017 iface = G_FILE_GET_IFACE (file);
2018 (* iface->create_async) (file,
2027 * g_file_create_finish:
2028 * @file: input #GFile.
2029 * @res: a #GAsyncResult.
2030 * @error: a #GError, or %NULL
2032 * Finishes an asynchronous file create operation started with
2033 * g_file_create_async().
2035 * Returns: (transfer full): a #GFileOutputStream or %NULL on error.
2036 * Free the returned object with g_object_unref().
2039 g_file_create_finish (GFile *file,
2045 g_return_val_if_fail (G_IS_FILE (file), NULL);
2046 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2048 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2050 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2051 if (g_simple_async_result_propagate_error (simple, error))
2055 iface = G_FILE_GET_IFACE (file);
2056 return (* iface->create_finish) (file, res, error);
2060 * g_file_replace_async:
2061 * @file: input #GFile.
2062 * @etag: (allow-none): an <link linkend="gfile-etag">entity tag</link> for the
2063 * current #GFile, or NULL to ignore.
2064 * @make_backup: %TRUE if a backup should be created.
2065 * @flags: a set of #GFileCreateFlags.
2066 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2068 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
2069 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
2070 * @user_data: (closure): the data to pass to callback function
2072 * Asynchronously overwrites the file, replacing the contents, possibly
2073 * creating a backup copy of the file first.
2075 * For more details, see g_file_replace() which is
2076 * the synchronous version of this call.
2078 * When the operation is finished, @callback will be called. You can then call
2079 * g_file_replace_finish() to get the result of the operation.
2082 g_file_replace_async (GFile *file,
2084 gboolean make_backup,
2085 GFileCreateFlags flags,
2087 GCancellable *cancellable,
2088 GAsyncReadyCallback callback,
2093 g_return_if_fail (G_IS_FILE (file));
2095 iface = G_FILE_GET_IFACE (file);
2096 (* iface->replace_async) (file,
2107 * g_file_replace_finish:
2108 * @file: input #GFile.
2109 * @res: a #GAsyncResult.
2110 * @error: a #GError, or %NULL
2112 * Finishes an asynchronous file replace operation started with
2113 * g_file_replace_async().
2115 * Returns: (transfer full): a #GFileOutputStream, or %NULL on error.
2116 * Free the returned object with g_object_unref().
2119 g_file_replace_finish (GFile *file,
2125 g_return_val_if_fail (G_IS_FILE (file), NULL);
2126 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2128 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2130 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2131 if (g_simple_async_result_propagate_error (simple, error))
2135 iface = G_FILE_GET_IFACE (file);
2136 return (* iface->replace_finish) (file, res, error);
2141 * g_file_open_readwrite_async:
2142 * @file: input #GFile.
2143 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2145 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
2146 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
2147 * @user_data: (closure): the data to pass to callback function
2149 * Asynchronously opens @file for reading and writing.
2151 * For more details, see g_file_open_readwrite() which is
2152 * the synchronous version of this call.
2154 * When the operation is finished, @callback will be called. You can then call
2155 * g_file_open_readwrite_finish() to get the result of the operation.
2160 g_file_open_readwrite_async (GFile *file,
2162 GCancellable *cancellable,
2163 GAsyncReadyCallback callback,
2168 g_return_if_fail (G_IS_FILE (file));
2170 iface = G_FILE_GET_IFACE (file);
2171 (* iface->open_readwrite_async) (file,
2179 * g_file_open_readwrite_finish:
2180 * @file: input #GFile.
2181 * @res: a #GAsyncResult.
2182 * @error: a #GError, or %NULL
2184 * Finishes an asynchronous file read operation started with
2185 * g_file_open_readwrite_async().
2187 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
2188 * Free the returned object with g_object_unref().
2193 g_file_open_readwrite_finish (GFile *file,
2199 g_return_val_if_fail (G_IS_FILE (file), NULL);
2200 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2202 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2204 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2205 if (g_simple_async_result_propagate_error (simple, error))
2209 iface = G_FILE_GET_IFACE (file);
2210 return (* iface->open_readwrite_finish) (file, res, error);
2215 * g_file_create_readwrite_async:
2216 * @file: input #GFile
2217 * @flags: a set of #GFileCreateFlags
2218 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2220 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
2221 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
2222 * @user_data: (closure): the data to pass to callback function
2224 * Asynchronously creates a new file and returns a stream for reading and
2225 * writing to it. The file must not already exist.
2227 * For more details, see g_file_create_readwrite() which is
2228 * the synchronous version of this call.
2230 * When the operation is finished, @callback will be called. You can then
2231 * call g_file_create_readwrite_finish() to get the result of the operation.
2236 g_file_create_readwrite_async (GFile *file,
2237 GFileCreateFlags flags,
2239 GCancellable *cancellable,
2240 GAsyncReadyCallback callback,
2245 g_return_if_fail (G_IS_FILE (file));
2247 iface = G_FILE_GET_IFACE (file);
2248 (* iface->create_readwrite_async) (file,
2257 * g_file_create_readwrite_finish:
2258 * @file: input #GFile
2259 * @res: a #GAsyncResult
2260 * @error: a #GError, or %NULL
2262 * Finishes an asynchronous file create operation started with
2263 * g_file_create_readwrite_async().
2265 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
2266 * Free the returned object with g_object_unref().
2271 g_file_create_readwrite_finish (GFile *file,
2277 g_return_val_if_fail (G_IS_FILE (file), NULL);
2278 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2280 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2282 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2283 if (g_simple_async_result_propagate_error (simple, error))
2287 iface = G_FILE_GET_IFACE (file);
2288 return (* iface->create_readwrite_finish) (file, res, error);
2292 * g_file_replace_readwrite_async:
2293 * @file: input #GFile.
2294 * @etag: (allow-none): an <link linkend="gfile-etag">entity tag</link> for the
2295 * current #GFile, or NULL to ignore.
2296 * @make_backup: %TRUE if a backup should be created.
2297 * @flags: a set of #GFileCreateFlags.
2298 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2300 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
2301 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
2302 * @user_data: (closure): the data to pass to callback function
2304 * Asynchronously overwrites the file in read-write mode, replacing the
2305 * contents, possibly creating a backup copy of the file first.
2307 * For more details, see g_file_replace_readwrite() which is
2308 * the synchronous version of this call.
2310 * When the operation is finished, @callback will be called. You can then
2311 * call g_file_replace_readwrite_finish() to get the result of the operation.
2316 g_file_replace_readwrite_async (GFile *file,
2318 gboolean make_backup,
2319 GFileCreateFlags flags,
2321 GCancellable *cancellable,
2322 GAsyncReadyCallback callback,
2327 g_return_if_fail (G_IS_FILE (file));
2329 iface = G_FILE_GET_IFACE (file);
2330 (* iface->replace_readwrite_async) (file,
2341 * g_file_replace_readwrite_finish:
2342 * @file: input #GFile.
2343 * @res: a #GAsyncResult.
2344 * @error: a #GError, or %NULL
2346 * Finishes an asynchronous file replace operation started with
2347 * g_file_replace_readwrite_async().
2349 * Returns: (transfer full): a #GFileIOStream, or %NULL on error.
2350 * Free the returned object with g_object_unref().
2355 g_file_replace_readwrite_finish (GFile *file,
2361 g_return_val_if_fail (G_IS_FILE (file), NULL);
2362 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2364 if (G_IS_SIMPLE_ASYNC_RESULT (res))
2366 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
2367 if (g_simple_async_result_propagate_error (simple, error))
2371 iface = G_FILE_GET_IFACE (file);
2372 return (* iface->replace_readwrite_finish) (file, res, error);
2376 copy_symlink (GFile *destination,
2377 GFileCopyFlags flags,
2378 GCancellable *cancellable,
2383 gboolean tried_delete;
2385 GFileType file_type;
2387 tried_delete = FALSE;
2391 if (!g_file_make_symbolic_link (destination, target, cancellable, &my_error))
2393 /* Maybe it already existed, and we want to overwrite? */
2394 if (!tried_delete && (flags & G_FILE_COPY_OVERWRITE) &&
2395 my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_EXISTS)
2397 g_error_free (my_error);
2400 /* Don't overwrite if the destination is a directory */
2401 info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
2402 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2403 cancellable, &my_error);
2406 file_type = g_file_info_get_file_type (info);
2407 g_object_unref (info);
2409 if (file_type == G_FILE_TYPE_DIRECTORY)
2411 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY,
2412 _("Can't copy over directory"));
2417 if (!g_file_delete (destination, cancellable, error))
2420 tried_delete = TRUE;
2424 g_propagate_error (error, my_error);
2431 static GInputStream *
2432 open_source_for_copy (GFile *source,
2434 GFileCopyFlags flags,
2435 GCancellable *cancellable,
2441 GFileType file_type;
2444 in = (GInputStream *)g_file_read (source, cancellable, &my_error);
2448 /* There was an error opening the source, try to set a good error for it: */
2450 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_IS_DIRECTORY)
2452 /* The source is a directory, don't fail with WOULD_RECURSE immediately,
2453 * as that is less useful to the app. Better check for errors on the
2456 g_error_free (my_error);
2459 info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
2460 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2461 cancellable, &my_error);
2463 g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_TYPE))
2465 file_type = g_file_info_get_file_type (info);
2466 g_object_unref (info);
2468 if (flags & G_FILE_COPY_OVERWRITE)
2470 if (file_type == G_FILE_TYPE_DIRECTORY)
2472 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_MERGE,
2473 _("Can't copy directory over directory"));
2476 /* continue to would_recurse error */
2480 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
2481 _("Target file exists"));
2487 /* Error getting info from target, return that error
2488 * (except for NOT_FOUND, which is no error here)
2490 if (my_error != NULL && !g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
2492 g_propagate_error (error, my_error);
2495 g_clear_error (&my_error);
2498 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_RECURSE,
2499 _("Can't recursively copy directory"));
2503 g_propagate_error (error, my_error);
2508 should_copy (GFileAttributeInfo *info,
2510 gboolean skip_perms)
2512 if (skip_perms && strcmp(info->name, "unix::mode") == 0)
2516 return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED;
2517 return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE;
2521 build_attribute_list_for_copy (GFileAttributeInfoList *attributes,
2522 GFileAttributeInfoList *namespaces,
2524 gboolean skip_perms)
2531 s = g_string_new ("");
2535 for (i = 0; i < attributes->n_infos; i++)
2537 if (should_copy (&attributes->infos[i], as_move, skip_perms))
2542 g_string_append_c (s, ',');
2544 g_string_append (s, attributes->infos[i].name);
2551 for (i = 0; i < namespaces->n_infos; i++)
2553 if (should_copy (&namespaces->infos[i], as_move, FALSE))
2558 g_string_append_c (s, ',');
2560 g_string_append (s, namespaces->infos[i].name);
2561 g_string_append (s, "::*");
2566 return g_string_free (s, FALSE);
2570 * g_file_copy_attributes:
2571 * @source: a #GFile with attributes.
2572 * @destination: a #GFile to copy attributes to.
2573 * @flags: a set of #GFileCopyFlags.
2574 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
2575 * @error: a #GError, %NULL to ignore.
2577 * Copies the file attributes from @source to @destination.
2579 * Normally only a subset of the file attributes are copied,
2580 * those that are copies in a normal file copy operation
2581 * (which for instance does not include e.g. owner). However
2582 * if #G_FILE_COPY_ALL_METADATA is specified in @flags, then
2583 * all the metadata that is possible to copy is copied. This
2584 * is useful when implementing move by copy + delete source.
2586 * Returns: %TRUE if the attributes were copied successfully, %FALSE otherwise.
2589 g_file_copy_attributes (GFile *source,
2591 GFileCopyFlags flags,
2592 GCancellable *cancellable,
2595 GFileAttributeInfoList *attributes, *namespaces;
2596 char *attrs_to_read;
2600 gboolean source_nofollow_symlinks;
2601 gboolean skip_perms;
2603 as_move = flags & G_FILE_COPY_ALL_METADATA;
2604 source_nofollow_symlinks = flags & G_FILE_COPY_NOFOLLOW_SYMLINKS;
2605 skip_perms = (flags & G_FILE_COPY_TARGET_DEFAULT_PERMS) != 0;
2607 /* Ignore errors here, if the target supports no attributes there is nothing to copy */
2608 attributes = g_file_query_settable_attributes (destination, cancellable, NULL);
2609 namespaces = g_file_query_writable_namespaces (destination, cancellable, NULL);
2611 if (attributes == NULL && namespaces == NULL)
2614 attrs_to_read = build_attribute_list_for_copy (attributes, namespaces, as_move, skip_perms);
2616 /* Ignore errors here, if we can't read some info (e.g. if it doesn't exist)
2617 * we just don't copy it.
2619 info = g_file_query_info (source, attrs_to_read,
2620 source_nofollow_symlinks ? G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS:0,
2624 g_free (attrs_to_read);
2629 res = g_file_set_attributes_from_info (destination,
2631 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2634 g_object_unref (info);
2637 g_file_attribute_info_list_unref (attributes);
2638 g_file_attribute_info_list_unref (namespaces);
2644 copy_stream_with_progress (GInputStream *in,
2647 GCancellable *cancellable,
2648 GFileProgressCallback progress_callback,
2649 gpointer progress_callback_data,
2652 gssize n_read, n_written;
2653 goffset current_size;
2654 char buffer[1024*64], *p;
2660 /* avoid performance impact of querying total size when it's not needed */
2661 if (progress_callback)
2663 info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (in),
2664 G_FILE_ATTRIBUTE_STANDARD_SIZE,
2668 if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
2669 total_size = g_file_info_get_size (info);
2670 g_object_unref (info);
2673 if (total_size == -1)
2675 info = g_file_query_info (source,
2676 G_FILE_ATTRIBUTE_STANDARD_SIZE,
2677 G_FILE_QUERY_INFO_NONE,
2681 if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
2682 total_size = g_file_info_get_size (info);
2683 g_object_unref (info);
2688 if (total_size == -1)
2695 n_read = g_input_stream_read (in, buffer, sizeof (buffer), cancellable, error);
2705 current_size += n_read;
2710 n_written = g_output_stream_write (out, p, n_read, cancellable, error);
2711 if (n_written == -1)
2718 n_read -= n_written;
2724 if (progress_callback)
2725 progress_callback (current_size, total_size, progress_callback_data);
2728 /* Make sure we send full copied size */
2729 if (progress_callback)
2730 progress_callback (current_size, total_size, progress_callback_data);
2738 do_splice (int fd_in,
2743 long *bytes_transferd,
2749 result = splice (fd_in, off_in, fd_out, off_out, len, SPLICE_F_MORE);
2757 else if (errsv == ENOSYS || errsv == EINVAL)
2758 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2759 _("Splice not supported"));
2761 g_set_error (error, G_IO_ERROR,
2762 g_io_error_from_errno (errsv),
2763 _("Error splicing file: %s"),
2764 g_strerror (errsv));
2769 *bytes_transferd = result;
2774 splice_stream_with_progress (GInputStream *in,
2776 GCancellable *cancellable,
2777 GFileProgressCallback progress_callback,
2778 gpointer progress_callback_data,
2788 fd_in = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (in));
2789 fd_out = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (out));
2791 if (pipe (buffer) != 0)
2793 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2794 "Pipe creation failed");
2799 /* avoid performance impact of querying total size when it's not needed */
2800 if (progress_callback)
2804 if (fstat (fd_in, &sbuf) == 0)
2805 total_size = sbuf.st_size;
2808 if (total_size == -1)
2811 offset_in = offset_out = 0;
2818 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2821 if (!do_splice (fd_in, &offset_in, buffer[1], NULL, 1024*64, &n_read, error))
2832 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2835 if (!do_splice (buffer[0], NULL, fd_out, &offset_out, n_read, &n_written, error))
2838 n_read -= n_written;
2841 if (progress_callback)
2842 progress_callback (offset_in, total_size, progress_callback_data);
2845 /* Make sure we send full copied size */
2846 if (progress_callback)
2847 progress_callback (offset_in, total_size, progress_callback_data);
2858 file_copy_fallback (GFile *source,
2860 GFileCopyFlags flags,
2861 GCancellable *cancellable,
2862 GFileProgressCallback progress_callback,
2863 gpointer progress_callback_data,
2872 gboolean fallback = TRUE;
2875 /* need to know the file type */
2876 info = g_file_query_info (source,
2877 G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
2878 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2885 /* Maybe copy the symlink? */
2886 if ((flags & G_FILE_COPY_NOFOLLOW_SYMLINKS) &&
2887 g_file_info_get_file_type (info) == G_FILE_TYPE_SYMBOLIC_LINK)
2889 target = g_file_info_get_symlink_target (info);
2892 if (!copy_symlink (destination, flags, cancellable, target, error))
2894 g_object_unref (info);
2898 g_object_unref (info);
2901 /* ... else fall back on a regular file copy */
2902 g_object_unref (info);
2904 /* Handle "special" files (pipes, device nodes, ...)? */
2905 else if (g_file_info_get_file_type (info) == G_FILE_TYPE_SPECIAL)
2907 /* FIXME: could try to recreate device nodes and others? */
2909 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2910 _("Can't copy special file"));
2911 g_object_unref (info);
2914 /* Everything else should just fall back on a regular copy. */
2916 g_object_unref (info);
2918 in = open_source_for_copy (source, destination, flags, cancellable, error);
2922 if (flags & G_FILE_COPY_OVERWRITE)
2924 out = (GOutputStream *)g_file_replace (destination,
2926 flags & G_FILE_COPY_BACKUP,
2927 G_FILE_CREATE_REPLACE_DESTINATION,
2928 cancellable, error);
2932 out = (GOutputStream *)g_file_create (destination, 0, cancellable, error);
2937 g_object_unref (in);
2942 if (G_IS_FILE_DESCRIPTOR_BASED (in) && G_IS_FILE_DESCRIPTOR_BASED (out))
2944 GError *splice_err = NULL;
2946 result = splice_stream_with_progress (in, out, cancellable,
2947 progress_callback, progress_callback_data,
2950 if (result || !g_error_matches (splice_err, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
2954 g_propagate_error (error, splice_err);
2957 g_clear_error (&splice_err);
2962 result = copy_stream_with_progress (in, out, source, cancellable,
2963 progress_callback, progress_callback_data,
2966 /* Don't care about errors in source here */
2967 g_input_stream_close (in, cancellable, NULL);
2969 /* But write errors on close are bad! */
2970 if (!g_output_stream_close (out, cancellable, result ? error : NULL))
2973 g_object_unref (in);
2974 g_object_unref (out);
2976 if (result == FALSE)
2980 /* Ignore errors here. Failure to copy metadata is not a hard error */
2981 g_file_copy_attributes (source, destination,
2982 flags, cancellable, NULL);
2989 * @source: input #GFile.
2990 * @destination: destination #GFile
2991 * @flags: set of #GFileCopyFlags
2992 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
2993 * @progress_callback: (scope call): function to callback with progress information
2994 * @progress_callback_data: (closure): user data to pass to @progress_callback
2995 * @error: #GError to set on error, or %NULL
2997 * Copies the file @source to the location specified by @destination.
2998 * Can not handle recursive copies of directories.
3000 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
3001 * existing @destination file is overwritten.
3003 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
3004 * will be copied as symlinks, otherwise the target of the
3005 * @source symlink will be copied.
3007 * If @cancellable is not %NULL, then the operation can be cancelled by
3008 * triggering the cancellable object from another thread. If the operation
3009 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3011 * If @progress_callback is not %NULL, then the operation can be monitored by
3012 * setting this to a #GFileProgressCallback function. @progress_callback_data
3013 * will be passed to this function. It is guaranteed that this callback will
3014 * be called after all data has been transferred with the total number of bytes
3015 * copied during the operation.
3017 * If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
3018 * error is returned, independent on the status of the @destination.
3020 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then the
3021 * error G_IO_ERROR_EXISTS is returned.
3023 * If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY
3024 * error is returned. If trying to overwrite a directory with a directory the
3025 * G_IO_ERROR_WOULD_MERGE error is returned.
3027 * If the source is a directory and the target does not exist, or #G_FILE_COPY_OVERWRITE is
3028 * specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error
3031 * If you are interested in copying the #GFile object itself (not the on-disk
3032 * file), see g_file_dup().
3034 * Returns: %TRUE on success, %FALSE otherwise.
3037 g_file_copy (GFile *source,
3039 GFileCopyFlags flags,
3040 GCancellable *cancellable,
3041 GFileProgressCallback progress_callback,
3042 gpointer progress_callback_data,
3049 g_return_val_if_fail (G_IS_FILE (source), FALSE);
3050 g_return_val_if_fail (G_IS_FILE (destination), FALSE);
3052 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3055 iface = G_FILE_GET_IFACE (destination);
3059 res = (* iface->copy) (source, destination,
3061 progress_callback, progress_callback_data,
3067 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3069 g_propagate_error (error, my_error);
3073 g_clear_error (&my_error);
3076 /* If the types are different, and the destination method failed
3077 also try the source method */
3078 if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
3080 iface = G_FILE_GET_IFACE (source);
3085 res = (* iface->copy) (source, destination,
3087 progress_callback, progress_callback_data,
3093 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3095 g_propagate_error (error, my_error);
3099 g_clear_error (&my_error);
3103 return file_copy_fallback (source, destination, flags, cancellable,
3104 progress_callback, progress_callback_data,
3109 * g_file_copy_async: (skip)
3110 * @source: input #GFile.
3111 * @destination: destination #GFile
3112 * @flags: set of #GFileCopyFlags
3113 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3115 * @cancellable: optional #GCancellable object, %NULL to ignore.
3116 * @progress_callback: function to callback with progress information
3117 * @progress_callback_data: user data to pass to @progress_callback
3118 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
3119 * @user_data: the data to pass to callback function
3121 * Copies the file @source to the location specified by @destination
3122 * asynchronously. For details of the behaviour, see g_file_copy().
3124 * If @progress_callback is not %NULL, then that function that will be called
3125 * just like in g_file_copy(), however the callback will run in the main loop,
3126 * not in the thread that is doing the I/O operation.
3128 * When the operation is finished, @callback will be called. You can then call
3129 * g_file_copy_finish() to get the result of the operation.
3132 g_file_copy_async (GFile *source,
3134 GFileCopyFlags flags,
3136 GCancellable *cancellable,
3137 GFileProgressCallback progress_callback,
3138 gpointer progress_callback_data,
3139 GAsyncReadyCallback callback,
3144 g_return_if_fail (G_IS_FILE (source));
3145 g_return_if_fail (G_IS_FILE (destination));
3147 iface = G_FILE_GET_IFACE (source);
3148 (* iface->copy_async) (source,
3154 progress_callback_data,
3160 * g_file_copy_finish:
3161 * @file: input #GFile.
3162 * @res: a #GAsyncResult.
3163 * @error: a #GError, or %NULL
3165 * Finishes copying the file started with
3166 * g_file_copy_async().
3168 * Returns: a %TRUE on success, %FALSE on error.
3171 g_file_copy_finish (GFile *file,
3177 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3178 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
3180 if (G_IS_SIMPLE_ASYNC_RESULT (res))
3182 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
3184 if (g_simple_async_result_propagate_error (simple, error))
3188 iface = G_FILE_GET_IFACE (file);
3189 return (* iface->copy_finish) (file, res, error);
3194 * @source: #GFile pointing to the source location.
3195 * @destination: #GFile pointing to the destination location.
3196 * @flags: set of #GFileCopyFlags.
3197 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3198 * @progress_callback: (scope call): #GFileProgressCallback function for updates.
3199 * @progress_callback_data: (closure): gpointer to user data for the callback function.
3200 * @error: #GError for returning error conditions, or %NULL
3203 * Tries to move the file or directory @source to the location specified by @destination.
3204 * If native move operations are supported then this is used, otherwise a copy + delete
3205 * fallback is used. The native implementation may support moving directories (for instance
3206 * on moves inside the same filesystem), but the fallback code does not.
3208 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
3209 * existing @destination file is overwritten.
3211 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
3212 * will be copied as symlinks, otherwise the target of the
3213 * @source symlink will be copied.
3215 * If @cancellable is not %NULL, then the operation can be cancelled by
3216 * triggering the cancellable object from another thread. If the operation
3217 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3219 * If @progress_callback is not %NULL, then the operation can be monitored by
3220 * setting this to a #GFileProgressCallback function. @progress_callback_data
3221 * will be passed to this function. It is guaranteed that this callback will
3222 * be called after all data has been transferred with the total number of bytes
3223 * copied during the operation.
3225 * If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
3226 * error is returned, independent on the status of the @destination.
3228 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then the
3229 * error G_IO_ERROR_EXISTS is returned.
3231 * If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY
3232 * error is returned. If trying to overwrite a directory with a directory the
3233 * G_IO_ERROR_WOULD_MERGE error is returned.
3235 * If the source is a directory and the target does not exist, or #G_FILE_COPY_OVERWRITE is
3236 * specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error
3237 * may be returned (if the native move operation isn't available).
3239 * Returns: %TRUE on successful move, %FALSE otherwise.
3242 g_file_move (GFile *source,
3244 GFileCopyFlags flags,
3245 GCancellable *cancellable,
3246 GFileProgressCallback progress_callback,
3247 gpointer progress_callback_data,
3254 g_return_val_if_fail (G_IS_FILE (source), FALSE);
3255 g_return_val_if_fail (G_IS_FILE (destination), FALSE);
3257 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3260 iface = G_FILE_GET_IFACE (destination);
3264 res = (* iface->move) (source, destination,
3266 progress_callback, progress_callback_data,
3272 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3274 g_propagate_error (error, my_error);
3279 /* If the types are different, and the destination method failed
3280 also try the source method */
3281 if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
3283 iface = G_FILE_GET_IFACE (source);
3288 res = (* iface->move) (source, destination,
3290 progress_callback, progress_callback_data,
3296 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3298 g_propagate_error (error, my_error);
3304 if (flags & G_FILE_COPY_NO_FALLBACK_FOR_MOVE)
3306 g_set_error_literal (error, G_IO_ERROR,
3307 G_IO_ERROR_NOT_SUPPORTED,
3308 _("Operation not supported"));
3312 flags |= G_FILE_COPY_ALL_METADATA;
3313 if (!g_file_copy (source, destination, flags, cancellable,
3314 progress_callback, progress_callback_data,
3318 return g_file_delete (source, cancellable, error);
3322 * g_file_make_directory
3323 * @file: input #GFile.
3324 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3325 * @error: a #GError, or %NULL
3327 * Creates a directory. Note that this will only create a child directory of
3328 * the immediate parent directory of the path or URI given by the #GFile. To
3329 * recursively create directories, see g_file_make_directory_with_parents().
3330 * This function will fail if the parent directory does not exist, setting
3331 * @error to %G_IO_ERROR_NOT_FOUND. If the file system doesn't support creating
3332 * directories, this function will fail, setting @error to
3333 * %G_IO_ERROR_NOT_SUPPORTED.
3335 * For a local #GFile the newly created directory will have the default
3336 * (current) ownership and permissions of the current process.
3338 * If @cancellable is not %NULL, then the operation can be cancelled by
3339 * triggering the cancellable object from another thread. If the operation
3340 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3342 * Returns: %TRUE on successful creation, %FALSE otherwise.
3345 g_file_make_directory (GFile *file,
3346 GCancellable *cancellable,
3351 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3353 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3356 iface = G_FILE_GET_IFACE (file);
3358 if (iface->make_directory == NULL)
3360 g_set_error_literal (error, G_IO_ERROR,
3361 G_IO_ERROR_NOT_SUPPORTED,
3362 _("Operation not supported"));
3366 return (* iface->make_directory) (file, cancellable, error);
3370 * g_file_make_directory_with_parents:
3371 * @file: input #GFile.
3372 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3373 * @error: a #GError, or %NULL
3375 * Creates a directory and any parent directories that may not exist similar to
3376 * 'mkdir -p'. If the file system does not support creating directories, this
3377 * function will fail, setting @error to %G_IO_ERROR_NOT_SUPPORTED.
3379 * For a local #GFile the newly created directories will have the default
3380 * (current) ownership and permissions of the current process.
3382 * If @cancellable is not %NULL, then the operation can be cancelled by
3383 * triggering the cancellable object from another thread. If the operation
3384 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3386 * Returns: %TRUE if all directories have been successfully created, %FALSE
3392 g_file_make_directory_with_parents (GFile *file,
3393 GCancellable *cancellable,
3397 GFile *parent_file, *work_file;
3398 GList *list = NULL, *l;
3399 GError *my_error = NULL;
3401 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3404 result = g_file_make_directory (file, cancellable, &my_error);
3405 if (result || my_error->code != G_IO_ERROR_NOT_FOUND)
3408 g_propagate_error (error, my_error);
3414 while (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
3416 g_clear_error (&my_error);
3418 parent_file = g_file_get_parent (work_file);
3419 if (parent_file == NULL)
3421 result = g_file_make_directory (parent_file, cancellable, &my_error);
3423 if (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
3424 list = g_list_prepend (list, parent_file);
3426 work_file = parent_file;
3429 for (l = list; result && l; l = l->next)
3431 result = g_file_make_directory ((GFile *) l->data, cancellable, &my_error);
3435 while (list != NULL)
3437 g_object_unref ((GFile *) list->data);
3438 list = g_list_remove (list, list->data);
3443 g_propagate_error (error, my_error);
3447 return g_file_make_directory (file, cancellable, error);
3451 * g_file_make_symbolic_link:
3452 * @file: a #GFile with the name of the symlink to create
3453 * @symlink_value: a string with the path for the target of the new symlink
3454 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3455 * @error: a #GError.
3457 * Creates a symbolic link named @file which contains the string
3460 * If @cancellable is not %NULL, then the operation can be cancelled by
3461 * triggering the cancellable object from another thread. If the operation
3462 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3464 * Returns: %TRUE on the creation of a new symlink, %FALSE otherwise.
3467 g_file_make_symbolic_link (GFile *file,
3468 const char *symlink_value,
3469 GCancellable *cancellable,
3474 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3475 g_return_val_if_fail (symlink_value != NULL, FALSE);
3477 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3480 if (*symlink_value == '\0')
3482 g_set_error_literal (error, G_IO_ERROR,
3483 G_IO_ERROR_INVALID_ARGUMENT,
3484 _("Invalid symlink value given"));
3488 iface = G_FILE_GET_IFACE (file);
3490 if (iface->make_symbolic_link == NULL)
3492 g_set_error_literal (error, G_IO_ERROR,
3493 G_IO_ERROR_NOT_SUPPORTED,
3494 _("Operation not supported"));
3498 return (* iface->make_symbolic_link) (file, symlink_value, cancellable, error);
3503 * @file: input #GFile.
3504 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3505 * @error: a #GError, or %NULL
3507 * Deletes a file. If the @file is a directory, it will only be deleted if it
3510 * If @cancellable is not %NULL, then the operation can be cancelled by
3511 * triggering the cancellable object from another thread. If the operation
3512 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3514 * Virtual: delete_file
3515 * Returns: %TRUE if the file was deleted. %FALSE otherwise.
3518 g_file_delete (GFile *file,
3519 GCancellable *cancellable,
3524 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3526 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3529 iface = G_FILE_GET_IFACE (file);
3531 if (iface->delete_file == NULL)
3533 g_set_error_literal (error, G_IO_ERROR,
3534 G_IO_ERROR_NOT_SUPPORTED,
3535 _("Operation not supported"));
3539 return (* iface->delete_file) (file, cancellable, error);
3544 * @file: #GFile to send to trash.
3545 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3546 * @error: a #GError, or %NULL
3548 * Sends @file to the "Trashcan", if possible. This is similar to
3549 * deleting it, but the user can recover it before emptying the trashcan.
3550 * Not all file systems support trashing, so this call can return the
3551 * %G_IO_ERROR_NOT_SUPPORTED error.
3554 * If @cancellable is not %NULL, then the operation can be cancelled by
3555 * triggering the cancellable object from another thread. If the operation
3556 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3558 * Returns: %TRUE on successful trash, %FALSE otherwise.
3561 g_file_trash (GFile *file,
3562 GCancellable *cancellable,
3567 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3569 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3572 iface = G_FILE_GET_IFACE (file);
3574 if (iface->trash == NULL)
3576 g_set_error_literal (error,
3577 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
3578 _("Trash not supported"));
3582 return (* iface->trash) (file, cancellable, error);
3586 * g_file_set_display_name:
3587 * @file: input #GFile.
3588 * @display_name: a string.
3589 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3590 * @error: a #GError, or %NULL
3592 * Renames @file to the specified display name.
3594 * The display name is converted from UTF8 to the correct encoding for the target
3595 * filesystem if possible and the @file is renamed to this.
3597 * If you want to implement a rename operation in the user interface the edit name
3598 * (#G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the initial value in the rename
3599 * widget, and then the result after editing should be passed to g_file_set_display_name().
3601 * On success the resulting converted filename is returned.
3603 * If @cancellable is not %NULL, then the operation can be cancelled by
3604 * triggering the cancellable object from another thread. If the operation
3605 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3607 * Returns: (transfer full): a #GFile specifying what @file was renamed to, or %NULL
3608 * if there was an error.
3609 * Free the returned object with g_object_unref().
3612 g_file_set_display_name (GFile *file,
3613 const char *display_name,
3614 GCancellable *cancellable,
3619 g_return_val_if_fail (G_IS_FILE (file), NULL);
3620 g_return_val_if_fail (display_name != NULL, NULL);
3622 if (strchr (display_name, G_DIR_SEPARATOR) != NULL)
3626 G_IO_ERROR_INVALID_ARGUMENT,
3627 _("File names cannot contain '%c'"), G_DIR_SEPARATOR);
3631 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3634 iface = G_FILE_GET_IFACE (file);
3636 return (* iface->set_display_name) (file, display_name, cancellable, error);
3640 * g_file_set_display_name_async:
3641 * @file: input #GFile.
3642 * @display_name: a string.
3643 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3645 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3646 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
3647 * @user_data: (closure): the data to pass to callback function
3649 * Asynchronously sets the display name for a given #GFile.
3651 * For more details, see g_file_set_display_name() which is
3652 * the synchronous version of this call.
3654 * When the operation is finished, @callback will be called. You can then call
3655 * g_file_set_display_name_finish() to get the result of the operation.
3658 g_file_set_display_name_async (GFile *file,
3659 const char *display_name,
3661 GCancellable *cancellable,
3662 GAsyncReadyCallback callback,
3667 g_return_if_fail (G_IS_FILE (file));
3668 g_return_if_fail (display_name != NULL);
3670 iface = G_FILE_GET_IFACE (file);
3671 (* iface->set_display_name_async) (file,
3680 * g_file_set_display_name_finish:
3681 * @file: input #GFile.
3682 * @res: a #GAsyncResult.
3683 * @error: a #GError, or %NULL
3685 * Finishes setting a display name started with
3686 * g_file_set_display_name_async().
3688 * Returns: (transfer full): a #GFile or %NULL on error.
3689 * Free the returned object with g_object_unref().
3692 g_file_set_display_name_finish (GFile *file,
3698 g_return_val_if_fail (G_IS_FILE (file), NULL);
3699 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
3701 if (G_IS_SIMPLE_ASYNC_RESULT (res))
3703 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
3704 if (g_simple_async_result_propagate_error (simple, error))
3708 iface = G_FILE_GET_IFACE (file);
3709 return (* iface->set_display_name_finish) (file, res, error);
3713 * g_file_query_settable_attributes:
3714 * @file: input #GFile.
3715 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3716 * @error: a #GError, or %NULL
3718 * Obtain the list of settable attributes for the file.
3720 * Returns the type and full attribute name of all the attributes
3721 * that can be set on this file. This doesn't mean setting it will always
3722 * succeed though, you might get an access failure, or some specific
3723 * file may not support a specific attribute.
3725 * If @cancellable is not %NULL, then the operation can be cancelled by
3726 * triggering the cancellable object from another thread. If the operation
3727 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3729 * Returns: a #GFileAttributeInfoList describing the settable attributes.
3730 * When you are done with it, release it with g_file_attribute_info_list_unref()
3732 GFileAttributeInfoList *
3733 g_file_query_settable_attributes (GFile *file,
3734 GCancellable *cancellable,
3739 GFileAttributeInfoList *list;
3741 g_return_val_if_fail (G_IS_FILE (file), NULL);
3743 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3746 iface = G_FILE_GET_IFACE (file);
3748 if (iface->query_settable_attributes == NULL)
3749 return g_file_attribute_info_list_new ();
3752 list = (* iface->query_settable_attributes) (file, cancellable, &my_error);
3756 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
3758 list = g_file_attribute_info_list_new ();
3759 g_error_free (my_error);
3762 g_propagate_error (error, my_error);
3769 * g_file_query_writable_namespaces:
3770 * @file: input #GFile.
3771 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3772 * @error: a #GError, or %NULL
3774 * Obtain the list of attribute namespaces where new attributes
3775 * can be created by a user. An example of this is extended
3776 * attributes (in the "xattr" namespace).
3778 * If @cancellable is not %NULL, then the operation can be cancelled by
3779 * triggering the cancellable object from another thread. If the operation
3780 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3782 * Returns: a #GFileAttributeInfoList describing the writable namespaces.
3783 * When you are done with it, release it with g_file_attribute_info_list_unref()
3785 GFileAttributeInfoList *
3786 g_file_query_writable_namespaces (GFile *file,
3787 GCancellable *cancellable,
3792 GFileAttributeInfoList *list;
3794 g_return_val_if_fail (G_IS_FILE (file), NULL);
3796 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3799 iface = G_FILE_GET_IFACE (file);
3801 if (iface->query_writable_namespaces == NULL)
3802 return g_file_attribute_info_list_new ();
3805 list = (* iface->query_writable_namespaces) (file, cancellable, &my_error);
3809 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
3811 list = g_file_attribute_info_list_new ();
3812 g_error_free (my_error);
3815 g_propagate_error (error, my_error);
3822 * g_file_set_attribute:
3823 * @file: input #GFile.
3824 * @attribute: a string containing the attribute's name.
3825 * @type: The type of the attribute
3826 * @value_p: a pointer to the value (or the pointer itself if the type is a pointer type)
3827 * @flags: a set of #GFileQueryInfoFlags.
3828 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3829 * @error: a #GError, or %NULL
3831 * Sets an attribute in the file with attribute name @attribute to @value.
3833 * If @cancellable is not %NULL, then the operation can be cancelled by
3834 * triggering the cancellable object from another thread. If the operation
3835 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3837 * Returns: %TRUE if the attribute was set, %FALSE otherwise.
3840 g_file_set_attribute (GFile *file,
3841 const char *attribute,
3842 GFileAttributeType type,
3844 GFileQueryInfoFlags flags,
3845 GCancellable *cancellable,
3850 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3851 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
3853 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3856 iface = G_FILE_GET_IFACE (file);
3858 if (iface->set_attribute == NULL)
3860 g_set_error_literal (error, G_IO_ERROR,
3861 G_IO_ERROR_NOT_SUPPORTED,
3862 _("Operation not supported"));
3866 return (* iface->set_attribute) (file, attribute, type, value_p, flags, cancellable, error);
3870 * g_file_set_attributes_from_info:
3871 * @file: input #GFile.
3872 * @info: a #GFileInfo.
3873 * @flags: #GFileQueryInfoFlags
3874 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3875 * @error: a #GError, or %NULL
3877 * Tries to set all attributes in the #GFileInfo on the target values,
3878 * not stopping on the first error.
3880 * If there is any error during this operation then @error will be set to
3881 * the first error. Error on particular fields are flagged by setting
3882 * the "status" field in the attribute value to
3883 * %G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can also detect
3886 * If @cancellable is not %NULL, then the operation can be cancelled by
3887 * triggering the cancellable object from another thread. If the operation
3888 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3890 * Returns: %TRUE if there was any error, %FALSE otherwise.
3893 g_file_set_attributes_from_info (GFile *file,
3895 GFileQueryInfoFlags flags,
3896 GCancellable *cancellable,
3901 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3902 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
3904 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3907 g_file_info_clear_status (info);
3909 iface = G_FILE_GET_IFACE (file);
3911 return (* iface->set_attributes_from_info) (file,
3920 g_file_real_set_attributes_from_info (GFile *file,
3922 GFileQueryInfoFlags flags,
3923 GCancellable *cancellable,
3929 GFileAttributeValue *value;
3933 attributes = g_file_info_list_attributes (info, NULL);
3935 for (i = 0; attributes[i] != NULL; i++)
3937 value = _g_file_info_get_attribute_value (info, attributes[i]);
3939 if (value->status != G_FILE_ATTRIBUTE_STATUS_UNSET)
3942 if (!g_file_set_attribute (file, attributes[i],
3943 value->type, _g_file_attribute_value_peek_as_pointer (value),
3944 flags, cancellable, error))
3946 value->status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
3948 /* Don't set error multiple times */
3952 value->status = G_FILE_ATTRIBUTE_STATUS_SET;
3955 g_strfreev (attributes);
3961 * g_file_set_attributes_async:
3962 * @file: input #GFile.
3963 * @info: a #GFileInfo.
3964 * @flags: a #GFileQueryInfoFlags.
3965 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3967 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
3968 * @callback: (scope async): a #GAsyncReadyCallback.
3969 * @user_data: (closure): a #gpointer.
3971 * Asynchronously sets the attributes of @file with @info.
3973 * For more details, see g_file_set_attributes_from_info() which is
3974 * the synchronous version of this call.
3976 * When the operation is finished, @callback will be called. You can then call
3977 * g_file_set_attributes_finish() to get the result of the operation.
3980 g_file_set_attributes_async (GFile *file,
3982 GFileQueryInfoFlags flags,
3984 GCancellable *cancellable,
3985 GAsyncReadyCallback callback,
3990 g_return_if_fail (G_IS_FILE (file));
3991 g_return_if_fail (G_IS_FILE_INFO (info));
3993 iface = G_FILE_GET_IFACE (file);
3994 (* iface->set_attributes_async) (file,
4004 * g_file_set_attributes_finish:
4005 * @file: input #GFile.
4006 * @result: a #GAsyncResult.
4007 * @info: (out) (transfer full): a #GFileInfo.
4008 * @error: a #GError, or %NULL
4010 * Finishes setting an attribute started in g_file_set_attributes_async().
4012 * Returns: %TRUE if the attributes were set correctly, %FALSE otherwise.
4015 g_file_set_attributes_finish (GFile *file,
4016 GAsyncResult *result,
4022 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4023 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4025 /* No standard handling of errors here, as we must set info even
4028 iface = G_FILE_GET_IFACE (file);
4029 return (* iface->set_attributes_finish) (file, result, info, error);
4033 * g_file_set_attribute_string:
4034 * @file: input #GFile.
4035 * @attribute: a string containing the attribute's name.
4036 * @value: a string containing the attribute's value.
4037 * @flags: #GFileQueryInfoFlags.
4038 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4039 * @error: a #GError, or %NULL
4041 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value.
4042 * If @attribute is of a different type, this operation will fail.
4044 * If @cancellable is not %NULL, then the operation can be cancelled by
4045 * triggering the cancellable object from another thread. If the operation
4046 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4048 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
4051 g_file_set_attribute_string (GFile *file,
4052 const char *attribute,
4054 GFileQueryInfoFlags flags,
4055 GCancellable *cancellable,
4058 return g_file_set_attribute (file, attribute,
4059 G_FILE_ATTRIBUTE_TYPE_STRING, (gpointer)value,
4060 flags, cancellable, error);
4064 * g_file_set_attribute_byte_string:
4065 * @file: input #GFile.
4066 * @attribute: a string containing the attribute's name.
4067 * @value: a string containing the attribute's new value.
4068 * @flags: a #GFileQueryInfoFlags.
4069 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4070 * @error: a #GError, or %NULL
4072 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value.
4073 * If @attribute is of a different type, this operation will fail,
4076 * If @cancellable is not %NULL, then the operation can be cancelled by
4077 * triggering the cancellable object from another thread. If the operation
4078 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4080 * Returns: %TRUE if the @attribute was successfully set to @value
4081 * in the @file, %FALSE otherwise.
4084 g_file_set_attribute_byte_string (GFile *file,
4085 const char *attribute,
4087 GFileQueryInfoFlags flags,
4088 GCancellable *cancellable,
4091 return g_file_set_attribute (file, attribute,
4092 G_FILE_ATTRIBUTE_TYPE_BYTE_STRING, (gpointer)value,
4093 flags, cancellable, error);
4097 * g_file_set_attribute_uint32:
4098 * @file: input #GFile.
4099 * @attribute: a string containing the attribute's name.
4100 * @value: a #guint32 containing the attribute's new value.
4101 * @flags: a #GFileQueryInfoFlags.
4102 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4103 * @error: a #GError, or %NULL
4105 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value.
4106 * If @attribute is of a different type, this operation will fail.
4108 * If @cancellable is not %NULL, then the operation can be cancelled by
4109 * triggering the cancellable object from another thread. If the operation
4110 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4112 * Returns: %TRUE if the @attribute was successfully set to @value
4113 * in the @file, %FALSE otherwise.
4116 g_file_set_attribute_uint32 (GFile *file,
4117 const char *attribute,
4119 GFileQueryInfoFlags flags,
4120 GCancellable *cancellable,
4123 return g_file_set_attribute (file, attribute,
4124 G_FILE_ATTRIBUTE_TYPE_UINT32, &value,
4125 flags, cancellable, error);
4129 * g_file_set_attribute_int32:
4130 * @file: input #GFile.
4131 * @attribute: a string containing the attribute's name.
4132 * @value: a #gint32 containing the attribute's new value.
4133 * @flags: a #GFileQueryInfoFlags.
4134 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4135 * @error: a #GError, or %NULL
4137 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value.
4138 * If @attribute is of a different type, this operation will fail.
4140 * If @cancellable is not %NULL, then the operation can be cancelled by
4141 * triggering the cancellable object from another thread. If the operation
4142 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4144 * Returns: %TRUE if the @attribute was successfully set to @value
4145 * in the @file, %FALSE otherwise.
4148 g_file_set_attribute_int32 (GFile *file,
4149 const char *attribute,
4151 GFileQueryInfoFlags flags,
4152 GCancellable *cancellable,
4155 return g_file_set_attribute (file, attribute,
4156 G_FILE_ATTRIBUTE_TYPE_INT32, &value,
4157 flags, cancellable, error);
4161 * g_file_set_attribute_uint64:
4162 * @file: input #GFile.
4163 * @attribute: a string containing the attribute's name.
4164 * @value: a #guint64 containing the attribute's new value.
4165 * @flags: a #GFileQueryInfoFlags.
4166 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4167 * @error: a #GError, or %NULL
4169 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value.
4170 * If @attribute is of a different type, this operation will fail.
4172 * If @cancellable is not %NULL, then the operation can be cancelled by
4173 * triggering the cancellable object from another thread. If the operation
4174 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4176 * Returns: %TRUE if the @attribute was successfully set to @value
4177 * in the @file, %FALSE otherwise.
4180 g_file_set_attribute_uint64 (GFile *file,
4181 const char *attribute,
4183 GFileQueryInfoFlags flags,
4184 GCancellable *cancellable,
4187 return g_file_set_attribute (file, attribute,
4188 G_FILE_ATTRIBUTE_TYPE_UINT64, &value,
4189 flags, cancellable, error);
4193 * g_file_set_attribute_int64:
4194 * @file: input #GFile.
4195 * @attribute: a string containing the attribute's name.
4196 * @value: a #guint64 containing the attribute's new value.
4197 * @flags: a #GFileQueryInfoFlags.
4198 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4199 * @error: a #GError, or %NULL
4201 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value.
4202 * If @attribute is of a different type, this operation will fail.
4204 * If @cancellable is not %NULL, then the operation can be cancelled by
4205 * triggering the cancellable object from another thread. If the operation
4206 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4208 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
4211 g_file_set_attribute_int64 (GFile *file,
4212 const char *attribute,
4214 GFileQueryInfoFlags flags,
4215 GCancellable *cancellable,
4218 return g_file_set_attribute (file, attribute,
4219 G_FILE_ATTRIBUTE_TYPE_INT64, &value,
4220 flags, cancellable, error);
4224 * g_file_mount_mountable:
4225 * @file: input #GFile.
4226 * @flags: flags affecting the operation
4227 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
4228 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4229 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4230 * @user_data: (closure): the data to pass to callback function
4232 * Mounts a file of type G_FILE_TYPE_MOUNTABLE.
4233 * Using @mount_operation, you can request callbacks when, for instance,
4234 * passwords are needed during authentication.
4236 * If @cancellable is not %NULL, then the operation can be cancelled by
4237 * triggering the cancellable object from another thread. If the operation
4238 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4240 * When the operation is finished, @callback will be called. You can then call
4241 * g_file_mount_mountable_finish() to get the result of the operation.
4244 g_file_mount_mountable (GFile *file,
4245 GMountMountFlags flags,
4246 GMountOperation *mount_operation,
4247 GCancellable *cancellable,
4248 GAsyncReadyCallback callback,
4253 g_return_if_fail (G_IS_FILE (file));
4255 iface = G_FILE_GET_IFACE (file);
4257 if (iface->mount_mountable == NULL)
4259 g_simple_async_report_error_in_idle (G_OBJECT (file),
4263 G_IO_ERROR_NOT_SUPPORTED,
4264 _("Operation not supported"));
4268 (* iface->mount_mountable) (file,
4277 * g_file_mount_mountable_finish:
4278 * @file: input #GFile.
4279 * @result: a #GAsyncResult.
4280 * @error: a #GError, or %NULL
4282 * Finishes a mount operation. See g_file_mount_mountable() for details.
4284 * Finish an asynchronous mount operation that was started
4285 * with g_file_mount_mountable().
4287 * Returns: (transfer full): a #GFile or %NULL on error.
4288 * Free the returned object with g_object_unref().
4291 g_file_mount_mountable_finish (GFile *file,
4292 GAsyncResult *result,
4297 g_return_val_if_fail (G_IS_FILE (file), NULL);
4298 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
4300 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4302 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4303 if (g_simple_async_result_propagate_error (simple, error))
4307 iface = G_FILE_GET_IFACE (file);
4308 return (* iface->mount_mountable_finish) (file, result, error);
4312 * g_file_unmount_mountable:
4313 * @file: input #GFile.
4314 * @flags: flags affecting the operation
4315 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4316 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4317 * @user_data: (closure): the data to pass to callback function
4319 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
4321 * If @cancellable is not %NULL, then the operation can be cancelled by
4322 * triggering the cancellable object from another thread. If the operation
4323 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4325 * When the operation is finished, @callback will be called. You can then call
4326 * g_file_unmount_mountable_finish() to get the result of the operation.
4328 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation() instead.
4331 g_file_unmount_mountable (GFile *file,
4332 GMountUnmountFlags flags,
4333 GCancellable *cancellable,
4334 GAsyncReadyCallback callback,
4339 g_return_if_fail (G_IS_FILE (file));
4341 iface = G_FILE_GET_IFACE (file);
4343 if (iface->unmount_mountable == NULL)
4345 g_simple_async_report_error_in_idle (G_OBJECT (file),
4349 G_IO_ERROR_NOT_SUPPORTED,
4350 _("Operation not supported"));
4354 (* iface->unmount_mountable) (file,
4362 * g_file_unmount_mountable_finish:
4363 * @file: input #GFile.
4364 * @result: a #GAsyncResult.
4365 * @error: a #GError, or %NULL
4367 * Finishes an unmount operation, see g_file_unmount_mountable() for details.
4369 * Finish an asynchronous unmount operation that was started
4370 * with g_file_unmount_mountable().
4372 * Returns: %TRUE if the operation finished successfully. %FALSE
4375 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation_finish() instead.
4378 g_file_unmount_mountable_finish (GFile *file,
4379 GAsyncResult *result,
4384 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4385 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4387 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4389 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4390 if (g_simple_async_result_propagate_error (simple, error))
4394 iface = G_FILE_GET_IFACE (file);
4395 return (* iface->unmount_mountable_finish) (file, result, error);
4399 * g_file_unmount_mountable_with_operation:
4400 * @file: input #GFile.
4401 * @flags: flags affecting the operation
4402 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
4403 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4404 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4405 * @user_data: (closure): the data to pass to callback function
4407 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
4409 * If @cancellable is not %NULL, then the operation can be cancelled by
4410 * triggering the cancellable object from another thread. If the operation
4411 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4413 * When the operation is finished, @callback will be called. You can then call
4414 * g_file_unmount_mountable_finish() to get the result of the operation.
4419 g_file_unmount_mountable_with_operation (GFile *file,
4420 GMountUnmountFlags flags,
4421 GMountOperation *mount_operation,
4422 GCancellable *cancellable,
4423 GAsyncReadyCallback callback,
4428 g_return_if_fail (G_IS_FILE (file));
4430 iface = G_FILE_GET_IFACE (file);
4432 if (iface->unmount_mountable == NULL && iface->unmount_mountable_with_operation == NULL)
4434 g_simple_async_report_error_in_idle (G_OBJECT (file),
4438 G_IO_ERROR_NOT_SUPPORTED,
4439 _("Operation not supported"));
4443 if (iface->unmount_mountable_with_operation != NULL)
4444 (* iface->unmount_mountable_with_operation) (file,
4451 (* iface->unmount_mountable) (file,
4459 * g_file_unmount_mountable_with_operation_finish:
4460 * @file: input #GFile.
4461 * @result: a #GAsyncResult.
4462 * @error: a #GError, or %NULL
4464 * Finishes an unmount operation, see g_file_unmount_mountable_with_operation() for details.
4466 * Finish an asynchronous unmount operation that was started
4467 * with g_file_unmount_mountable_with_operation().
4469 * Returns: %TRUE if the operation finished successfully. %FALSE
4475 g_file_unmount_mountable_with_operation_finish (GFile *file,
4476 GAsyncResult *result,
4481 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4482 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4484 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4486 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4487 if (g_simple_async_result_propagate_error (simple, error))
4491 iface = G_FILE_GET_IFACE (file);
4492 if (iface->unmount_mountable_with_operation_finish != NULL)
4493 return (* iface->unmount_mountable_with_operation_finish) (file, result, error);
4495 return (* iface->unmount_mountable_finish) (file, result, error);
4499 * g_file_eject_mountable:
4500 * @file: input #GFile.
4501 * @flags: flags affecting the operation
4502 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4503 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4504 * @user_data: (closure): the data to pass to callback function
4506 * Starts an asynchronous eject on a mountable.
4507 * When this operation has completed, @callback will be called with
4508 * @user_user data, and the operation can be finalized with
4509 * g_file_eject_mountable_finish().
4511 * If @cancellable is not %NULL, then the operation can be cancelled by
4512 * triggering the cancellable object from another thread. If the operation
4513 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4515 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation() instead.
4518 g_file_eject_mountable (GFile *file,
4519 GMountUnmountFlags flags,
4520 GCancellable *cancellable,
4521 GAsyncReadyCallback callback,
4526 g_return_if_fail (G_IS_FILE (file));
4528 iface = G_FILE_GET_IFACE (file);
4530 if (iface->eject_mountable == NULL)
4532 g_simple_async_report_error_in_idle (G_OBJECT (file),
4536 G_IO_ERROR_NOT_SUPPORTED,
4537 _("Operation not supported"));
4541 (* iface->eject_mountable) (file,
4549 * g_file_eject_mountable_finish:
4550 * @file: input #GFile.
4551 * @result: a #GAsyncResult.
4552 * @error: a #GError, or %NULL
4554 * Finishes an asynchronous eject operation started by
4555 * g_file_eject_mountable().
4557 * Returns: %TRUE if the @file was ejected successfully. %FALSE
4560 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation_finish() instead.
4563 g_file_eject_mountable_finish (GFile *file,
4564 GAsyncResult *result,
4569 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4570 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4572 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4574 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4575 if (g_simple_async_result_propagate_error (simple, error))
4579 iface = G_FILE_GET_IFACE (file);
4580 return (* iface->eject_mountable_finish) (file, result, error);
4584 * g_file_eject_mountable_with_operation:
4585 * @file: input #GFile.
4586 * @flags: flags affecting the operation
4587 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
4588 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4589 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
4590 * @user_data: (closure): the data to pass to callback function
4592 * Starts an asynchronous eject on a mountable.
4593 * When this operation has completed, @callback will be called with
4594 * @user_user data, and the operation can be finalized with
4595 * g_file_eject_mountable_with_operation_finish().
4597 * If @cancellable is not %NULL, then the operation can be cancelled by
4598 * triggering the cancellable object from another thread. If the operation
4599 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4604 g_file_eject_mountable_with_operation (GFile *file,
4605 GMountUnmountFlags flags,
4606 GMountOperation *mount_operation,
4607 GCancellable *cancellable,
4608 GAsyncReadyCallback callback,
4613 g_return_if_fail (G_IS_FILE (file));
4615 iface = G_FILE_GET_IFACE (file);
4617 if (iface->eject_mountable == NULL && iface->eject_mountable_with_operation == NULL)
4619 g_simple_async_report_error_in_idle (G_OBJECT (file),
4623 G_IO_ERROR_NOT_SUPPORTED,
4624 _("Operation not supported"));
4628 if (iface->eject_mountable_with_operation != NULL)
4629 (* iface->eject_mountable_with_operation) (file,
4636 (* iface->eject_mountable) (file,
4644 * g_file_eject_mountable_with_operation_finish:
4645 * @file: input #GFile.
4646 * @result: a #GAsyncResult.
4647 * @error: a #GError, or %NULL
4649 * Finishes an asynchronous eject operation started by
4650 * g_file_eject_mountable_with_operation().
4652 * Returns: %TRUE if the @file was ejected successfully. %FALSE
4658 g_file_eject_mountable_with_operation_finish (GFile *file,
4659 GAsyncResult *result,
4664 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4665 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4667 if (G_IS_SIMPLE_ASYNC_RESULT (result))
4669 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
4670 if (g_simple_async_result_propagate_error (simple, error))
4674 iface = G_FILE_GET_IFACE (file);
4675 if (iface->eject_mountable_with_operation_finish != NULL)
4676 return (* iface->eject_mountable_with_operation_finish) (file, result, error);
4678 return (* iface->eject_mountable_finish) (file, result, error);
4682 * g_file_monitor_directory:
4683 * @file: input #GFile.
4684 * @flags: a set of #GFileMonitorFlags.
4685 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4686 * @error: a #GError, or %NULL.
4688 * Obtains a directory monitor for the given file.
4689 * This may fail if directory monitoring is not supported.
4691 * If @cancellable is not %NULL, then the operation can be cancelled by
4692 * triggering the cancellable object from another thread. If the operation
4693 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4695 * Virtual: monitor_dir
4696 * Returns: (transfer full): a #GFileMonitor for the given @file, or %NULL on error.
4697 * Free the returned object with g_object_unref().
4700 g_file_monitor_directory (GFile *file,
4701 GFileMonitorFlags flags,
4702 GCancellable *cancellable,
4707 g_return_val_if_fail (G_IS_FILE (file), NULL);
4709 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4712 iface = G_FILE_GET_IFACE (file);
4714 if (iface->monitor_dir == NULL)
4716 g_set_error_literal (error, G_IO_ERROR,
4717 G_IO_ERROR_NOT_SUPPORTED,
4718 _("Operation not supported"));
4722 return (* iface->monitor_dir) (file, flags, cancellable, error);
4726 * g_file_monitor_file:
4727 * @file: input #GFile.
4728 * @flags: a set of #GFileMonitorFlags.
4729 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
4730 * @error: a #GError, or %NULL.
4732 * Obtains a file monitor for the given file. If no file notification
4733 * mechanism exists, then regular polling of the file is used.
4735 * If @cancellable is not %NULL, then the operation can be cancelled by
4736 * triggering the cancellable object from another thread. If the operation
4737 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4739 * Returns: (transfer full): a #GFileMonitor for the given @file, or %NULL on error.
4740 * Free the returned object with g_object_unref().
4743 g_file_monitor_file (GFile *file,
4744 GFileMonitorFlags flags,
4745 GCancellable *cancellable,
4749 GFileMonitor *monitor;
4751 g_return_val_if_fail (G_IS_FILE (file), NULL);
4753 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4756 iface = G_FILE_GET_IFACE (file);
4760 if (iface->monitor_file)
4761 monitor = (* iface->monitor_file) (file, flags, cancellable, NULL);
4763 /* Fallback to polling */
4764 if (monitor == NULL)
4765 monitor = _g_poll_file_monitor_new (file);
4772 * @file: input #GFile
4773 * @flags: a set of #GFileMonitorFlags
4774 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
4775 * @error: a #GError, or %NULL
4777 * Obtains a file or directory monitor for the given file, depending
4778 * on the type of the file.
4780 * If @cancellable is not %NULL, then the operation can be cancelled by
4781 * triggering the cancellable object from another thread. If the operation
4782 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4784 * Returns: (transfer full): a #GFileMonitor for the given @file, or %NULL on error.
4785 * Free the returned object with g_object_unref().
4790 g_file_monitor (GFile *file,
4791 GFileMonitorFlags flags,
4792 GCancellable *cancellable,
4795 if (g_file_query_file_type (file, 0, cancellable) == G_FILE_TYPE_DIRECTORY)
4796 return g_file_monitor_directory (file, flags, cancellable, error);
4798 return g_file_monitor_file (file, flags, cancellable, error);
4801 /********************************************
4802 * Default implementation of async ops *
4803 ********************************************/
4807 GFileQueryInfoFlags flags;
4809 } QueryInfoAsyncData;
4812 query_info_data_free (QueryInfoAsyncData *data)
4815 g_object_unref (data->info);
4816 g_free (data->attributes);
4821 query_info_async_thread (GSimpleAsyncResult *res,
4823 GCancellable *cancellable)
4825 GError *error = NULL;
4826 QueryInfoAsyncData *data;
4829 data = g_simple_async_result_get_op_res_gpointer (res);
4831 info = g_file_query_info (G_FILE (object), data->attributes, data->flags, cancellable, &error);
4834 g_simple_async_result_take_error (res, error);
4840 g_file_real_query_info_async (GFile *file,
4841 const char *attributes,
4842 GFileQueryInfoFlags flags,
4844 GCancellable *cancellable,
4845 GAsyncReadyCallback callback,
4848 GSimpleAsyncResult *res;
4849 QueryInfoAsyncData *data;
4851 data = g_new0 (QueryInfoAsyncData, 1);
4852 data->attributes = g_strdup (attributes);
4853 data->flags = flags;
4855 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_query_info_async);
4856 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_info_data_free);
4858 g_simple_async_result_run_in_thread (res, query_info_async_thread, io_priority, cancellable);
4859 g_object_unref (res);
4863 g_file_real_query_info_finish (GFile *file,
4867 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4868 QueryInfoAsyncData *data;
4870 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_info_async);
4872 data = g_simple_async_result_get_op_res_gpointer (simple);
4874 return g_object_ref (data->info);
4882 } QueryFilesystemInfoAsyncData;
4885 query_filesystem_info_data_free (QueryFilesystemInfoAsyncData *data)
4888 g_object_unref (data->info);
4889 g_free (data->attributes);
4894 query_filesystem_info_async_thread (GSimpleAsyncResult *res,
4896 GCancellable *cancellable)
4898 GError *error = NULL;
4899 QueryFilesystemInfoAsyncData *data;
4902 data = g_simple_async_result_get_op_res_gpointer (res);
4904 info = g_file_query_filesystem_info (G_FILE (object), data->attributes, cancellable, &error);
4907 g_simple_async_result_take_error (res, error);
4913 g_file_real_query_filesystem_info_async (GFile *file,
4914 const char *attributes,
4916 GCancellable *cancellable,
4917 GAsyncReadyCallback callback,
4920 GSimpleAsyncResult *res;
4921 QueryFilesystemInfoAsyncData *data;
4923 data = g_new0 (QueryFilesystemInfoAsyncData, 1);
4924 data->attributes = g_strdup (attributes);
4926 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_query_filesystem_info_async);
4927 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_filesystem_info_data_free);
4929 g_simple_async_result_run_in_thread (res, query_filesystem_info_async_thread, io_priority, cancellable);
4930 g_object_unref (res);
4934 g_file_real_query_filesystem_info_finish (GFile *file,
4938 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
4939 QueryFilesystemInfoAsyncData *data;
4941 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_filesystem_info_async);
4943 data = g_simple_async_result_get_op_res_gpointer (simple);
4945 return g_object_ref (data->info);
4952 GFileQueryInfoFlags flags;
4953 GFileEnumerator *enumerator;
4954 } EnumerateChildrenAsyncData;
4957 enumerate_children_data_free (EnumerateChildrenAsyncData *data)
4959 if (data->enumerator)
4960 g_object_unref (data->enumerator);
4961 g_free (data->attributes);
4966 enumerate_children_async_thread (GSimpleAsyncResult *res,
4968 GCancellable *cancellable)
4970 GError *error = NULL;
4971 EnumerateChildrenAsyncData *data;
4972 GFileEnumerator *enumerator;
4974 data = g_simple_async_result_get_op_res_gpointer (res);
4976 enumerator = g_file_enumerate_children (G_FILE (object), data->attributes, data->flags, cancellable, &error);
4978 if (enumerator == NULL)
4979 g_simple_async_result_take_error (res, error);
4981 data->enumerator = enumerator;
4985 g_file_real_enumerate_children_async (GFile *file,
4986 const char *attributes,
4987 GFileQueryInfoFlags flags,
4989 GCancellable *cancellable,
4990 GAsyncReadyCallback callback,
4993 GSimpleAsyncResult *res;
4994 EnumerateChildrenAsyncData *data;
4996 data = g_new0 (EnumerateChildrenAsyncData, 1);
4997 data->attributes = g_strdup (attributes);
4998 data->flags = flags;
5000 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_enumerate_children_async);
5001 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)enumerate_children_data_free);
5003 g_simple_async_result_run_in_thread (res, enumerate_children_async_thread, io_priority, cancellable);
5004 g_object_unref (res);
5007 static GFileEnumerator *
5008 g_file_real_enumerate_children_finish (GFile *file,
5012 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5013 EnumerateChildrenAsyncData *data;
5015 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_enumerate_children_async);
5017 data = g_simple_async_result_get_op_res_gpointer (simple);
5018 if (data->enumerator)
5019 return g_object_ref (data->enumerator);
5025 open_read_async_thread (GSimpleAsyncResult *res,
5027 GCancellable *cancellable)
5030 GFileInputStream *stream;
5031 GError *error = NULL;
5033 iface = G_FILE_GET_IFACE (object);
5035 if (iface->read_fn == NULL)
5037 g_set_error_literal (&error, G_IO_ERROR,
5038 G_IO_ERROR_NOT_SUPPORTED,
5039 _("Operation not supported"));
5041 g_simple_async_result_take_error (res, error);
5046 stream = iface->read_fn (G_FILE (object), cancellable, &error);
5049 g_simple_async_result_take_error (res, error);
5051 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5055 g_file_real_read_async (GFile *file,
5057 GCancellable *cancellable,
5058 GAsyncReadyCallback callback,
5061 GSimpleAsyncResult *res;
5063 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_read_async);
5065 g_simple_async_result_run_in_thread (res, open_read_async_thread, io_priority, cancellable);
5066 g_object_unref (res);
5069 static GFileInputStream *
5070 g_file_real_read_finish (GFile *file,
5074 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5077 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_read_async);
5079 op = g_simple_async_result_get_op_res_gpointer (simple);
5081 return g_object_ref (op);
5087 append_to_async_thread (GSimpleAsyncResult *res,
5089 GCancellable *cancellable)
5092 GFileCreateFlags *data;
5093 GFileOutputStream *stream;
5094 GError *error = NULL;
5096 iface = G_FILE_GET_IFACE (object);
5098 data = g_simple_async_result_get_op_res_gpointer (res);
5100 stream = iface->append_to (G_FILE (object), *data, cancellable, &error);
5103 g_simple_async_result_take_error (res, error);
5105 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5109 g_file_real_append_to_async (GFile *file,
5110 GFileCreateFlags flags,
5112 GCancellable *cancellable,
5113 GAsyncReadyCallback callback,
5116 GFileCreateFlags *data;
5117 GSimpleAsyncResult *res;
5119 data = g_new0 (GFileCreateFlags, 1);
5122 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_append_to_async);
5123 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
5125 g_simple_async_result_run_in_thread (res, append_to_async_thread, io_priority, cancellable);
5126 g_object_unref (res);
5129 static GFileOutputStream *
5130 g_file_real_append_to_finish (GFile *file,
5134 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5137 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_append_to_async);
5139 op = g_simple_async_result_get_op_res_gpointer (simple);
5141 return g_object_ref (op);
5147 create_async_thread (GSimpleAsyncResult *res,
5149 GCancellable *cancellable)
5152 GFileCreateFlags *data;
5153 GFileOutputStream *stream;
5154 GError *error = NULL;
5156 iface = G_FILE_GET_IFACE (object);
5158 data = g_simple_async_result_get_op_res_gpointer (res);
5160 stream = iface->create (G_FILE (object), *data, cancellable, &error);
5163 g_simple_async_result_take_error (res, error);
5165 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5169 g_file_real_create_async (GFile *file,
5170 GFileCreateFlags flags,
5172 GCancellable *cancellable,
5173 GAsyncReadyCallback callback,
5176 GFileCreateFlags *data;
5177 GSimpleAsyncResult *res;
5179 data = g_new0 (GFileCreateFlags, 1);
5182 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_create_async);
5183 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
5185 g_simple_async_result_run_in_thread (res, create_async_thread, io_priority, cancellable);
5186 g_object_unref (res);
5189 static GFileOutputStream *
5190 g_file_real_create_finish (GFile *file,
5194 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5197 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_async);
5199 op = g_simple_async_result_get_op_res_gpointer (simple);
5201 return g_object_ref (op);
5207 GFileOutputStream *stream;
5209 gboolean make_backup;
5210 GFileCreateFlags flags;
5214 replace_async_data_free (ReplaceAsyncData *data)
5217 g_object_unref (data->stream);
5218 g_free (data->etag);
5223 replace_async_thread (GSimpleAsyncResult *res,
5225 GCancellable *cancellable)
5228 GFileOutputStream *stream;
5229 GError *error = NULL;
5230 ReplaceAsyncData *data;
5232 iface = G_FILE_GET_IFACE (object);
5234 data = g_simple_async_result_get_op_res_gpointer (res);
5236 stream = iface->replace (G_FILE (object),
5244 g_simple_async_result_take_error (res, error);
5246 data->stream = stream;
5250 g_file_real_replace_async (GFile *file,
5252 gboolean make_backup,
5253 GFileCreateFlags flags,
5255 GCancellable *cancellable,
5256 GAsyncReadyCallback callback,
5259 GSimpleAsyncResult *res;
5260 ReplaceAsyncData *data;
5262 data = g_new0 (ReplaceAsyncData, 1);
5263 data->etag = g_strdup (etag);
5264 data->make_backup = make_backup;
5265 data->flags = flags;
5267 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_replace_async);
5268 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_async_data_free);
5270 g_simple_async_result_run_in_thread (res, replace_async_thread, io_priority, cancellable);
5271 g_object_unref (res);
5274 static GFileOutputStream *
5275 g_file_real_replace_finish (GFile *file,
5279 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5280 ReplaceAsyncData *data;
5282 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_async);
5284 data = g_simple_async_result_get_op_res_gpointer (simple);
5286 return g_object_ref (data->stream);
5292 open_readwrite_async_thread (GSimpleAsyncResult *res,
5294 GCancellable *cancellable)
5297 GFileIOStream *stream;
5298 GError *error = NULL;
5300 iface = G_FILE_GET_IFACE (object);
5302 if (iface->open_readwrite == NULL)
5304 g_set_error_literal (&error, G_IO_ERROR,
5305 G_IO_ERROR_NOT_SUPPORTED,
5306 _("Operation not supported"));
5308 g_simple_async_result_take_error (res, error);
5313 stream = iface->open_readwrite (G_FILE (object), cancellable, &error);
5316 g_simple_async_result_take_error (res, error);
5318 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5322 g_file_real_open_readwrite_async (GFile *file,
5324 GCancellable *cancellable,
5325 GAsyncReadyCallback callback,
5328 GSimpleAsyncResult *res;
5330 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_open_readwrite_async);
5332 g_simple_async_result_run_in_thread (res, open_readwrite_async_thread, io_priority, cancellable);
5333 g_object_unref (res);
5336 static GFileIOStream *
5337 g_file_real_open_readwrite_finish (GFile *file,
5341 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5344 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_open_readwrite_async);
5346 op = g_simple_async_result_get_op_res_gpointer (simple);
5348 return g_object_ref (op);
5354 create_readwrite_async_thread (GSimpleAsyncResult *res,
5356 GCancellable *cancellable)
5359 GFileCreateFlags *data;
5360 GFileIOStream *stream;
5361 GError *error = NULL;
5363 iface = G_FILE_GET_IFACE (object);
5365 data = g_simple_async_result_get_op_res_gpointer (res);
5367 if (iface->create_readwrite == NULL)
5369 g_set_error_literal (&error, G_IO_ERROR,
5370 G_IO_ERROR_NOT_SUPPORTED,
5371 _("Operation not supported"));
5373 g_simple_async_result_take_error (res, error);
5378 stream = iface->create_readwrite (G_FILE (object), *data, cancellable, &error);
5381 g_simple_async_result_take_error (res, error);
5383 g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
5387 g_file_real_create_readwrite_async (GFile *file,
5388 GFileCreateFlags flags,
5390 GCancellable *cancellable,
5391 GAsyncReadyCallback callback,
5394 GFileCreateFlags *data;
5395 GSimpleAsyncResult *res;
5397 data = g_new0 (GFileCreateFlags, 1);
5400 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_create_readwrite_async);
5401 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
5403 g_simple_async_result_run_in_thread (res, create_readwrite_async_thread, io_priority, cancellable);
5404 g_object_unref (res);
5407 static GFileIOStream *
5408 g_file_real_create_readwrite_finish (GFile *file,
5412 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5415 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_readwrite_async);
5417 op = g_simple_async_result_get_op_res_gpointer (simple);
5419 return g_object_ref (op);
5425 GFileIOStream *stream;
5427 gboolean make_backup;
5428 GFileCreateFlags flags;
5429 } ReplaceRWAsyncData;
5432 replace_rw_async_data_free (ReplaceRWAsyncData *data)
5435 g_object_unref (data->stream);
5436 g_free (data->etag);
5441 replace_readwrite_async_thread (GSimpleAsyncResult *res,
5443 GCancellable *cancellable)
5446 GFileIOStream *stream;
5447 GError *error = NULL;
5448 ReplaceRWAsyncData *data;
5450 iface = G_FILE_GET_IFACE (object);
5452 data = g_simple_async_result_get_op_res_gpointer (res);
5454 stream = iface->replace_readwrite (G_FILE (object),
5462 g_simple_async_result_take_error (res, error);
5464 data->stream = stream;
5468 g_file_real_replace_readwrite_async (GFile *file,
5470 gboolean make_backup,
5471 GFileCreateFlags flags,
5473 GCancellable *cancellable,
5474 GAsyncReadyCallback callback,
5477 GSimpleAsyncResult *res;
5478 ReplaceRWAsyncData *data;
5480 data = g_new0 (ReplaceRWAsyncData, 1);
5481 data->etag = g_strdup (etag);
5482 data->make_backup = make_backup;
5483 data->flags = flags;
5485 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_replace_readwrite_async);
5486 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_rw_async_data_free);
5488 g_simple_async_result_run_in_thread (res, replace_readwrite_async_thread, io_priority, cancellable);
5489 g_object_unref (res);
5492 static GFileIOStream *
5493 g_file_real_replace_readwrite_finish (GFile *file,
5497 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5498 ReplaceRWAsyncData *data;
5500 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_readwrite_async);
5502 data = g_simple_async_result_get_op_res_gpointer (simple);
5504 return g_object_ref (data->stream);
5512 } SetDisplayNameAsyncData;
5515 set_display_name_data_free (SetDisplayNameAsyncData *data)
5517 g_free (data->name);
5519 g_object_unref (data->file);
5524 set_display_name_async_thread (GSimpleAsyncResult *res,
5526 GCancellable *cancellable)
5528 GError *error = NULL;
5529 SetDisplayNameAsyncData *data;
5532 data = g_simple_async_result_get_op_res_gpointer (res);
5534 file = g_file_set_display_name (G_FILE (object), data->name, cancellable, &error);
5537 g_simple_async_result_take_error (res, error);
5543 g_file_real_set_display_name_async (GFile *file,
5544 const char *display_name,
5546 GCancellable *cancellable,
5547 GAsyncReadyCallback callback,
5550 GSimpleAsyncResult *res;
5551 SetDisplayNameAsyncData *data;
5553 data = g_new0 (SetDisplayNameAsyncData, 1);
5554 data->name = g_strdup (display_name);
5556 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_set_display_name_async);
5557 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)set_display_name_data_free);
5559 g_simple_async_result_run_in_thread (res, set_display_name_async_thread, io_priority, cancellable);
5560 g_object_unref (res);
5564 g_file_real_set_display_name_finish (GFile *file,
5568 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5569 SetDisplayNameAsyncData *data;
5571 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_display_name_async);
5573 data = g_simple_async_result_get_op_res_gpointer (simple);
5575 return g_object_ref (data->file);
5581 GFileQueryInfoFlags flags;
5588 set_info_data_free (SetInfoAsyncData *data)
5591 g_object_unref (data->info);
5593 g_error_free (data->error);
5598 set_info_async_thread (GSimpleAsyncResult *res,
5600 GCancellable *cancellable)
5602 SetInfoAsyncData *data;
5604 data = g_simple_async_result_get_op_res_gpointer (res);
5607 data->res = g_file_set_attributes_from_info (G_FILE (object),
5615 g_file_real_set_attributes_async (GFile *file,
5617 GFileQueryInfoFlags flags,
5619 GCancellable *cancellable,
5620 GAsyncReadyCallback callback,
5623 GSimpleAsyncResult *res;
5624 SetInfoAsyncData *data;
5626 data = g_new0 (SetInfoAsyncData, 1);
5627 data->info = g_file_info_dup (info);
5628 data->flags = flags;
5630 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_set_attributes_async);
5631 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)set_info_data_free);
5633 g_simple_async_result_run_in_thread (res, set_info_async_thread, io_priority, cancellable);
5634 g_object_unref (res);
5638 g_file_real_set_attributes_finish (GFile *file,
5643 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5644 SetInfoAsyncData *data;
5646 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_attributes_async);
5648 data = g_simple_async_result_get_op_res_gpointer (simple);
5651 *info = g_object_ref (data->info);
5653 if (error != NULL && data->error)
5654 *error = g_error_copy (data->error);
5660 find_enclosing_mount_async_thread (GSimpleAsyncResult *res,
5662 GCancellable *cancellable)
5664 GError *error = NULL;
5667 mount = g_file_find_enclosing_mount (G_FILE (object), cancellable, &error);
5670 g_simple_async_result_take_error (res, error);
5672 g_simple_async_result_set_op_res_gpointer (res, mount, (GDestroyNotify)g_object_unref);
5676 g_file_real_find_enclosing_mount_async (GFile *file,
5678 GCancellable *cancellable,
5679 GAsyncReadyCallback callback,
5682 GSimpleAsyncResult *res;
5684 res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_find_enclosing_mount_async);
5686 g_simple_async_result_run_in_thread (res, find_enclosing_mount_async_thread, io_priority, cancellable);
5687 g_object_unref (res);
5691 g_file_real_find_enclosing_mount_finish (GFile *file,
5695 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
5698 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_find_enclosing_mount_async);
5700 mount = g_simple_async_result_get_op_res_gpointer (simple);
5701 return g_object_ref (mount);
5708 GFileCopyFlags flags;
5709 GFileProgressCallback progress_cb;
5710 gpointer progress_cb_data;
5711 GIOSchedulerJob *job;
5715 copy_async_data_free (CopyAsyncData *data)
5717 g_object_unref (data->source);
5718 g_object_unref (data->destination);
5723 CopyAsyncData *data;
5724 goffset current_num_bytes;
5725 goffset total_num_bytes;
5729 copy_async_progress_in_main (gpointer user_data)
5731 ProgressData *progress = user_data;
5732 CopyAsyncData *data = progress->data;
5734 data->progress_cb (progress->current_num_bytes,
5735 progress->total_num_bytes,
5736 data->progress_cb_data);
5742 mainloop_barrier (gpointer user_data)
5744 /* Does nothing, but ensures all queued idles before
5751 copy_async_progress_callback (goffset current_num_bytes,
5752 goffset total_num_bytes,
5755 CopyAsyncData *data = user_data;
5756 ProgressData *progress;
5758 progress = g_new (ProgressData, 1);
5759 progress->data = data;
5760 progress->current_num_bytes = current_num_bytes;
5761 progress->total_num_bytes = total_num_bytes;
5763 g_io_scheduler_job_send_to_mainloop_async (data->job,
5764 copy_async_progress_in_main,
5770 copy_async_thread (GIOSchedulerJob *job,
5771 GCancellable *cancellable,
5774 GSimpleAsyncResult *res;
5775 CopyAsyncData *data;
5780 data = g_simple_async_result_get_op_res_gpointer (res);
5784 result = g_file_copy (data->source,
5788 (data->progress_cb != NULL) ? copy_async_progress_callback : NULL,
5792 /* Ensure all progress callbacks are done running in main thread */
5793 if (data->progress_cb != NULL)
5794 g_io_scheduler_job_send_to_mainloop (job,
5799 g_simple_async_result_take_error (res, error);
5801 g_simple_async_result_complete_in_idle (res);
5807 g_file_real_copy_async (GFile *source,
5809 GFileCopyFlags flags,
5811 GCancellable *cancellable,
5812 GFileProgressCallback progress_callback,
5813 gpointer progress_callback_data,
5814 GAsyncReadyCallback callback,
5817 GSimpleAsyncResult *res;
5818 CopyAsyncData *data;
5820 data = g_new0 (CopyAsyncData, 1);
5821 data->source = g_object_ref (source);
5822 data->destination = g_object_ref (destination);
5823 data->flags = flags;
5824 data->progress_cb = progress_callback;
5825 data->progress_cb_data = progress_callback_data;
5827 res = g_simple_async_result_new (G_OBJECT (source), callback, user_data, g_file_real_copy_async);
5828 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)copy_async_data_free);
5830 g_io_scheduler_push_job (copy_async_thread, res, g_object_unref, io_priority, cancellable);
5834 g_file_real_copy_finish (GFile *file,
5838 /* Error handled in g_file_copy_finish() */
5843 /********************************************
5844 * Default VFS operations *
5845 ********************************************/
5848 * g_file_new_for_path:
5849 * @path: a string containing a relative or absolute path. The string
5850 * must be encoded in the glib filename encoding.
5852 * Constructs a #GFile for a given path. This operation never
5853 * fails, but the returned object might not support any I/O
5854 * operation if @path is malformed.
5856 * Returns: (transfer full): a new #GFile for the given @path.
5859 g_file_new_for_path (const char *path)
5861 g_return_val_if_fail (path != NULL, NULL);
5863 return g_vfs_get_file_for_path (g_vfs_get_default (), path);
5867 * g_file_new_for_uri:
5868 * @uri: a UTF8 string containing a URI.
5870 * Constructs a #GFile for a given URI. This operation never
5871 * fails, but the returned object might not support any I/O
5872 * operation if @uri is malformed or if the uri type is
5875 * Returns: (transfer full): a #GFile for the given @uri.
5878 g_file_new_for_uri (const char *uri)
5880 g_return_val_if_fail (uri != NULL, NULL);
5882 return g_vfs_get_file_for_uri (g_vfs_get_default (), uri);
5886 * g_file_parse_name:
5887 * @parse_name: a file name or path to be parsed.
5889 * Constructs a #GFile with the given @parse_name (i.e. something given by g_file_get_parse_name()).
5890 * This operation never fails, but the returned object might not support any I/O
5891 * operation if the @parse_name cannot be parsed.
5893 * Returns: (transfer full): a new #GFile.
5896 g_file_parse_name (const char *parse_name)
5898 g_return_val_if_fail (parse_name != NULL, NULL);
5900 return g_vfs_parse_name (g_vfs_get_default (), parse_name);
5904 is_valid_scheme_character (char c)
5906 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
5909 /* Following RFC 2396, valid schemes are built like:
5910 * scheme = alpha *( alpha | digit | "+" | "-" | "." )
5913 has_valid_scheme (const char *uri)
5919 if (!g_ascii_isalpha (*p))
5924 } while (is_valid_scheme_character (*p));
5930 * g_file_new_for_commandline_arg:
5931 * @arg: a command line string.
5933 * Creates a #GFile with the given argument from the command line. The value of
5934 * @arg can be either a URI, an absolute path or a relative path resolved
5935 * relative to the current working directory.
5936 * This operation never fails, but the returned object might not support any
5937 * I/O operation if @arg points to a malformed path.
5939 * Returns: (transfer full): a new #GFile.
5942 g_file_new_for_commandline_arg (const char *arg)
5948 g_return_val_if_fail (arg != NULL, NULL);
5950 if (g_path_is_absolute (arg))
5951 return g_file_new_for_path (arg);
5953 if (has_valid_scheme (arg))
5954 return g_file_new_for_uri (arg);
5956 current_dir = g_get_current_dir ();
5957 filename = g_build_filename (current_dir, arg, NULL);
5958 g_free (current_dir);
5960 file = g_file_new_for_path (filename);
5967 * g_file_mount_enclosing_volume:
5968 * @location: input #GFile.
5969 * @flags: flags affecting the operation
5970 * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
5971 * @cancellable: optional #GCancellable object, %NULL to ignore.
5972 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
5973 * @user_data: the data to pass to callback function
5975 * Starts a @mount_operation, mounting the volume that contains the file @location.
5977 * When this operation has completed, @callback will be called with
5978 * @user_user data, and the operation can be finalized with
5979 * g_file_mount_enclosing_volume_finish().
5981 * If @cancellable is not %NULL, then the operation can be cancelled by
5982 * triggering the cancellable object from another thread. If the operation
5983 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5986 g_file_mount_enclosing_volume (GFile *location,
5987 GMountMountFlags flags,
5988 GMountOperation *mount_operation,
5989 GCancellable *cancellable,
5990 GAsyncReadyCallback callback,
5995 g_return_if_fail (G_IS_FILE (location));
5997 iface = G_FILE_GET_IFACE (location);
5999 if (iface->mount_enclosing_volume == NULL)
6001 g_simple_async_report_error_in_idle (G_OBJECT (location),
6002 callback, user_data,
6003 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
6004 _("volume doesn't implement mount"));
6009 (* iface->mount_enclosing_volume) (location, flags, mount_operation, cancellable, callback, user_data);
6014 * g_file_mount_enclosing_volume_finish:
6015 * @location: input #GFile.
6016 * @result: a #GAsyncResult.
6017 * @error: a #GError, or %NULL
6019 * Finishes a mount operation started by g_file_mount_enclosing_volume().
6021 * Returns: %TRUE if successful. If an error
6022 * has occurred, this function will return %FALSE and set @error
6023 * appropriately if present.
6026 g_file_mount_enclosing_volume_finish (GFile *location,
6027 GAsyncResult *result,
6032 g_return_val_if_fail (G_IS_FILE (location), FALSE);
6033 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
6035 if (G_IS_SIMPLE_ASYNC_RESULT (result))
6037 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
6038 if (g_simple_async_result_propagate_error (simple, error))
6042 iface = G_FILE_GET_IFACE (location);
6044 return (* iface->mount_enclosing_volume_finish) (location, result, error);
6047 /********************************************
6048 * Utility functions *
6049 ********************************************/
6052 * g_file_query_default_handler:
6053 * @file: a #GFile to open.
6054 * @cancellable: optional #GCancellable object, %NULL to ignore.
6055 * @error: a #GError, or %NULL
6057 * Returns the #GAppInfo that is registered as the default
6058 * application to handle the file specified by @file.
6060 * If @cancellable is not %NULL, then the operation can be cancelled by
6061 * triggering the cancellable object from another thread. If the operation
6062 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6064 * Returns: (transfer full): a #GAppInfo if the handle was found, %NULL if there were errors.
6065 * When you are done with it, release it with g_object_unref()
6068 g_file_query_default_handler (GFile *file,
6069 GCancellable *cancellable,
6073 const char *content_type;
6078 uri_scheme = g_file_get_uri_scheme (file);
6079 if (uri_scheme && uri_scheme[0] != '\0')
6081 appinfo = g_app_info_get_default_for_uri_scheme (uri_scheme);
6082 g_free (uri_scheme);
6084 if (appinfo != NULL)
6088 info = g_file_query_info (file,
6089 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
6098 content_type = g_file_info_get_content_type (info);
6101 /* Don't use is_native(), as we want to support fuse paths if availible */
6102 path = g_file_get_path (file);
6103 appinfo = g_app_info_get_default_for_type (content_type,
6108 g_object_unref (info);
6110 if (appinfo != NULL)
6113 g_set_error_literal (error, G_IO_ERROR,
6114 G_IO_ERROR_NOT_SUPPORTED,
6115 _("No application is registered as handling this file"));
6121 #define GET_CONTENT_BLOCK_SIZE 8192
6124 * g_file_load_contents:
6125 * @file: input #GFile.
6126 * @cancellable: optional #GCancellable object, %NULL to ignore.
6127 * @contents: (out) (transfer full): a location to place the contents of the file.
6128 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6129 * or %NULL if the length is not needed
6130 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6131 * or %NULL if the entity tag is not needed
6132 * @error: a #GError, or %NULL
6134 * Loads the content of the file into memory. The data is always
6135 * zero-terminated, but this is not included in the resultant @length.
6136 * The returned @content should be freed with g_free() when no longer
6139 * If @cancellable is not %NULL, then the operation can be cancelled by
6140 * triggering the cancellable object from another thread. If the operation
6141 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6143 * Returns: %TRUE if the @file's contents were successfully loaded.
6144 * %FALSE if there were errors.
6147 g_file_load_contents (GFile *file,
6148 GCancellable *cancellable,
6154 GFileInputStream *in;
6155 GByteArray *content;
6160 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6161 g_return_val_if_fail (contents != NULL, FALSE);
6163 in = g_file_read (file, cancellable, error);
6167 content = g_byte_array_new ();
6170 g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
6171 while ((res = g_input_stream_read (G_INPUT_STREAM (in),
6172 content->data + pos,
6173 GET_CONTENT_BLOCK_SIZE,
6174 cancellable, error)) > 0)
6177 g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
6184 info = g_file_input_stream_query_info (in,
6185 G_FILE_ATTRIBUTE_ETAG_VALUE,
6190 *etag_out = g_strdup (g_file_info_get_etag (info));
6191 g_object_unref (info);
6195 /* Ignore errors on close */
6196 g_input_stream_close (G_INPUT_STREAM (in), cancellable, NULL);
6197 g_object_unref (in);
6201 /* error is set already */
6202 g_byte_array_free (content, TRUE);
6209 /* Zero terminate (we got an extra byte allocated for this */
6210 content->data[pos] = 0;
6212 *contents = (char *)g_byte_array_free (content, FALSE);
6220 GCancellable *cancellable;
6221 GFileReadMoreCallback read_more_callback;
6222 GAsyncReadyCallback callback;
6224 GByteArray *content;
6231 load_contents_data_free (LoadContentsData *data)
6234 g_error_free (data->error);
6235 if (data->cancellable)
6236 g_object_unref (data->cancellable);
6238 g_byte_array_free (data->content, TRUE);
6239 g_free (data->etag);
6240 g_object_unref (data->file);
6245 load_contents_close_callback (GObject *obj,
6246 GAsyncResult *close_res,
6249 GInputStream *stream = G_INPUT_STREAM (obj);
6250 LoadContentsData *data = user_data;
6251 GSimpleAsyncResult *res;
6253 /* Ignore errors here, we're only reading anyway */
6254 g_input_stream_close_finish (stream, close_res, NULL);
6255 g_object_unref (stream);
6257 res = g_simple_async_result_new (G_OBJECT (data->file),
6260 g_file_load_contents_async);
6261 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)load_contents_data_free);
6262 g_simple_async_result_complete (res);
6263 g_object_unref (res);
6267 load_contents_fstat_callback (GObject *obj,
6268 GAsyncResult *stat_res,
6271 GInputStream *stream = G_INPUT_STREAM (obj);
6272 LoadContentsData *data = user_data;
6275 info = g_file_input_stream_query_info_finish (G_FILE_INPUT_STREAM (stream),
6279 data->etag = g_strdup (g_file_info_get_etag (info));
6280 g_object_unref (info);
6283 g_input_stream_close_async (stream, 0,
6285 load_contents_close_callback, data);
6289 load_contents_read_callback (GObject *obj,
6290 GAsyncResult *read_res,
6293 GInputStream *stream = G_INPUT_STREAM (obj);
6294 LoadContentsData *data = user_data;
6295 GError *error = NULL;
6298 read_size = g_input_stream_read_finish (stream, read_res, &error);
6302 /* Error or EOF, close the file */
6303 data->error = error;
6304 g_input_stream_close_async (stream, 0,
6306 load_contents_close_callback, data);
6308 else if (read_size == 0)
6310 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
6311 G_FILE_ATTRIBUTE_ETAG_VALUE,
6314 load_contents_fstat_callback,
6317 else if (read_size > 0)
6319 data->pos += read_size;
6321 g_byte_array_set_size (data->content,
6322 data->pos + GET_CONTENT_BLOCK_SIZE);
6325 if (data->read_more_callback &&
6326 !data->read_more_callback ((char *)data->content->data, data->pos, data->user_data))
6327 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
6328 G_FILE_ATTRIBUTE_ETAG_VALUE,
6331 load_contents_fstat_callback,
6334 g_input_stream_read_async (stream,
6335 data->content->data + data->pos,
6336 GET_CONTENT_BLOCK_SIZE,
6339 load_contents_read_callback,
6345 load_contents_open_callback (GObject *obj,
6346 GAsyncResult *open_res,
6349 GFile *file = G_FILE (obj);
6350 GFileInputStream *stream;
6351 LoadContentsData *data = user_data;
6352 GError *error = NULL;
6353 GSimpleAsyncResult *res;
6355 stream = g_file_read_finish (file, open_res, &error);
6359 g_byte_array_set_size (data->content,
6360 data->pos + GET_CONTENT_BLOCK_SIZE);
6361 g_input_stream_read_async (G_INPUT_STREAM (stream),
6362 data->content->data + data->pos,
6363 GET_CONTENT_BLOCK_SIZE,
6366 load_contents_read_callback,
6372 res = g_simple_async_result_new_take_error (G_OBJECT (data->file),
6376 g_simple_async_result_complete (res);
6377 load_contents_data_free (data);
6378 g_object_unref (res);
6383 * g_file_load_partial_contents_async: (skip)
6384 * @file: input #GFile.
6385 * @cancellable: optional #GCancellable object, %NULL to ignore.
6386 * @read_more_callback: a #GFileReadMoreCallback to receive partial data and to specify whether further data should be read.
6387 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6388 * @user_data: the data to pass to the callback functions.
6390 * Reads the partial contents of a file. A #GFileReadMoreCallback should be
6391 * used to stop reading from the file when appropriate, else this function
6392 * will behave exactly as g_file_load_contents_async(). This operation
6393 * can be finished by g_file_load_partial_contents_finish().
6395 * Users of this function should be aware that @user_data is passed to
6396 * both the @read_more_callback and the @callback.
6398 * If @cancellable is not %NULL, then the operation can be cancelled by
6399 * triggering the cancellable object from another thread. If the operation
6400 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6403 g_file_load_partial_contents_async (GFile *file,
6404 GCancellable *cancellable,
6405 GFileReadMoreCallback read_more_callback,
6406 GAsyncReadyCallback callback,
6409 LoadContentsData *data;
6411 g_return_if_fail (G_IS_FILE (file));
6413 data = g_new0 (LoadContentsData, 1);
6416 data->cancellable = g_object_ref (cancellable);
6417 data->read_more_callback = read_more_callback;
6418 data->callback = callback;
6419 data->user_data = user_data;
6420 data->content = g_byte_array_new ();
6421 data->file = g_object_ref (file);
6423 g_file_read_async (file,
6426 load_contents_open_callback,
6431 * g_file_load_partial_contents_finish:
6432 * @file: input #GFile.
6433 * @res: a #GAsyncResult.
6434 * @contents: (out) (transfer full): a location to place the contents of the file.
6435 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6436 * or %NULL if the length is not needed
6437 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6438 * or %NULL if the entity tag is not needed
6439 * @error: a #GError, or %NULL
6441 * Finishes an asynchronous partial load operation that was started
6442 * with g_file_load_partial_contents_async(). The data is always
6443 * zero-terminated, but this is not included in the resultant @length.
6444 * The returned @content should be freed with g_free() when no longer
6447 * Returns: %TRUE if the load was successful. If %FALSE and @error is
6448 * present, it will be set appropriately.
6451 g_file_load_partial_contents_finish (GFile *file,
6458 GSimpleAsyncResult *simple;
6459 LoadContentsData *data;
6461 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6462 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE);
6463 g_return_val_if_fail (contents != NULL, FALSE);
6465 simple = G_SIMPLE_ASYNC_RESULT (res);
6467 if (g_simple_async_result_propagate_error (simple, error))
6470 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_load_contents_async);
6472 data = g_simple_async_result_get_op_res_gpointer (simple);
6476 g_propagate_error (error, data->error);
6485 *length = data->pos;
6489 *etag_out = data->etag;
6493 /* Zero terminate */
6494 g_byte_array_set_size (data->content, data->pos + 1);
6495 data->content->data[data->pos] = 0;
6497 *contents = (char *)g_byte_array_free (data->content, FALSE);
6498 data->content = NULL;
6504 * g_file_load_contents_async:
6505 * @file: input #GFile.
6506 * @cancellable: optional #GCancellable object, %NULL to ignore.
6507 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6508 * @user_data: the data to pass to callback function
6510 * Starts an asynchronous load of the @file's contents.
6512 * For more details, see g_file_load_contents() which is
6513 * the synchronous version of this call.
6515 * When the load operation has completed, @callback will be called
6516 * with @user data. To finish the operation, call
6517 * g_file_load_contents_finish() with the #GAsyncResult returned by
6520 * If @cancellable is not %NULL, then the operation can be cancelled by
6521 * triggering the cancellable object from another thread. If the operation
6522 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6525 g_file_load_contents_async (GFile *file,
6526 GCancellable *cancellable,
6527 GAsyncReadyCallback callback,
6530 g_file_load_partial_contents_async (file,
6533 callback, user_data);
6537 * g_file_load_contents_finish:
6538 * @file: input #GFile.
6539 * @res: a #GAsyncResult.
6540 * @contents: (out) (transfer full): a location to place the contents of the file.
6541 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6542 * or %NULL if the length is not needed
6543 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6544 * or %NULL if the entity tag is not needed
6545 * @error: a #GError, or %NULL
6547 * Finishes an asynchronous load of the @file's contents.
6548 * The contents are placed in @contents, and @length is set to the
6549 * size of the @contents string. The @content should be freed with
6550 * g_free() when no longer needed. If @etag_out is present, it will be
6551 * set to the new entity tag for the @file.
6553 * Returns: %TRUE if the load was successful. If %FALSE and @error is
6554 * present, it will be set appropriately.
6557 g_file_load_contents_finish (GFile *file,
6564 return g_file_load_partial_contents_finish (file,
6573 * g_file_replace_contents:
6574 * @file: input #GFile.
6575 * @contents: a string containing the new contents for @file.
6576 * @length: the length of @contents in bytes.
6577 * @etag: (allow-none): the old <link linkend="gfile-etag">entity tag</link>
6578 * for the document, or %NULL
6579 * @make_backup: %TRUE if a backup should be created.
6580 * @flags: a set of #GFileCreateFlags.
6581 * @new_etag: (allow-none) (out): a location to a new <link linkend="gfile-etag">entity tag</link>
6582 * for the document. This should be freed with g_free() when no longer
6584 * @cancellable: optional #GCancellable object, %NULL to ignore.
6585 * @error: a #GError, or %NULL
6587 * Replaces the contents of @file with @contents of @length bytes.
6589 * If @etag is specified (not %NULL) any existing file must have that etag, or
6590 * the error %G_IO_ERROR_WRONG_ETAG will be returned.
6592 * If @make_backup is %TRUE, this function will attempt to make a backup of @file.
6594 * If @cancellable is not %NULL, then the operation can be cancelled by
6595 * triggering the cancellable object from another thread. If the operation
6596 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6598 * The returned @new_etag can be used to verify that the file hasn't changed the
6599 * next time it is saved over.
6601 * Returns: %TRUE if successful. If an error
6602 * has occurred, this function will return %FALSE and set @error
6603 * appropriately if present.
6606 g_file_replace_contents (GFile *file,
6607 const char *contents,
6610 gboolean make_backup,
6611 GFileCreateFlags flags,
6613 GCancellable *cancellable,
6616 GFileOutputStream *out;
6617 gsize pos, remainder;
6621 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6622 g_return_val_if_fail (contents != NULL, FALSE);
6624 out = g_file_replace (file, etag, make_backup, flags, cancellable, error);
6630 while (remainder > 0 &&
6631 (res = g_output_stream_write (G_OUTPUT_STREAM (out),
6633 MIN (remainder, GET_CONTENT_BLOCK_SIZE),
6641 if (remainder > 0 && res < 0)
6643 /* Ignore errors on close */
6644 g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, NULL);
6645 g_object_unref (out);
6647 /* error is set already */
6651 ret = g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, error);
6654 *new_etag = g_file_output_stream_get_etag (out);
6656 g_object_unref (out);
6664 GCancellable *cancellable;
6665 GAsyncReadyCallback callback;
6667 const char *content;
6671 } ReplaceContentsData;
6674 replace_contents_data_free (ReplaceContentsData *data)
6677 g_error_free (data->error);
6678 if (data->cancellable)
6679 g_object_unref (data->cancellable);
6680 g_object_unref (data->file);
6681 g_free (data->etag);
6686 replace_contents_close_callback (GObject *obj,
6687 GAsyncResult *close_res,
6690 GOutputStream *stream = G_OUTPUT_STREAM (obj);
6691 ReplaceContentsData *data = user_data;
6692 GSimpleAsyncResult *res;
6694 /* Ignore errors here, we're only reading anyway */
6695 g_output_stream_close_finish (stream, close_res, NULL);
6696 g_object_unref (stream);
6698 data->etag = g_file_output_stream_get_etag (G_FILE_OUTPUT_STREAM (stream));
6700 res = g_simple_async_result_new (G_OBJECT (data->file),
6703 g_file_replace_contents_async);
6704 g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_contents_data_free);
6705 g_simple_async_result_complete (res);
6706 g_object_unref (res);
6710 replace_contents_write_callback (GObject *obj,
6711 GAsyncResult *read_res,
6714 GOutputStream *stream = G_OUTPUT_STREAM (obj);
6715 ReplaceContentsData *data = user_data;
6716 GError *error = NULL;
6719 write_size = g_output_stream_write_finish (stream, read_res, &error);
6721 if (write_size <= 0)
6723 /* Error or EOF, close the file */
6725 data->error = error;
6726 g_output_stream_close_async (stream, 0,
6728 replace_contents_close_callback, data);
6730 else if (write_size > 0)
6732 data->pos += write_size;
6734 if (data->pos >= data->length)
6735 g_output_stream_close_async (stream, 0,
6737 replace_contents_close_callback, data);
6739 g_output_stream_write_async (stream,
6740 data->content + data->pos,
6741 data->length - data->pos,
6744 replace_contents_write_callback,
6750 replace_contents_open_callback (GObject *obj,
6751 GAsyncResult *open_res,
6754 GFile *file = G_FILE (obj);
6755 GFileOutputStream *stream;
6756 ReplaceContentsData *data = user_data;
6757 GError *error = NULL;
6758 GSimpleAsyncResult *res;
6760 stream = g_file_replace_finish (file, open_res, &error);
6764 g_output_stream_write_async (G_OUTPUT_STREAM (stream),
6765 data->content + data->pos,
6766 data->length - data->pos,
6769 replace_contents_write_callback,
6775 res = g_simple_async_result_new_take_error (G_OBJECT (data->file),
6779 g_simple_async_result_complete (res);
6780 replace_contents_data_free (data);
6781 g_object_unref (res);
6786 * g_file_replace_contents_async:
6787 * @file: input #GFile.
6788 * @contents: string of contents to replace the file with.
6789 * @length: the length of @contents in bytes.
6790 * @etag: (allow-none): a new <link linkend="gfile-etag">entity tag</link> for the @file, or %NULL
6791 * @make_backup: %TRUE if a backup should be created.
6792 * @flags: a set of #GFileCreateFlags.
6793 * @cancellable: optional #GCancellable object, %NULL to ignore.
6794 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6795 * @user_data: the data to pass to callback function
6797 * Starts an asynchronous replacement of @file with the given
6798 * @contents of @length bytes. @etag will replace the document's
6799 * current entity tag.
6801 * When this operation has completed, @callback will be called with
6802 * @user_user data, and the operation can be finalized with
6803 * g_file_replace_contents_finish().
6805 * If @cancellable is not %NULL, then the operation can be cancelled by
6806 * triggering the cancellable object from another thread. If the operation
6807 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6809 * If @make_backup is %TRUE, this function will attempt to
6810 * make a backup of @file.
6813 g_file_replace_contents_async (GFile *file,
6814 const char *contents,
6817 gboolean make_backup,
6818 GFileCreateFlags flags,
6819 GCancellable *cancellable,
6820 GAsyncReadyCallback callback,
6823 ReplaceContentsData *data;
6825 g_return_if_fail (G_IS_FILE (file));
6826 g_return_if_fail (contents != NULL);
6828 data = g_new0 (ReplaceContentsData, 1);
6831 data->cancellable = g_object_ref (cancellable);
6832 data->callback = callback;
6833 data->user_data = user_data;
6834 data->content = contents;
6835 data->length = length;
6837 data->file = g_object_ref (file);
6839 g_file_replace_async (file,
6845 replace_contents_open_callback,
6850 * g_file_replace_contents_finish:
6851 * @file: input #GFile.
6852 * @res: a #GAsyncResult.
6853 * @new_etag: (out) (allow-none): a location of a new <link linkend="gfile-etag">entity tag</link>
6854 * for the document. This should be freed with g_free() when it is no
6855 * longer needed, or %NULL
6856 * @error: a #GError, or %NULL
6858 * Finishes an asynchronous replace of the given @file. See
6859 * g_file_replace_contents_async(). Sets @new_etag to the new entity
6860 * tag for the document, if present.
6862 * Returns: %TRUE on success, %FALSE on failure.
6865 g_file_replace_contents_finish (GFile *file,
6870 GSimpleAsyncResult *simple;
6871 ReplaceContentsData *data;
6873 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6874 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE);
6876 simple = G_SIMPLE_ASYNC_RESULT (res);
6878 if (g_simple_async_result_propagate_error (simple, error))
6881 g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_replace_contents_async);
6883 data = g_simple_async_result_get_op_res_gpointer (simple);
6887 g_propagate_error (error, data->error);
6895 *new_etag = data->etag;
6896 data->etag = NULL; /* Take ownership */
6903 * g_file_start_mountable:
6904 * @file: input #GFile.
6905 * @flags: flags affecting the operation
6906 * @start_operation: a #GMountOperation, or %NULL to avoid user interaction.
6907 * @cancellable: optional #GCancellable object, %NULL to ignore.
6908 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
6909 * @user_data: the data to pass to callback function
6911 * Starts a file of type G_FILE_TYPE_MOUNTABLE.
6912 * Using @start_operation, you can request callbacks when, for instance,
6913 * passwords are needed during authentication.
6915 * If @cancellable is not %NULL, then the operation can be cancelled by
6916 * triggering the cancellable object from another thread. If the operation
6917 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6919 * When the operation is finished, @callback will be called. You can then call
6920 * g_file_mount_mountable_finish() to get the result of the operation.
6925 g_file_start_mountable (GFile *file,
6926 GDriveStartFlags flags,
6927 GMountOperation *start_operation,
6928 GCancellable *cancellable,
6929 GAsyncReadyCallback callback,
6934 g_return_if_fail (G_IS_FILE (file));
6936 iface = G_FILE_GET_IFACE (file);
6938 if (iface->start_mountable == NULL)
6940 g_simple_async_report_error_in_idle (G_OBJECT (file),
6944 G_IO_ERROR_NOT_SUPPORTED,
6945 _("Operation not supported"));
6949 (* iface->start_mountable) (file,
6958 * g_file_start_mountable_finish:
6959 * @file: input #GFile.
6960 * @result: a #GAsyncResult.
6961 * @error: a #GError, or %NULL
6963 * Finishes a start operation. See g_file_start_mountable() for details.
6965 * Finish an asynchronous start operation that was started
6966 * with g_file_start_mountable().
6968 * Returns: %TRUE if the operation finished successfully. %FALSE
6974 g_file_start_mountable_finish (GFile *file,
6975 GAsyncResult *result,
6980 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6981 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
6983 if (G_IS_SIMPLE_ASYNC_RESULT (result))
6985 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
6986 if (g_simple_async_result_propagate_error (simple, error))
6990 iface = G_FILE_GET_IFACE (file);
6991 return (* iface->start_mountable_finish) (file, result, error);
6995 * g_file_stop_mountable:
6996 * @file: input #GFile.
6997 * @flags: flags affecting the operation
6998 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
6999 * @cancellable: optional #GCancellable object, %NULL to ignore.
7000 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
7001 * @user_data: the data to pass to callback function
7003 * Stops a file of type G_FILE_TYPE_MOUNTABLE.
7005 * If @cancellable is not %NULL, then the operation can be cancelled by
7006 * triggering the cancellable object from another thread. If the operation
7007 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7009 * When the operation is finished, @callback will be called. You can then call
7010 * g_file_stop_mountable_finish() to get the result of the operation.
7015 g_file_stop_mountable (GFile *file,
7016 GMountUnmountFlags flags,
7017 GMountOperation *mount_operation,
7018 GCancellable *cancellable,
7019 GAsyncReadyCallback callback,
7024 g_return_if_fail (G_IS_FILE (file));
7026 iface = G_FILE_GET_IFACE (file);
7028 if (iface->stop_mountable == NULL)
7030 g_simple_async_report_error_in_idle (G_OBJECT (file),
7034 G_IO_ERROR_NOT_SUPPORTED,
7035 _("Operation not supported"));
7039 (* iface->stop_mountable) (file,
7048 * g_file_stop_mountable_finish:
7049 * @file: input #GFile.
7050 * @result: a #GAsyncResult.
7051 * @error: a #GError, or %NULL
7053 * Finishes an stop operation, see g_file_stop_mountable() for details.
7055 * Finish an asynchronous stop operation that was started
7056 * with g_file_stop_mountable().
7058 * Returns: %TRUE if the operation finished successfully. %FALSE
7064 g_file_stop_mountable_finish (GFile *file,
7065 GAsyncResult *result,
7070 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7071 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7073 if (G_IS_SIMPLE_ASYNC_RESULT (result))
7075 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
7076 if (g_simple_async_result_propagate_error (simple, error))
7080 iface = G_FILE_GET_IFACE (file);
7081 return (* iface->stop_mountable_finish) (file, result, error);
7085 * g_file_poll_mountable:
7086 * @file: input #GFile.
7087 * @cancellable: optional #GCancellable object, %NULL to ignore.
7088 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
7089 * @user_data: the data to pass to callback function
7091 * Polls a file of type G_FILE_TYPE_MOUNTABLE.
7093 * If @cancellable is not %NULL, then the operation can be cancelled by
7094 * triggering the cancellable object from another thread. If the operation
7095 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7097 * When the operation is finished, @callback will be called. You can then call
7098 * g_file_mount_mountable_finish() to get the result of the operation.
7103 g_file_poll_mountable (GFile *file,
7104 GCancellable *cancellable,
7105 GAsyncReadyCallback callback,
7110 g_return_if_fail (G_IS_FILE (file));
7112 iface = G_FILE_GET_IFACE (file);
7114 if (iface->poll_mountable == NULL)
7116 g_simple_async_report_error_in_idle (G_OBJECT (file),
7120 G_IO_ERROR_NOT_SUPPORTED,
7121 _("Operation not supported"));
7125 (* iface->poll_mountable) (file,
7132 * g_file_poll_mountable_finish:
7133 * @file: input #GFile.
7134 * @result: a #GAsyncResult.
7135 * @error: a #GError, or %NULL
7137 * Finishes a poll operation. See g_file_poll_mountable() for details.
7139 * Finish an asynchronous poll operation that was polled
7140 * with g_file_poll_mountable().
7142 * Returns: %TRUE if the operation finished successfully. %FALSE
7148 g_file_poll_mountable_finish (GFile *file,
7149 GAsyncResult *result,
7154 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7155 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7157 if (G_IS_SIMPLE_ASYNC_RESULT (result))
7159 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
7160 if (g_simple_async_result_propagate_error (simple, error))
7164 iface = G_FILE_GET_IFACE (file);
7165 return (* iface->poll_mountable_finish) (file, result, error);
7169 * g_file_supports_thread_contexts:
7172 * Checks if @file supports <link
7173 * linkend="g-main-context-push-thread-default-context">thread-default
7174 * contexts</link>. If this returns %FALSE, you cannot perform
7175 * asynchronous operations on @file in a thread that has a
7176 * thread-default context.
7178 * Returns: Whether or not @file supports thread-default contexts.
7183 g_file_supports_thread_contexts (GFile *file)
7187 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7189 iface = G_FILE_GET_IFACE (file);
7190 return iface->supports_thread_contexts;