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>
28 #include <sys/ioctl.h>
30 /* See linux.git/fs/btrfs/ioctl.h */
31 #define BTRFS_IOCTL_MAGIC 0x94
32 #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
43 #include <sys/types.h>
49 #include "glib/gstdio.h"
51 #include "glib-unix.h"
55 #include "gfileattribute-priv.h"
56 #include "gfiledescriptorbased.h"
57 #include "gpollfilemonitor.h"
59 #include "gfileinputstream.h"
60 #include "gfileoutputstream.h"
61 #include "glocalfileoutputstream.h"
62 #include "glocalfileiostream.h"
63 #include "gcancellable.h"
64 #include "gasyncresult.h"
71 * @short_description: File and Directory Handling
73 * @see_also: #GFileInfo, #GFileEnumerator
75 * #GFile is a high level abstraction for manipulating files on a
76 * virtual file system. #GFiles are lightweight, immutable objects
77 * that do no I/O upon creation. It is necessary to understand that
78 * #GFile objects do not represent files, merely an identifier for a
79 * file. All file content I/O is implemented as streaming operations
80 * (see #GInputStream and #GOutputStream).
82 * To construct a #GFile, you can use:
84 * <member>g_file_new_for_path() if you have a path.</member>
85 * <member>g_file_new_for_uri() if you have a URI.</member>
86 * <member>g_file_new_for_commandline_arg() for a command line argument.</member>
87 * <member>g_file_new_tmp() to create a temporary file from a template.</member>
88 * <member>g_file_parse_name() from a UTF-8 string gotten from g_file_get_parse_name().</member>
91 * One way to think of a #GFile is as an abstraction of a pathname. For
92 * normal files the system pathname is what is stored internally, but as
93 * #GFiles are extensible it could also be something else that corresponds
94 * to a pathname in a userspace implementation of a filesystem.
96 * #GFiles make up hierarchies of directories and files that correspond to
97 * the files on a filesystem. You can move through the file system with
98 * #GFile using g_file_get_parent() to get an identifier for the parent
99 * directory, g_file_get_child() to get a child within a directory,
100 * g_file_resolve_relative_path() to resolve a relative path between two
101 * #GFiles. There can be multiple hierarchies, so you may not end up at
102 * the same root if you repeatedly call g_file_get_parent() on two different
105 * All #GFiles have a basename (get with g_file_get_basename()). These names
106 * are byte strings that are used to identify the file on the filesystem
107 * (relative to its parent directory) and there is no guarantees that they
108 * have any particular charset encoding or even make any sense at all. If
109 * you want to use filenames in a user interface you should use the display
110 * name that you can get by requesting the
111 * %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info().
112 * This is guaranteed to be in UTF-8 and can be used in a user interface.
113 * But always store the real basename or the #GFile to use to actually
114 * access the file, because there is no way to go from a display name to
117 * Using #GFile as an identifier has the same weaknesses as using a path
118 * in that there may be multiple aliases for the same file. For instance,
119 * hard or soft links may cause two different #GFiles to refer to the same
120 * file. Other possible causes for aliases are: case insensitive filesystems,
121 * short and long names on FAT/NTFS, or bind mounts in Linux. If you want to
122 * check if two #GFiles point to the same file you can query for the
123 * %G_FILE_ATTRIBUTE_ID_FILE attribute. Note that #GFile does some trivial
124 * canonicalization of pathnames passed in, so that trivial differences in
125 * the path string used at creation (duplicated slashes, slash at end of
126 * path, "." or ".." path segments, etc) does not create different #GFiles.
128 * Many #GFile operations have both synchronous and asynchronous versions
129 * to suit your application. Asynchronous versions of synchronous functions
130 * simply have _async() appended to their function names. The asynchronous
131 * I/O functions call a #GAsyncReadyCallback which is then used to finalize
132 * the operation, producing a GAsyncResult which is then passed to the
133 * function's matching _finish() operation.
135 * Some #GFile operations do not have synchronous analogs, as they may
136 * take a very long time to finish, and blocking may leave an application
137 * unusable. Notable cases include:
139 * <member>g_file_mount_mountable() to mount a mountable file.</member>
140 * <member>g_file_unmount_mountable_with_operation() to unmount a mountable file.</member>
141 * <member>g_file_eject_mountable_with_operation() to eject a mountable file.</member>
144 * <para id="gfile-etag"><indexterm><primary>entity tag</primary></indexterm>
145 * One notable feature of #GFiles are entity tags, or "etags" for
146 * short. Entity tags are somewhat like a more abstract version of the
147 * traditional mtime, and can be used to quickly determine if the file has
148 * been modified from the version on the file system. See the HTTP 1.1
149 * <ulink url="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">specification</ulink>
150 * for HTTP Etag headers, which are a very similar concept.
154 static void g_file_real_query_info_async (GFile *file,
155 const char *attributes,
156 GFileQueryInfoFlags flags,
158 GCancellable *cancellable,
159 GAsyncReadyCallback callback,
161 static GFileInfo * g_file_real_query_info_finish (GFile *file,
164 static void g_file_real_query_filesystem_info_async (GFile *file,
165 const char *attributes,
167 GCancellable *cancellable,
168 GAsyncReadyCallback callback,
170 static GFileInfo * g_file_real_query_filesystem_info_finish (GFile *file,
173 static void g_file_real_enumerate_children_async (GFile *file,
174 const char *attributes,
175 GFileQueryInfoFlags flags,
177 GCancellable *cancellable,
178 GAsyncReadyCallback callback,
180 static GFileEnumerator * g_file_real_enumerate_children_finish (GFile *file,
183 static void g_file_real_read_async (GFile *file,
185 GCancellable *cancellable,
186 GAsyncReadyCallback callback,
188 static GFileInputStream * g_file_real_read_finish (GFile *file,
191 static void g_file_real_append_to_async (GFile *file,
192 GFileCreateFlags flags,
194 GCancellable *cancellable,
195 GAsyncReadyCallback callback,
197 static GFileOutputStream *g_file_real_append_to_finish (GFile *file,
200 static void g_file_real_create_async (GFile *file,
201 GFileCreateFlags flags,
203 GCancellable *cancellable,
204 GAsyncReadyCallback callback,
206 static GFileOutputStream *g_file_real_create_finish (GFile *file,
209 static void g_file_real_replace_async (GFile *file,
211 gboolean make_backup,
212 GFileCreateFlags flags,
214 GCancellable *cancellable,
215 GAsyncReadyCallback callback,
217 static GFileOutputStream *g_file_real_replace_finish (GFile *file,
220 static void g_file_real_delete_async (GFile *file,
222 GCancellable *cancellable,
223 GAsyncReadyCallback callback,
225 static gboolean g_file_real_delete_finish (GFile *file,
228 static void g_file_real_trash_async (GFile *file,
230 GCancellable *cancellable,
231 GAsyncReadyCallback callback,
233 static gboolean g_file_real_trash_finish (GFile *file,
236 static void g_file_real_make_directory_async (GFile *file,
238 GCancellable *cancellable,
239 GAsyncReadyCallback callback,
241 static gboolean g_file_real_make_directory_finish (GFile *file,
244 static void g_file_real_open_readwrite_async (GFile *file,
246 GCancellable *cancellable,
247 GAsyncReadyCallback callback,
249 static GFileIOStream * g_file_real_open_readwrite_finish (GFile *file,
252 static void g_file_real_create_readwrite_async (GFile *file,
253 GFileCreateFlags flags,
255 GCancellable *cancellable,
256 GAsyncReadyCallback callback,
258 static GFileIOStream * g_file_real_create_readwrite_finish (GFile *file,
261 static void g_file_real_replace_readwrite_async (GFile *file,
263 gboolean make_backup,
264 GFileCreateFlags flags,
266 GCancellable *cancellable,
267 GAsyncReadyCallback callback,
269 static GFileIOStream * g_file_real_replace_readwrite_finish (GFile *file,
272 static gboolean g_file_real_set_attributes_from_info (GFile *file,
274 GFileQueryInfoFlags flags,
275 GCancellable *cancellable,
277 static void g_file_real_set_display_name_async (GFile *file,
278 const char *display_name,
280 GCancellable *cancellable,
281 GAsyncReadyCallback callback,
283 static GFile * g_file_real_set_display_name_finish (GFile *file,
286 static void g_file_real_set_attributes_async (GFile *file,
288 GFileQueryInfoFlags flags,
290 GCancellable *cancellable,
291 GAsyncReadyCallback callback,
293 static gboolean g_file_real_set_attributes_finish (GFile *file,
297 static void g_file_real_find_enclosing_mount_async (GFile *file,
299 GCancellable *cancellable,
300 GAsyncReadyCallback callback,
302 static GMount * g_file_real_find_enclosing_mount_finish (GFile *file,
305 static void g_file_real_copy_async (GFile *source,
307 GFileCopyFlags flags,
309 GCancellable *cancellable,
310 GFileProgressCallback progress_callback,
311 gpointer progress_callback_data,
312 GAsyncReadyCallback callback,
314 static gboolean g_file_real_copy_finish (GFile *file,
318 typedef GFileIface GFileInterface;
319 G_DEFINE_INTERFACE (GFile, g_file, G_TYPE_OBJECT)
322 g_file_default_init (GFileIface *iface)
324 iface->enumerate_children_async = g_file_real_enumerate_children_async;
325 iface->enumerate_children_finish = g_file_real_enumerate_children_finish;
326 iface->set_display_name_async = g_file_real_set_display_name_async;
327 iface->set_display_name_finish = g_file_real_set_display_name_finish;
328 iface->query_info_async = g_file_real_query_info_async;
329 iface->query_info_finish = g_file_real_query_info_finish;
330 iface->query_filesystem_info_async = g_file_real_query_filesystem_info_async;
331 iface->query_filesystem_info_finish = g_file_real_query_filesystem_info_finish;
332 iface->set_attributes_async = g_file_real_set_attributes_async;
333 iface->set_attributes_finish = g_file_real_set_attributes_finish;
334 iface->read_async = g_file_real_read_async;
335 iface->read_finish = g_file_real_read_finish;
336 iface->append_to_async = g_file_real_append_to_async;
337 iface->append_to_finish = g_file_real_append_to_finish;
338 iface->create_async = g_file_real_create_async;
339 iface->create_finish = g_file_real_create_finish;
340 iface->replace_async = g_file_real_replace_async;
341 iface->replace_finish = g_file_real_replace_finish;
342 iface->delete_file_async = g_file_real_delete_async;
343 iface->delete_file_finish = g_file_real_delete_finish;
344 iface->trash_async = g_file_real_trash_async;
345 iface->trash_finish = g_file_real_trash_finish;
346 iface->make_directory_async = g_file_real_make_directory_async;
347 iface->make_directory_finish = g_file_real_make_directory_finish;
348 iface->open_readwrite_async = g_file_real_open_readwrite_async;
349 iface->open_readwrite_finish = g_file_real_open_readwrite_finish;
350 iface->create_readwrite_async = g_file_real_create_readwrite_async;
351 iface->create_readwrite_finish = g_file_real_create_readwrite_finish;
352 iface->replace_readwrite_async = g_file_real_replace_readwrite_async;
353 iface->replace_readwrite_finish = g_file_real_replace_readwrite_finish;
354 iface->find_enclosing_mount_async = g_file_real_find_enclosing_mount_async;
355 iface->find_enclosing_mount_finish = g_file_real_find_enclosing_mount_finish;
356 iface->set_attributes_from_info = g_file_real_set_attributes_from_info;
357 iface->copy_async = g_file_real_copy_async;
358 iface->copy_finish = g_file_real_copy_finish;
364 * @file: input #GFile
366 * Checks to see if a file is native to the platform.
368 * A native file s one expressed in the platform-native filename format,
369 * e.g. "C:\Windows" or "/usr/bin/". This does not mean the file is local,
370 * as it might be on a locally mounted remote filesystem.
372 * On some systems non-native files may be available using the native
373 * filesystem via a userspace filesystem (FUSE), in these cases this call
374 * will return %FALSE, but g_file_get_path() will still return a native path.
376 * This call does no blocking I/O.
378 * Returns: %TRUE if @file is native
381 g_file_is_native (GFile *file)
385 g_return_val_if_fail (G_IS_FILE (file), FALSE);
387 iface = G_FILE_GET_IFACE (file);
389 return (* iface->is_native) (file);
394 * g_file_has_uri_scheme:
395 * @file: input #GFile
396 * @uri_scheme: a string containing a URI scheme
398 * Checks to see if a #GFile has a given URI scheme.
400 * This call does no blocking I/O.
402 * Returns: %TRUE if #GFile's backend supports the
403 * given URI scheme, %FALSE if URI scheme is %NULL,
404 * not supported, or #GFile is invalid.
407 g_file_has_uri_scheme (GFile *file,
408 const char *uri_scheme)
412 g_return_val_if_fail (G_IS_FILE (file), FALSE);
413 g_return_val_if_fail (uri_scheme != NULL, FALSE);
415 iface = G_FILE_GET_IFACE (file);
417 return (* iface->has_uri_scheme) (file, uri_scheme);
422 * g_file_get_uri_scheme:
423 * @file: input #GFile
425 * Gets the URI scheme for a #GFile.
426 * RFC 3986 decodes the scheme as:
428 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
430 * Common schemes include "file", "http", "ftp", etc.
432 * This call does no blocking I/O.
434 * Returns: a string containing the URI scheme for the given
435 * #GFile. The returned string should be freed with g_free()
436 * when no longer needed.
439 g_file_get_uri_scheme (GFile *file)
443 g_return_val_if_fail (G_IS_FILE (file), NULL);
445 iface = G_FILE_GET_IFACE (file);
447 return (* iface->get_uri_scheme) (file);
452 * g_file_get_basename:
453 * @file: input #GFile
455 * Gets the base name (the last component of the path) for a given #GFile.
457 * If called for the top level of a system (such as the filesystem root
458 * or a uri like sftp://host/) it will return a single directory separator
459 * (and on Windows, possibly a drive letter).
461 * The base name is a byte string (not UTF-8). It has no defined encoding
462 * or rules other than it may not contain zero bytes. If you want to use
463 * filenames in a user interface you should use the display name that you
464 * can get by requesting the %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
465 * attribute with g_file_query_info().
467 * This call does no blocking I/O.
469 * Returns: string containing the #GFile's base name, or %NULL
470 * if given #GFile is invalid. The returned string should be
471 * freed with g_free() when no longer needed.
474 g_file_get_basename (GFile *file)
478 g_return_val_if_fail (G_IS_FILE (file), NULL);
480 iface = G_FILE_GET_IFACE (file);
482 return (* iface->get_basename) (file);
487 * @file: input #GFile
489 * Gets the local pathname for #GFile, if one exists.
491 * This call does no blocking I/O.
493 * Returns: string containing the #GFile's path, or %NULL if
494 * no such path exists. The returned string should be
495 * freed with g_free() when no longer needed.
498 g_file_get_path (GFile *file)
502 g_return_val_if_fail (G_IS_FILE (file), NULL);
504 iface = G_FILE_GET_IFACE (file);
506 return (* iface->get_path) (file);
511 * @file: input #GFile
513 * Gets the URI for the @file.
515 * This call does no blocking I/O.
517 * Returns: a string containing the #GFile's URI.
518 * The returned string should be freed with g_free()
519 * when no longer needed.
522 g_file_get_uri (GFile *file)
526 g_return_val_if_fail (G_IS_FILE (file), NULL);
528 iface = G_FILE_GET_IFACE (file);
530 return (* iface->get_uri) (file);
534 * g_file_get_parse_name:
535 * @file: input #GFile
537 * Gets the parse name of the @file.
538 * A parse name is a UTF-8 string that describes the
539 * file such that one can get the #GFile back using
540 * g_file_parse_name().
542 * This is generally used to show the #GFile as a nice
543 * full-pathname kind of string in a user interface,
544 * like in a location entry.
546 * For local files with names that can safely be converted
547 * to UTF-8 the pathname is used, otherwise the IRI is used
548 * (a form of URI that allows UTF-8 characters unescaped).
550 * This call does no blocking I/O.
552 * Returns: a string containing the #GFile's parse name.
553 * The returned string should be freed with g_free()
554 * when no longer needed.
557 g_file_get_parse_name (GFile *file)
561 g_return_val_if_fail (G_IS_FILE (file), NULL);
563 iface = G_FILE_GET_IFACE (file);
565 return (* iface->get_parse_name) (file);
570 * @file: input #GFile
572 * Duplicates a #GFile handle. This operation does not duplicate
573 * the actual file or directory represented by the #GFile; see
574 * g_file_copy() if attempting to copy a file.
576 * This call does no blocking I/O.
578 * Returns: (transfer full): a new #GFile that is a duplicate
579 * of the given #GFile.
582 g_file_dup (GFile *file)
586 g_return_val_if_fail (G_IS_FILE (file), NULL);
588 iface = G_FILE_GET_IFACE (file);
590 return (* iface->dup) (file);
595 * @file: (type GFile): #gconstpointer to a #GFile
597 * Creates a hash value for a #GFile.
599 * This call does no blocking I/O.
602 * Returns: 0 if @file is not a valid #GFile, otherwise an
603 * integer that can be used as hash value for the #GFile.
604 * This function is intended for easily hashing a #GFile to
605 * add to a #GHashTable or similar data structure.
608 g_file_hash (gconstpointer file)
612 g_return_val_if_fail (G_IS_FILE (file), 0);
614 iface = G_FILE_GET_IFACE (file);
616 return (* iface->hash) ((GFile *)file);
621 * @file1: the first #GFile
622 * @file2: the second #GFile
624 * Checks equality of two given #GFiles.
626 * Note that two #GFiles that differ can still refer to the same
627 * file on the filesystem due to various forms of filename
630 * This call does no blocking I/O.
632 * Returns: %TRUE if @file1 and @file2 are equal.
633 * %FALSE if either is not a #GFile.
636 g_file_equal (GFile *file1,
641 g_return_val_if_fail (G_IS_FILE (file1), FALSE);
642 g_return_val_if_fail (G_IS_FILE (file2), FALSE);
644 if (G_TYPE_FROM_INSTANCE (file1) != G_TYPE_FROM_INSTANCE (file2))
647 iface = G_FILE_GET_IFACE (file1);
649 return (* iface->equal) (file1, file2);
655 * @file: input #GFile
657 * Gets the parent directory for the @file.
658 * If the @file represents the root directory of the
659 * file system, then %NULL will be returned.
661 * This call does no blocking I/O.
663 * Returns: (transfer full): a #GFile structure to the
664 * parent of the given #GFile or %NULL if there is
665 * no parent. Free the returned object with g_object_unref().
668 g_file_get_parent (GFile *file)
672 g_return_val_if_fail (G_IS_FILE (file), NULL);
674 iface = G_FILE_GET_IFACE (file);
676 return (* iface->get_parent) (file);
681 * @file: input #GFile
682 * @parent: (allow-none): the parent to check for, or %NULL
684 * Checks if @file has a parent, and optionally, if it is @parent.
686 * If @parent is %NULL then this function returns %TRUE if @file has any
687 * parent at all. If @parent is non-%NULL then %TRUE is only returned
688 * if @file is a child of @parent.
690 * Returns: %TRUE if @file is a child of @parent (or any parent in the
691 * case that @parent is %NULL).
696 g_file_has_parent (GFile *file,
699 GFile *actual_parent;
702 g_return_val_if_fail (G_IS_FILE (file), FALSE);
703 g_return_val_if_fail (parent == NULL || G_IS_FILE (parent), FALSE);
705 actual_parent = g_file_get_parent (file);
707 if (actual_parent != NULL)
710 result = g_file_equal (parent, actual_parent);
714 g_object_unref (actual_parent);
724 * @file: input #GFile
725 * @name: string containing the child's basename
727 * Gets a child of @file with basename equal to @name.
729 * Note that the file with that specific name might not exist, but
730 * you can still have a #GFile that points to it. You can use this
731 * for instance to create that file.
733 * This call does no blocking I/O.
735 * Returns: (transfer full): a #GFile to a child specified by @name.
736 * Free the returned object with g_object_unref().
739 g_file_get_child (GFile *file,
742 g_return_val_if_fail (G_IS_FILE (file), NULL);
743 g_return_val_if_fail (name != NULL, NULL);
745 return g_file_resolve_relative_path (file, name);
749 * g_file_get_child_for_display_name:
750 * @file: input #GFile
751 * @display_name: string to a possible child
752 * @error: return location for an error
754 * Gets the child of @file for a given @display_name (i.e. a UTF-8
755 * version of the name). If this function fails, it returns %NULL
756 * and @error will be set. This is very useful when constructing a
757 * #GFile for a new file and the user entered the filename in the
758 * user interface, for instance when you select a directory and
759 * type a filename in the file selector.
761 * This call does no blocking I/O.
763 * Returns: (transfer full): a #GFile to the specified child, or
764 * %NULL if the display name couldn't be converted.
765 * Free the returned object with g_object_unref().
768 g_file_get_child_for_display_name (GFile *file,
769 const char *display_name,
774 g_return_val_if_fail (G_IS_FILE (file), NULL);
775 g_return_val_if_fail (display_name != NULL, NULL);
777 iface = G_FILE_GET_IFACE (file);
779 return (* iface->get_child_for_display_name) (file, display_name, error);
784 * @file: input #GFile
785 * @prefix: input #GFile
787 * Checks whether @file has the prefix specified by @prefix.
789 * In other words, if the names of initial elements of @file's
790 * pathname match @prefix. Only full pathname elements are matched,
791 * so a path like /foo is not considered a prefix of /foobar, only
794 * This call does no I/O, as it works purely on names. As such it can
795 * sometimes return %FALSE even if @file is inside a @prefix (from a
796 * filesystem point of view), because the prefix of @file is an alias
799 * Virtual: prefix_matches
800 * Returns: %TRUE if the @files's parent, grandparent, etc is @prefix,
804 g_file_has_prefix (GFile *file,
809 g_return_val_if_fail (G_IS_FILE (file), FALSE);
810 g_return_val_if_fail (G_IS_FILE (prefix), FALSE);
812 if (G_TYPE_FROM_INSTANCE (file) != G_TYPE_FROM_INSTANCE (prefix))
815 iface = G_FILE_GET_IFACE (file);
817 /* The vtable function differs in arg order since
818 * we're using the old contains_file call
820 return (* iface->prefix_matches) (prefix, file);
824 * g_file_get_relative_path:
825 * @parent: input #GFile
826 * @descendant: input #GFile
828 * Gets the path for @descendant relative to @parent.
830 * This call does no blocking I/O.
832 * Returns: string with the relative path from @descendant
833 * to @parent, or %NULL if @descendant doesn't have @parent
834 * as prefix. The returned string should be freed with g_free()
835 * when no longer needed.
838 g_file_get_relative_path (GFile *parent,
843 g_return_val_if_fail (G_IS_FILE (parent), NULL);
844 g_return_val_if_fail (G_IS_FILE (descendant), NULL);
846 if (G_TYPE_FROM_INSTANCE (parent) != G_TYPE_FROM_INSTANCE (descendant))
849 iface = G_FILE_GET_IFACE (parent);
851 return (* iface->get_relative_path) (parent, descendant);
855 * g_file_resolve_relative_path:
856 * @file: input #GFile
857 * @relative_path: a given relative path string
859 * Resolves a relative path for @file to an absolute path.
861 * This call does no blocking I/O.
863 * Returns: (transfer full): #GFile to the resolved path.
864 * %NULL if @relative_path is %NULL or if @file is invalid.
865 * Free the returned object with g_object_unref().
868 g_file_resolve_relative_path (GFile *file,
869 const char *relative_path)
873 g_return_val_if_fail (G_IS_FILE (file), NULL);
874 g_return_val_if_fail (relative_path != NULL, NULL);
876 iface = G_FILE_GET_IFACE (file);
878 return (* iface->resolve_relative_path) (file, relative_path);
882 * g_file_enumerate_children:
883 * @file: input #GFile
884 * @attributes: an attribute query string
885 * @flags: a set of #GFileQueryInfoFlags
886 * @cancellable: (allow-none): optional #GCancellable object,
888 * @error: #GError for error reporting
890 * Gets the requested information about the files in a directory.
891 * The result is a #GFileEnumerator object that will give out
892 * #GFileInfo objects for all the files in the directory.
894 * The @attributes value is a string that specifies the file
895 * attributes that should be gathered. It is not an error if
896 * it's not possible to read a particular requested attribute
897 * from a file - it just won't be set. @attributes should
898 * be a comma-separated list of attributes or attribute wildcards.
899 * The wildcard "*" means all attributes, and a wildcard like
900 * "standard::*" means all attributes in the standard namespace.
901 * An example attribute query be "standard::*,owner::user".
902 * The standard attributes are available as defines, like
903 * #G_FILE_ATTRIBUTE_STANDARD_NAME.
905 * If @cancellable is not %NULL, then the operation can be cancelled
906 * by triggering the cancellable object from another thread. If the
907 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
910 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will
911 * be returned. If the file is not a directory, the %G_IO_ERROR_NOT_DIRECTORY
912 * error will be returned. Other errors are possible too.
914 * Returns: (transfer full): A #GFileEnumerator if successful,
915 * %NULL on error. Free the returned object with g_object_unref().
918 g_file_enumerate_children (GFile *file,
919 const char *attributes,
920 GFileQueryInfoFlags flags,
921 GCancellable *cancellable,
926 g_return_val_if_fail (G_IS_FILE (file), NULL);
928 if (g_cancellable_set_error_if_cancelled (cancellable, error))
931 iface = G_FILE_GET_IFACE (file);
933 if (iface->enumerate_children == NULL)
935 g_set_error_literal (error, G_IO_ERROR,
936 G_IO_ERROR_NOT_SUPPORTED,
937 _("Operation not supported"));
941 return (* iface->enumerate_children) (file, attributes, flags,
946 * g_file_enumerate_children_async:
947 * @file: input #GFile
948 * @attributes: an attribute query string
949 * @flags: a set of #GFileQueryInfoFlags
950 * @io_priority: the <link linkend="io-priority">I/O priority</link>
952 * @cancellable: (allow-none): optional #GCancellable object,
954 * @callback: (scope async): a #GAsyncReadyCallback to call when the
955 * request is satisfied
956 * @user_data: (closure): the data to pass to callback function
958 * Asynchronously gets the requested information about the files
959 * in a directory. The result is a #GFileEnumerator object that will
960 * give out #GFileInfo objects for all the files in the directory.
962 * For more details, see g_file_enumerate_children() which is
963 * the synchronous version of this call.
965 * When the operation is finished, @callback will be called. You can
966 * then call g_file_enumerate_children_finish() to get the result of
970 g_file_enumerate_children_async (GFile *file,
971 const char *attributes,
972 GFileQueryInfoFlags flags,
974 GCancellable *cancellable,
975 GAsyncReadyCallback callback,
980 g_return_if_fail (G_IS_FILE (file));
982 iface = G_FILE_GET_IFACE (file);
983 (* iface->enumerate_children_async) (file,
993 * g_file_enumerate_children_finish:
994 * @file: input #GFile
995 * @res: a #GAsyncResult
998 * Finishes an async enumerate children operation.
999 * See g_file_enumerate_children_async().
1001 * Returns: (transfer full): a #GFileEnumerator or %NULL
1002 * if an error occurred.
1003 * Free the returned object with g_object_unref().
1006 g_file_enumerate_children_finish (GFile *file,
1012 g_return_val_if_fail (G_IS_FILE (file), NULL);
1013 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1015 if (g_async_result_legacy_propagate_error (res, error))
1018 iface = G_FILE_GET_IFACE (file);
1019 return (* iface->enumerate_children_finish) (file, res, error);
1023 * g_file_query_exists:
1024 * @file: input #GFile
1025 * @cancellable: (allow-none): optional #GCancellable object,
1028 * Utility function to check if a particular file exists. This is
1029 * implemented using g_file_query_info() and as such does blocking I/O.
1031 * Note that in many cases it is racy to first check for file existence
1032 * and then execute something based on the outcome of that, because the
1033 * file might have been created or removed in between the operations. The
1034 * general approach to handling that is to not check, but just do the
1035 * operation and handle the errors as they come.
1037 * As an example of race-free checking, take the case of reading a file,
1038 * and if it doesn't exist, creating it. There are two racy versions: read
1039 * it, and on error create it; and: check if it exists, if not create it.
1040 * These can both result in two processes creating the file (with perhaps
1041 * a partially written file as the result). The correct approach is to
1042 * always try to create the file with g_file_create() which will either
1043 * atomically create the file or fail with a %G_IO_ERROR_EXISTS error.
1045 * However, in many cases an existence check is useful in a user interface,
1046 * for instance to make a menu item sensitive/insensitive, so that you don't
1047 * have to fool users that something is possible and then just show an error
1048 * dialog. If you do this, you should make sure to also handle the errors
1049 * that can happen due to races when you execute the operation.
1051 * Returns: %TRUE if the file exists (and can be detected without error),
1052 * %FALSE otherwise (or if cancelled).
1055 g_file_query_exists (GFile *file,
1056 GCancellable *cancellable)
1060 g_return_val_if_fail (G_IS_FILE(file), FALSE);
1062 info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE,
1063 G_FILE_QUERY_INFO_NONE, cancellable, NULL);
1066 g_object_unref (info);
1074 * g_file_query_file_type:
1075 * @file: input #GFile
1076 * @flags: a set of #GFileQueryInfoFlags passed to g_file_query_info()
1077 * @cancellable: (allow-none): optional #GCancellable object,
1080 * Utility function to inspect the #GFileType of a file. This is
1081 * implemented using g_file_query_info() and as such does blocking I/O.
1083 * The primary use case of this method is to check if a file is
1084 * a regular file, directory, or symlink.
1086 * Returns: The #GFileType of the file and #G_FILE_TYPE_UNKNOWN
1087 * if the file does not exist
1092 g_file_query_file_type (GFile *file,
1093 GFileQueryInfoFlags flags,
1094 GCancellable *cancellable)
1097 GFileType file_type;
1099 g_return_val_if_fail (G_IS_FILE(file), G_FILE_TYPE_UNKNOWN);
1100 info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, flags,
1104 file_type = g_file_info_get_file_type (info);
1105 g_object_unref (info);
1108 file_type = G_FILE_TYPE_UNKNOWN;
1114 * g_file_query_info:
1115 * @file: input #GFile
1116 * @attributes: an attribute query string
1117 * @flags: a set of #GFileQueryInfoFlags
1118 * @cancellable: (allow-none): optional #GCancellable object,
1122 * Gets the requested information about specified @file.
1123 * The result is a #GFileInfo object that contains key-value
1124 * attributes (such as the type or size of the file).
1126 * The @attributes value is a string that specifies the file
1127 * attributes that should be gathered. It is not an error if
1128 * it's not possible to read a particular requested attribute
1129 * from a file - it just won't be set. @attributes should be a
1130 * comma-separated list of attributes or attribute wildcards.
1131 * The wildcard "*" means all attributes, and a wildcard like
1132 * "standard::*" means all attributes in the standard namespace.
1133 * An example attribute query be "standard::*,owner::user".
1134 * The standard attributes are available as defines, like
1135 * #G_FILE_ATTRIBUTE_STANDARD_NAME.
1137 * If @cancellable is not %NULL, then the operation can be cancelled
1138 * by triggering the cancellable object from another thread. If the
1139 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1142 * For symlinks, normally the information about the target of the
1143 * symlink is returned, rather than information about the symlink
1144 * itself. However if you pass #G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
1145 * in @flags the information about the symlink itself will be returned.
1146 * Also, for symlinks that point to non-existing files the information
1147 * about the symlink itself will be returned.
1149 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will be
1150 * returned. Other errors are possible too, and depend on what kind of
1151 * filesystem the file is on.
1153 * Returns: (transfer full): a #GFileInfo for the given @file, or %NULL
1154 * on error. Free the returned object with g_object_unref().
1157 g_file_query_info (GFile *file,
1158 const char *attributes,
1159 GFileQueryInfoFlags flags,
1160 GCancellable *cancellable,
1165 g_return_val_if_fail (G_IS_FILE (file), NULL);
1167 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1170 iface = G_FILE_GET_IFACE (file);
1172 if (iface->query_info == NULL)
1174 g_set_error_literal (error, G_IO_ERROR,
1175 G_IO_ERROR_NOT_SUPPORTED,
1176 _("Operation not supported"));
1180 return (* iface->query_info) (file, attributes, flags, cancellable, error);
1184 * g_file_query_info_async:
1185 * @file: input #GFile
1186 * @attributes: an attribute query string
1187 * @flags: a set of #GFileQueryInfoFlags
1188 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1190 * @cancellable: (allow-none): optional #GCancellable object,
1192 * @callback: (scope async): a #GAsyncReadyCallback to call when the
1193 * request is satisfied
1194 * @user_data: (closure): the data to pass to callback function
1196 * Asynchronously gets the requested information about specified @file.
1197 * The result is a #GFileInfo object that contains key-value attributes
1198 * (such as type or size for the file).
1200 * For more details, see g_file_query_info() which is the synchronous
1201 * version of this call.
1203 * When the operation is finished, @callback will be called. You can
1204 * then call g_file_query_info_finish() to get the result of the operation.
1207 g_file_query_info_async (GFile *file,
1208 const char *attributes,
1209 GFileQueryInfoFlags flags,
1211 GCancellable *cancellable,
1212 GAsyncReadyCallback callback,
1217 g_return_if_fail (G_IS_FILE (file));
1219 iface = G_FILE_GET_IFACE (file);
1220 (* iface->query_info_async) (file,
1230 * g_file_query_info_finish:
1231 * @file: input #GFile
1232 * @res: a #GAsyncResult
1235 * Finishes an asynchronous file info query.
1236 * See g_file_query_info_async().
1238 * Returns: (transfer full): #GFileInfo for given @file
1239 * or %NULL on error. Free the returned object with
1243 g_file_query_info_finish (GFile *file,
1249 g_return_val_if_fail (G_IS_FILE (file), NULL);
1250 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1252 if (g_async_result_legacy_propagate_error (res, error))
1255 iface = G_FILE_GET_IFACE (file);
1256 return (* iface->query_info_finish) (file, res, error);
1260 * g_file_query_filesystem_info:
1261 * @file: input #GFile
1262 * @attributes: an attribute query string
1263 * @cancellable: (allow-none): optional #GCancellable object,
1267 * Similar to g_file_query_info(), but obtains information
1268 * about the filesystem the @file is on, rather than the file itself.
1269 * For instance the amount of space available and the type of
1272 * The @attributes value is a string that specifies the attributes
1273 * that should be gathered. It is not an error if it's not possible
1274 * to read a particular requested attribute from a file - it just
1275 * won't be set. @attributes should be a comma-separated list of
1276 * attributes or attribute wildcards. The wildcard "*" means all
1277 * attributes, and a wildcard like "filesystem::*" means all attributes
1278 * in the filesystem namespace. The standard namespace for filesystem
1279 * attributes is "filesystem". Common attributes of interest are
1280 * #G_FILE_ATTRIBUTE_FILESYSTEM_SIZE (the total size of the filesystem
1281 * in bytes), #G_FILE_ATTRIBUTE_FILESYSTEM_FREE (number of bytes available),
1282 * and #G_FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).
1284 * If @cancellable is not %NULL, then the operation can be cancelled
1285 * by triggering the cancellable object from another thread. If the
1286 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1289 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will
1290 * be returned. Other errors are possible too, and depend on what
1291 * kind of filesystem the file is on.
1293 * Returns: (transfer full): a #GFileInfo or %NULL if there was an error.
1294 * Free the returned object with g_object_unref().
1297 g_file_query_filesystem_info (GFile *file,
1298 const char *attributes,
1299 GCancellable *cancellable,
1304 g_return_val_if_fail (G_IS_FILE (file), NULL);
1306 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1309 iface = G_FILE_GET_IFACE (file);
1311 if (iface->query_filesystem_info == NULL)
1313 g_set_error_literal (error, G_IO_ERROR,
1314 G_IO_ERROR_NOT_SUPPORTED,
1315 _("Operation not supported"));
1319 return (* iface->query_filesystem_info) (file, attributes, cancellable, error);
1323 * g_file_query_filesystem_info_async:
1324 * @file: input #GFile
1325 * @attributes: an attribute query string
1326 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1328 * @cancellable: (allow-none): optional #GCancellable object,
1330 * @callback: (scope async): a #GAsyncReadyCallback to call
1331 * when the request is satisfied
1332 * @user_data: (closure): the data to pass to callback function
1334 * Asynchronously gets the requested information about the filesystem
1335 * that the specified @file is on. The result is a #GFileInfo object
1336 * that contains key-value attributes (such as type or size for the
1339 * For more details, see g_file_query_filesystem_info() which is the
1340 * synchronous version of this call.
1342 * When the operation is finished, @callback will be called. You can
1343 * then call g_file_query_info_finish() to get the result of the
1347 g_file_query_filesystem_info_async (GFile *file,
1348 const char *attributes,
1350 GCancellable *cancellable,
1351 GAsyncReadyCallback callback,
1356 g_return_if_fail (G_IS_FILE (file));
1358 iface = G_FILE_GET_IFACE (file);
1359 (* iface->query_filesystem_info_async) (file,
1368 * g_file_query_filesystem_info_finish:
1369 * @file: input #GFile
1370 * @res: a #GAsyncResult
1373 * Finishes an asynchronous filesystem info query.
1374 * See g_file_query_filesystem_info_async().
1376 * Returns: (transfer full): #GFileInfo for given @file
1377 * or %NULL on error.
1378 * Free the returned object with g_object_unref().
1381 g_file_query_filesystem_info_finish (GFile *file,
1387 g_return_val_if_fail (G_IS_FILE (file), NULL);
1388 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1390 if (g_async_result_legacy_propagate_error (res, error))
1393 iface = G_FILE_GET_IFACE (file);
1394 return (* iface->query_filesystem_info_finish) (file, res, error);
1398 * g_file_find_enclosing_mount:
1399 * @file: input #GFile
1400 * @cancellable: (allow-none): optional #GCancellable object,
1404 * Gets a #GMount for the #GFile.
1406 * If the #GFileIface for @file does not have a mount (e.g.
1407 * possibly a remote share), @error will be set to %G_IO_ERROR_NOT_FOUND
1408 * and %NULL will be returned.
1410 * If @cancellable is not %NULL, then the operation can be cancelled by
1411 * triggering the cancellable object from another thread. If the operation
1412 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1414 * Returns: (transfer full): a #GMount where the @file is located
1415 * or %NULL on error.
1416 * Free the returned object with g_object_unref().
1419 g_file_find_enclosing_mount (GFile *file,
1420 GCancellable *cancellable,
1425 g_return_val_if_fail (G_IS_FILE (file), NULL);
1427 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1430 iface = G_FILE_GET_IFACE (file);
1431 if (iface->find_enclosing_mount == NULL)
1434 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
1435 /* Translators: This is an error message when
1436 * trying to find the enclosing (user visible)
1437 * mount of a file, but none exists.
1439 _("Containing mount does not exist"));
1443 return (* iface->find_enclosing_mount) (file, cancellable, error);
1447 * g_file_find_enclosing_mount_async:
1449 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1451 * @cancellable: (allow-none): optional #GCancellable object,
1453 * @callback: (scope async): a #GAsyncReadyCallback to call
1454 * when the request is satisfied
1455 * @user_data: (closure): the data to pass to callback function
1457 * Asynchronously gets the mount for the file.
1459 * For more details, see g_file_find_enclosing_mount() which is
1460 * the synchronous version of this call.
1462 * When the operation is finished, @callback will be called.
1463 * You can then call g_file_find_enclosing_mount_finish() to
1464 * get the result of the operation.
1467 g_file_find_enclosing_mount_async (GFile *file,
1469 GCancellable *cancellable,
1470 GAsyncReadyCallback callback,
1475 g_return_if_fail (G_IS_FILE (file));
1477 iface = G_FILE_GET_IFACE (file);
1478 (* iface->find_enclosing_mount_async) (file,
1486 * g_file_find_enclosing_mount_finish:
1488 * @res: a #GAsyncResult
1491 * Finishes an asynchronous find mount request.
1492 * See g_file_find_enclosing_mount_async().
1494 * Returns: (transfer full): #GMount for given @file or %NULL on error.
1495 * Free the returned object with g_object_unref().
1498 g_file_find_enclosing_mount_finish (GFile *file,
1504 g_return_val_if_fail (G_IS_FILE (file), NULL);
1505 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1507 if (g_async_result_legacy_propagate_error (res, error))
1510 iface = G_FILE_GET_IFACE (file);
1511 return (* iface->find_enclosing_mount_finish) (file, res, error);
1517 * @file: #GFile to read
1518 * @cancellable: (allow-none): a #GCancellable
1519 * @error: a #GError, or %NULL
1521 * Opens a file for reading. The result is a #GFileInputStream that
1522 * can be used to read the contents of the file.
1524 * If @cancellable is not %NULL, then the operation can be cancelled by
1525 * triggering the cancellable object from another thread. If the operation
1526 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1528 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will be
1529 * returned. If the file is a directory, the %G_IO_ERROR_IS_DIRECTORY
1530 * error will be returned. Other errors are possible too, and depend
1531 * on what kind of filesystem the file is on.
1534 * Returns: (transfer full): #GFileInputStream or %NULL on error.
1535 * Free the returned object with g_object_unref().
1538 g_file_read (GFile *file,
1539 GCancellable *cancellable,
1544 g_return_val_if_fail (G_IS_FILE (file), NULL);
1546 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1549 iface = G_FILE_GET_IFACE (file);
1551 if (iface->read_fn == NULL)
1553 g_set_error_literal (error, G_IO_ERROR,
1554 G_IO_ERROR_NOT_SUPPORTED,
1555 _("Operation not supported"));
1559 return (* iface->read_fn) (file, cancellable, error);
1564 * @file: input #GFile
1565 * @flags: a set of #GFileCreateFlags
1566 * @cancellable: (allow-none): optional #GCancellable object,
1568 * @error: a #GError, or %NULL
1570 * Gets an output stream for appending data to the file.
1571 * If the file doesn't already exist it is created.
1573 * By default files created are generally readable by everyone,
1574 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1575 * will be made readable only to the current user, to the level that
1576 * is supported on the target filesystem.
1578 * If @cancellable is not %NULL, then the operation can be cancelled
1579 * by triggering the cancellable object from another thread. If the
1580 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1583 * Some file systems don't allow all file names, and may return an
1584 * %G_IO_ERROR_INVALID_FILENAME error. If the file is a directory the
1585 * %G_IO_ERROR_IS_DIRECTORY error will be returned. Other errors are
1586 * possible too, and depend on what kind of filesystem the file is on.
1588 * Returns: (transfer full): a #GFileOutputStream, or %NULL on error.
1589 * Free the returned object with g_object_unref().
1592 g_file_append_to (GFile *file,
1593 GFileCreateFlags flags,
1594 GCancellable *cancellable,
1599 g_return_val_if_fail (G_IS_FILE (file), NULL);
1601 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1604 iface = G_FILE_GET_IFACE (file);
1606 if (iface->append_to == NULL)
1608 g_set_error_literal (error, G_IO_ERROR,
1609 G_IO_ERROR_NOT_SUPPORTED,
1610 _("Operation not supported"));
1614 return (* iface->append_to) (file, flags, cancellable, error);
1619 * @file: input #GFile
1620 * @flags: a set of #GFileCreateFlags
1621 * @cancellable: (allow-none): optional #GCancellable object,
1623 * @error: a #GError, or %NULL
1625 * Creates a new file and returns an output stream for writing to it.
1626 * The file must not already exist.
1628 * By default files created are generally readable by everyone,
1629 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1630 * will be made readable only to the current user, to the level
1631 * that is supported on the target filesystem.
1633 * If @cancellable is not %NULL, then the operation can be cancelled
1634 * by triggering the cancellable object from another thread. If the
1635 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1638 * If a file or directory with this name already exists the
1639 * %G_IO_ERROR_EXISTS error will be returned. Some file systems don't
1640 * allow all file names, and may return an %G_IO_ERROR_INVALID_FILENAME
1641 * error, and if the name is to long %G_IO_ERROR_FILENAME_TOO_LONG will
1642 * be returned. Other errors are possible too, and depend on what kind
1643 * of filesystem the file is on.
1645 * Returns: (transfer full): a #GFileOutputStream for the newly created
1646 * file, or %NULL on error.
1647 * Free the returned object with g_object_unref().
1650 g_file_create (GFile *file,
1651 GFileCreateFlags flags,
1652 GCancellable *cancellable,
1657 g_return_val_if_fail (G_IS_FILE (file), NULL);
1659 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1662 iface = G_FILE_GET_IFACE (file);
1664 if (iface->create == NULL)
1666 g_set_error_literal (error, G_IO_ERROR,
1667 G_IO_ERROR_NOT_SUPPORTED,
1668 _("Operation not supported"));
1672 return (* iface->create) (file, flags, cancellable, error);
1677 * @file: input #GFile
1678 * @etag: (allow-none): an optional <link linkend="gfile-etag">entity tag</link>
1679 * for the current #GFile, or #NULL to ignore
1680 * @make_backup: %TRUE if a backup should be created
1681 * @flags: a set of #GFileCreateFlags
1682 * @cancellable: (allow-none): optional #GCancellable object,
1684 * @error: a #GError, or %NULL
1686 * Returns an output stream for overwriting the file, possibly
1687 * creating a backup copy of the file first. If the file doesn't exist,
1688 * it will be created.
1690 * This will try to replace the file in the safest way possible so
1691 * that any errors during the writing will not affect an already
1692 * existing copy of the file. For instance, for local files it
1693 * may write to a temporary file and then atomically rename over
1694 * the destination when the stream is closed.
1696 * By default files created are generally readable by everyone,
1697 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1698 * will be made readable only to the current user, to the level that
1699 * is supported on the target filesystem.
1701 * If @cancellable is not %NULL, then the operation can be cancelled
1702 * by triggering the cancellable object from another thread. If the
1703 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1706 * If you pass in a non-%NULL @etag value, then this value is
1707 * compared to the current entity tag of the file, and if they differ
1708 * an %G_IO_ERROR_WRONG_ETAG error is returned. This generally means
1709 * that the file has been changed since you last read it. You can get
1710 * the new etag from g_file_output_stream_get_etag() after you've
1711 * finished writing and closed the #GFileOutputStream. When you load
1712 * a new file you can use g_file_input_stream_query_info() to get
1713 * the etag of the file.
1715 * If @make_backup is %TRUE, this function will attempt to make a
1716 * backup of the current file before overwriting it. If this fails
1717 * a %G_IO_ERROR_CANT_CREATE_BACKUP error will be returned. If you
1718 * want to replace anyway, try again with @make_backup set to %FALSE.
1720 * If the file is a directory the %G_IO_ERROR_IS_DIRECTORY error will
1721 * be returned, and if the file is some other form of non-regular file
1722 * then a %G_IO_ERROR_NOT_REGULAR_FILE error will be returned. Some
1723 * file systems don't allow all file names, and may return an
1724 * %G_IO_ERROR_INVALID_FILENAME error, and if the name is to long
1725 * %G_IO_ERROR_FILENAME_TOO_LONG will be returned. Other errors are
1726 * possible too, and depend on what kind of filesystem the file is on.
1728 * Returns: (transfer full): a #GFileOutputStream or %NULL on error.
1729 * Free the returned object with g_object_unref().
1732 g_file_replace (GFile *file,
1734 gboolean make_backup,
1735 GFileCreateFlags flags,
1736 GCancellable *cancellable,
1741 g_return_val_if_fail (G_IS_FILE (file), NULL);
1743 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1746 iface = G_FILE_GET_IFACE (file);
1748 if (iface->replace == NULL)
1750 g_set_error_literal (error, G_IO_ERROR,
1751 G_IO_ERROR_NOT_SUPPORTED,
1752 _("Operation not supported"));
1756 /* Handle empty tag string as NULL in consistent way. */
1757 if (etag && *etag == 0)
1760 return (* iface->replace) (file, etag, make_backup, flags, cancellable, error);
1764 * g_file_open_readwrite:
1765 * @file: #GFile to open
1766 * @cancellable: (allow-none): a #GCancellable
1767 * @error: a #GError, or %NULL
1769 * Opens an existing file for reading and writing. The result is
1770 * a #GFileIOStream that can be used to read and write the contents
1773 * If @cancellable is not %NULL, then the operation can be cancelled
1774 * by triggering the cancellable object from another thread. If the
1775 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1778 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will
1779 * be returned. If the file is a directory, the %G_IO_ERROR_IS_DIRECTORY
1780 * error will be returned. Other errors are possible too, and depend on
1781 * what kind of filesystem the file is on. Note that in many non-local
1782 * file cases read and write streams are not supported, so make sure you
1783 * really need to do read and write streaming, rather than just opening
1784 * for reading or writing.
1786 * Returns: (transfer full): #GFileIOStream or %NULL on error.
1787 * Free the returned object with g_object_unref().
1792 g_file_open_readwrite (GFile *file,
1793 GCancellable *cancellable,
1798 g_return_val_if_fail (G_IS_FILE (file), NULL);
1800 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1803 iface = G_FILE_GET_IFACE (file);
1805 if (iface->open_readwrite == NULL)
1807 g_set_error_literal (error, G_IO_ERROR,
1808 G_IO_ERROR_NOT_SUPPORTED,
1809 _("Operation not supported"));
1813 return (* iface->open_readwrite) (file, cancellable, error);
1817 * g_file_create_readwrite:
1819 * @flags: a set of #GFileCreateFlags
1820 * @cancellable: (allow-none): optional #GCancellable object,
1822 * @error: return location for a #GError, or %NULL
1824 * Creates a new file and returns a stream for reading and
1825 * writing to it. The file must not already exist.
1827 * By default files created are generally readable by everyone,
1828 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1829 * will be made readable only to the current user, to the level
1830 * that is supported on the target filesystem.
1832 * If @cancellable is not %NULL, then the operation can be cancelled
1833 * by triggering the cancellable object from another thread. If the
1834 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1837 * If a file or directory with this name already exists, the
1838 * %G_IO_ERROR_EXISTS error will be returned. Some file systems don't
1839 * allow all file names, and may return an %G_IO_ERROR_INVALID_FILENAME
1840 * error, and if the name is too long, %G_IO_ERROR_FILENAME_TOO_LONG
1841 * will be returned. Other errors are possible too, and depend on what
1842 * kind of filesystem the file is on.
1844 * Note that in many non-local file cases read and write streams are
1845 * not supported, so make sure you really need to do read and write
1846 * streaming, rather than just opening for reading or writing.
1848 * Returns: (transfer full): a #GFileIOStream for the newly created
1849 * file, or %NULL on error.
1850 * Free the returned object with g_object_unref().
1855 g_file_create_readwrite (GFile *file,
1856 GFileCreateFlags flags,
1857 GCancellable *cancellable,
1862 g_return_val_if_fail (G_IS_FILE (file), NULL);
1864 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1867 iface = G_FILE_GET_IFACE (file);
1869 if (iface->create_readwrite == NULL)
1871 g_set_error_literal (error, G_IO_ERROR,
1872 G_IO_ERROR_NOT_SUPPORTED,
1873 _("Operation not supported"));
1877 return (* iface->create_readwrite) (file, flags, cancellable, error);
1881 * g_file_replace_readwrite:
1883 * @etag: (allow-none): an optional <link linkend="gfile-etag">entity tag</link>
1884 * for the current #GFile, or #NULL to ignore
1885 * @make_backup: %TRUE if a backup should be created
1886 * @flags: a set of #GFileCreateFlags
1887 * @cancellable: (allow-none): optional #GCancellable object,
1889 * @error: return location for a #GError, or %NULL
1891 * Returns an output stream for overwriting the file in readwrite mode,
1892 * possibly creating a backup copy of the file first. If the file doesn't
1893 * exist, it will be created.
1895 * For details about the behaviour, see g_file_replace() which does the
1896 * same thing but returns an output stream only.
1898 * Note that in many non-local file cases read and write streams are not
1899 * supported, so make sure you really need to do read and write streaming,
1900 * rather than just opening for reading or writing.
1902 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
1903 * Free the returned object with g_object_unref().
1908 g_file_replace_readwrite (GFile *file,
1910 gboolean make_backup,
1911 GFileCreateFlags flags,
1912 GCancellable *cancellable,
1917 g_return_val_if_fail (G_IS_FILE (file), NULL);
1919 if (g_cancellable_set_error_if_cancelled (cancellable, error))
1922 iface = G_FILE_GET_IFACE (file);
1924 if (iface->replace_readwrite == NULL)
1926 g_set_error_literal (error, G_IO_ERROR,
1927 G_IO_ERROR_NOT_SUPPORTED,
1928 _("Operation not supported"));
1932 return (* iface->replace_readwrite) (file, etag, make_backup, flags, cancellable, error);
1936 * g_file_read_async:
1937 * @file: input #GFile
1938 * @io_priority: the <link linkend="io-priority">I/O priority</link>
1940 * @cancellable: (allow-none): optional #GCancellable object,
1942 * @callback: (scope async): a #GAsyncReadyCallback to call
1943 * when the request is satisfied
1944 * @user_data: (closure): the data to pass to callback function
1946 * Asynchronously opens @file for reading.
1948 * For more details, see g_file_read() which is
1949 * the synchronous version of this call.
1951 * When the operation is finished, @callback will be called.
1952 * You can then call g_file_read_finish() to get the result
1956 g_file_read_async (GFile *file,
1958 GCancellable *cancellable,
1959 GAsyncReadyCallback callback,
1964 g_return_if_fail (G_IS_FILE (file));
1966 iface = G_FILE_GET_IFACE (file);
1967 (* iface->read_async) (file,
1975 * g_file_read_finish:
1976 * @file: input #GFile
1977 * @res: a #GAsyncResult
1978 * @error: a #GError, or %NULL
1980 * Finishes an asynchronous file read operation started with
1981 * g_file_read_async().
1983 * Returns: (transfer full): a #GFileInputStream or %NULL on error.
1984 * Free the returned object with g_object_unref().
1987 g_file_read_finish (GFile *file,
1993 g_return_val_if_fail (G_IS_FILE (file), NULL);
1994 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
1996 if (g_async_result_legacy_propagate_error (res, error))
1999 iface = G_FILE_GET_IFACE (file);
2000 return (* iface->read_finish) (file, res, error);
2004 * g_file_append_to_async:
2005 * @file: input #GFile
2006 * @flags: a set of #GFileCreateFlags
2007 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2009 * @cancellable: (allow-none): optional #GCancellable object,
2011 * @callback: (scope async): a #GAsyncReadyCallback to call
2012 * when the request is satisfied
2013 * @user_data: (closure): the data to pass to callback function
2015 * Asynchronously opens @file for appending.
2017 * For more details, see g_file_append_to() which is
2018 * the synchronous version of this call.
2020 * When the operation is finished, @callback will be called.
2021 * You can then call g_file_append_to_finish() to get the result
2025 g_file_append_to_async (GFile *file,
2026 GFileCreateFlags flags,
2028 GCancellable *cancellable,
2029 GAsyncReadyCallback callback,
2034 g_return_if_fail (G_IS_FILE (file));
2036 iface = G_FILE_GET_IFACE (file);
2037 (* iface->append_to_async) (file,
2046 * g_file_append_to_finish:
2047 * @file: input #GFile
2048 * @res: #GAsyncResult
2049 * @error: a #GError, or %NULL
2051 * Finishes an asynchronous file append operation started with
2052 * g_file_append_to_async().
2054 * Returns: (transfer full): a valid #GFileOutputStream
2055 * or %NULL on error.
2056 * Free the returned object with g_object_unref().
2059 g_file_append_to_finish (GFile *file,
2065 g_return_val_if_fail (G_IS_FILE (file), NULL);
2066 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2068 if (g_async_result_legacy_propagate_error (res, error))
2071 iface = G_FILE_GET_IFACE (file);
2072 return (* iface->append_to_finish) (file, res, error);
2076 * g_file_create_async:
2077 * @file: input #GFile
2078 * @flags: a set of #GFileCreateFlags
2079 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2081 * @cancellable: (allow-none): optional #GCancellable object,
2083 * @callback: (scope async): a #GAsyncReadyCallback to call
2084 * when the request is satisfied
2085 * @user_data: (closure): the data to pass to callback function
2087 * Asynchronously creates a new file and returns an output stream
2088 * for writing to it. The file must not already exist.
2090 * For more details, see g_file_create() which is
2091 * the synchronous version of this call.
2093 * When the operation is finished, @callback will be called.
2094 * You can then call g_file_create_finish() to get the result
2098 g_file_create_async (GFile *file,
2099 GFileCreateFlags flags,
2101 GCancellable *cancellable,
2102 GAsyncReadyCallback callback,
2107 g_return_if_fail (G_IS_FILE (file));
2109 iface = G_FILE_GET_IFACE (file);
2110 (* iface->create_async) (file,
2119 * g_file_create_finish:
2120 * @file: input #GFile
2121 * @res: a #GAsyncResult
2122 * @error: a #GError, or %NULL
2124 * Finishes an asynchronous file create operation started with
2125 * g_file_create_async().
2127 * Returns: (transfer full): a #GFileOutputStream or %NULL on error.
2128 * Free the returned object with g_object_unref().
2131 g_file_create_finish (GFile *file,
2137 g_return_val_if_fail (G_IS_FILE (file), NULL);
2138 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2140 if (g_async_result_legacy_propagate_error (res, error))
2143 iface = G_FILE_GET_IFACE (file);
2144 return (* iface->create_finish) (file, res, error);
2148 * g_file_replace_async:
2149 * @file: input #GFile
2150 * @etag: (allow-none): an <link linkend="gfile-etag">entity tag</link>
2151 * for the current #GFile, or NULL to ignore
2152 * @make_backup: %TRUE if a backup should be created
2153 * @flags: a set of #GFileCreateFlags
2154 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2156 * @cancellable: (allow-none): optional #GCancellable object,
2158 * @callback: (scope async): a #GAsyncReadyCallback to call
2159 * when the request is satisfied
2160 * @user_data: (closure): the data to pass to callback function
2162 * Asynchronously overwrites the file, replacing the contents,
2163 * possibly creating a backup copy of the file first.
2165 * For more details, see g_file_replace() which is
2166 * the synchronous version of this call.
2168 * When the operation is finished, @callback will be called.
2169 * You can then call g_file_replace_finish() to get the result
2173 g_file_replace_async (GFile *file,
2175 gboolean make_backup,
2176 GFileCreateFlags flags,
2178 GCancellable *cancellable,
2179 GAsyncReadyCallback callback,
2184 g_return_if_fail (G_IS_FILE (file));
2186 iface = G_FILE_GET_IFACE (file);
2187 (* iface->replace_async) (file,
2198 * g_file_replace_finish:
2199 * @file: input #GFile
2200 * @res: a #GAsyncResult
2201 * @error: a #GError, or %NULL
2203 * Finishes an asynchronous file replace operation started with
2204 * g_file_replace_async().
2206 * Returns: (transfer full): a #GFileOutputStream, or %NULL on error.
2207 * Free the returned object with g_object_unref().
2210 g_file_replace_finish (GFile *file,
2216 g_return_val_if_fail (G_IS_FILE (file), NULL);
2217 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2219 if (g_async_result_legacy_propagate_error (res, error))
2222 iface = G_FILE_GET_IFACE (file);
2223 return (* iface->replace_finish) (file, res, error);
2227 * g_file_open_readwrite_async
2228 * @file: input #GFile
2229 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2231 * @cancellable: (allow-none): optional #GCancellable object,
2233 * @callback: (scope async): a #GAsyncReadyCallback to call
2234 * when the request is satisfied
2235 * @user_data: (closure): the data to pass to callback function
2237 * Asynchronously opens @file for reading and writing.
2239 * For more details, see g_file_open_readwrite() which is
2240 * the synchronous version of this call.
2242 * When the operation is finished, @callback will be called.
2243 * You can then call g_file_open_readwrite_finish() to get
2244 * the result of the operation.
2249 g_file_open_readwrite_async (GFile *file,
2251 GCancellable *cancellable,
2252 GAsyncReadyCallback callback,
2257 g_return_if_fail (G_IS_FILE (file));
2259 iface = G_FILE_GET_IFACE (file);
2260 (* iface->open_readwrite_async) (file,
2268 * g_file_open_readwrite_finish:
2269 * @file: input #GFile
2270 * @res: a #GAsyncResult
2271 * @error: a #GError, or %NULL
2273 * Finishes an asynchronous file read operation started with
2274 * g_file_open_readwrite_async().
2276 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
2277 * Free the returned object with g_object_unref().
2282 g_file_open_readwrite_finish (GFile *file,
2288 g_return_val_if_fail (G_IS_FILE (file), NULL);
2289 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2291 if (g_async_result_legacy_propagate_error (res, error))
2294 iface = G_FILE_GET_IFACE (file);
2295 return (* iface->open_readwrite_finish) (file, res, error);
2299 * g_file_create_readwrite_async:
2300 * @file: input #GFile
2301 * @flags: a set of #GFileCreateFlags
2302 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2304 * @cancellable: (allow-none): optional #GCancellable object,
2306 * @callback: (scope async): a #GAsyncReadyCallback to call
2307 * when the request is satisfied
2308 * @user_data: (closure): the data to pass to callback function
2310 * Asynchronously creates a new file and returns a stream
2311 * for reading and writing to it. The file must not already exist.
2313 * For more details, see g_file_create_readwrite() which is
2314 * the synchronous version of this call.
2316 * When the operation is finished, @callback will be called.
2317 * You can then call g_file_create_readwrite_finish() to get
2318 * the result of the operation.
2323 g_file_create_readwrite_async (GFile *file,
2324 GFileCreateFlags flags,
2326 GCancellable *cancellable,
2327 GAsyncReadyCallback callback,
2332 g_return_if_fail (G_IS_FILE (file));
2334 iface = G_FILE_GET_IFACE (file);
2335 (* iface->create_readwrite_async) (file,
2344 * g_file_create_readwrite_finish:
2345 * @file: input #GFile
2346 * @res: a #GAsyncResult
2347 * @error: a #GError, or %NULL
2349 * Finishes an asynchronous file create operation started with
2350 * g_file_create_readwrite_async().
2352 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
2353 * Free the returned object with g_object_unref().
2358 g_file_create_readwrite_finish (GFile *file,
2364 g_return_val_if_fail (G_IS_FILE (file), NULL);
2365 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2367 if (g_async_result_legacy_propagate_error (res, error))
2370 iface = G_FILE_GET_IFACE (file);
2371 return (* iface->create_readwrite_finish) (file, res, error);
2375 * g_file_replace_readwrite_async:
2376 * @file: input #GFile
2377 * @etag: (allow-none): an <link linkend="gfile-etag">entity tag</link>
2378 * for the current #GFile, or NULL to ignore
2379 * @make_backup: %TRUE if a backup should be created
2380 * @flags: a set of #GFileCreateFlags
2381 * @io_priority: the <link linkend="io-priority">I/O priority</link>
2383 * @cancellable: (allow-none): optional #GCancellable object,
2385 * @callback: (scope async): a #GAsyncReadyCallback to call
2386 * when the request is satisfied
2387 * @user_data: (closure): the data to pass to callback function
2389 * Asynchronously overwrites the file in read-write mode,
2390 * replacing the contents, possibly creating a backup copy
2391 * of the file first.
2393 * For more details, see g_file_replace_readwrite() which is
2394 * the synchronous version of this call.
2396 * When the operation is finished, @callback will be called.
2397 * You can then call g_file_replace_readwrite_finish() to get
2398 * the result of the operation.
2403 g_file_replace_readwrite_async (GFile *file,
2405 gboolean make_backup,
2406 GFileCreateFlags flags,
2408 GCancellable *cancellable,
2409 GAsyncReadyCallback callback,
2414 g_return_if_fail (G_IS_FILE (file));
2416 iface = G_FILE_GET_IFACE (file);
2417 (* iface->replace_readwrite_async) (file,
2428 * g_file_replace_readwrite_finish:
2429 * @file: input #GFile
2430 * @res: a #GAsyncResult
2431 * @error: a #GError, or %NULL
2433 * Finishes an asynchronous file replace operation started with
2434 * g_file_replace_readwrite_async().
2436 * Returns: (transfer full): a #GFileIOStream, or %NULL on error.
2437 * Free the returned object with g_object_unref().
2442 g_file_replace_readwrite_finish (GFile *file,
2448 g_return_val_if_fail (G_IS_FILE (file), NULL);
2449 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
2451 if (g_async_result_legacy_propagate_error (res, error))
2454 iface = G_FILE_GET_IFACE (file);
2455 return (* iface->replace_readwrite_finish) (file, res, error);
2459 copy_symlink (GFile *destination,
2460 GFileCopyFlags flags,
2461 GCancellable *cancellable,
2466 gboolean tried_delete;
2468 GFileType file_type;
2470 tried_delete = FALSE;
2474 if (!g_file_make_symbolic_link (destination, target, cancellable, &my_error))
2476 /* Maybe it already existed, and we want to overwrite? */
2477 if (!tried_delete && (flags & G_FILE_COPY_OVERWRITE) &&
2478 my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_EXISTS)
2480 g_error_free (my_error);
2482 /* Don't overwrite if the destination is a directory */
2483 info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
2484 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2485 cancellable, &my_error);
2488 file_type = g_file_info_get_file_type (info);
2489 g_object_unref (info);
2491 if (file_type == G_FILE_TYPE_DIRECTORY)
2493 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY,
2494 _("Can't copy over directory"));
2499 if (!g_file_delete (destination, cancellable, error))
2502 tried_delete = TRUE;
2506 g_propagate_error (error, my_error);
2513 static GInputStream *
2514 open_source_for_copy (GFile *source,
2516 GFileCopyFlags flags,
2517 GCancellable *cancellable,
2523 GFileType file_type;
2526 in = (GInputStream *)g_file_read (source, cancellable, &my_error);
2530 /* There was an error opening the source, try to set a good error for it: */
2531 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_IS_DIRECTORY)
2533 /* The source is a directory, don't fail with WOULD_RECURSE immediately,
2534 * as that is less useful to the app. Better check for errors on the
2537 g_error_free (my_error);
2540 info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
2541 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2542 cancellable, &my_error);
2544 g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_TYPE))
2546 file_type = g_file_info_get_file_type (info);
2547 g_object_unref (info);
2549 if (flags & G_FILE_COPY_OVERWRITE)
2551 if (file_type == G_FILE_TYPE_DIRECTORY)
2553 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_MERGE,
2554 _("Can't copy directory over directory"));
2557 /* continue to would_recurse error */
2561 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
2562 _("Target file exists"));
2568 /* Error getting info from target, return that error
2569 * (except for NOT_FOUND, which is no error here)
2571 g_clear_object (&info);
2572 if (my_error != NULL && !g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
2574 g_propagate_error (error, my_error);
2577 g_clear_error (&my_error);
2580 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_RECURSE,
2581 _("Can't recursively copy directory"));
2585 g_propagate_error (error, my_error);
2590 should_copy (GFileAttributeInfo *info,
2592 gboolean skip_perms)
2594 if (skip_perms && strcmp(info->name, "unix::mode") == 0)
2598 return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED;
2599 return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE;
2603 build_attribute_list_for_copy (GFileAttributeInfoList *attributes,
2604 GFileAttributeInfoList *namespaces,
2606 gboolean skip_perms)
2613 s = g_string_new ("");
2617 for (i = 0; i < attributes->n_infos; i++)
2619 if (should_copy (&attributes->infos[i], as_move, skip_perms))
2624 g_string_append_c (s, ',');
2626 g_string_append (s, attributes->infos[i].name);
2633 for (i = 0; i < namespaces->n_infos; i++)
2635 if (should_copy (&namespaces->infos[i], as_move, FALSE))
2640 g_string_append_c (s, ',');
2642 g_string_append (s, namespaces->infos[i].name);
2643 g_string_append (s, "::*");
2648 return g_string_free (s, FALSE);
2652 * g_file_copy_attributes:
2653 * @source: a #GFile with attributes
2654 * @destination: a #GFile to copy attributes to
2655 * @flags: a set of #GFileCopyFlags
2656 * @cancellable: (allow-none): optional #GCancellable object,
2658 * @error: a #GError, %NULL to ignore
2660 * Copies the file attributes from @source to @destination.
2662 * Normally only a subset of the file attributes are copied,
2663 * those that are copies in a normal file copy operation
2664 * (which for instance does not include e.g. owner). However
2665 * if #G_FILE_COPY_ALL_METADATA is specified in @flags, then
2666 * all the metadata that is possible to copy is copied. This
2667 * is useful when implementing move by copy + delete source.
2669 * Returns: %TRUE if the attributes were copied successfully,
2673 g_file_copy_attributes (GFile *source,
2675 GFileCopyFlags flags,
2676 GCancellable *cancellable,
2679 GFileAttributeInfoList *attributes, *namespaces;
2680 char *attrs_to_read;
2684 gboolean source_nofollow_symlinks;
2685 gboolean skip_perms;
2687 as_move = flags & G_FILE_COPY_ALL_METADATA;
2688 source_nofollow_symlinks = flags & G_FILE_COPY_NOFOLLOW_SYMLINKS;
2689 skip_perms = (flags & G_FILE_COPY_TARGET_DEFAULT_PERMS) != 0;
2691 /* Ignore errors here, if the target supports no attributes there is
2694 attributes = g_file_query_settable_attributes (destination, cancellable, NULL);
2695 namespaces = g_file_query_writable_namespaces (destination, cancellable, NULL);
2697 if (attributes == NULL && namespaces == NULL)
2700 attrs_to_read = build_attribute_list_for_copy (attributes, namespaces, as_move, skip_perms);
2702 /* Ignore errors here, if we can't read some info (e.g. if it doesn't exist)
2703 * we just don't copy it.
2705 info = g_file_query_info (source, attrs_to_read,
2706 source_nofollow_symlinks ? G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS:0,
2710 g_free (attrs_to_read);
2715 res = g_file_set_attributes_from_info (destination,
2717 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
2720 g_object_unref (info);
2723 g_file_attribute_info_list_unref (attributes);
2724 g_file_attribute_info_list_unref (namespaces);
2730 copy_stream_with_progress (GInputStream *in,
2733 GCancellable *cancellable,
2734 GFileProgressCallback progress_callback,
2735 gpointer progress_callback_data,
2738 gssize n_read, n_written;
2739 goffset current_size;
2740 char buffer[1024*64], *p;
2746 /* avoid performance impact of querying total size when it's not needed */
2747 if (progress_callback)
2749 info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (in),
2750 G_FILE_ATTRIBUTE_STANDARD_SIZE,
2754 if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
2755 total_size = g_file_info_get_size (info);
2756 g_object_unref (info);
2759 if (total_size == -1)
2761 info = g_file_query_info (source,
2762 G_FILE_ATTRIBUTE_STANDARD_SIZE,
2763 G_FILE_QUERY_INFO_NONE,
2767 if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
2768 total_size = g_file_info_get_size (info);
2769 g_object_unref (info);
2774 if (total_size == -1)
2781 n_read = g_input_stream_read (in, buffer, sizeof (buffer), cancellable, error);
2791 current_size += n_read;
2796 n_written = g_output_stream_write (out, p, n_read, cancellable, error);
2797 if (n_written == -1)
2804 n_read -= n_written;
2810 if (progress_callback)
2811 progress_callback (current_size, total_size, progress_callback_data);
2814 /* Make sure we send full copied size */
2815 if (progress_callback)
2816 progress_callback (current_size, total_size, progress_callback_data);
2824 do_splice (int fd_in,
2829 long *bytes_transferd,
2835 result = splice (fd_in, off_in, fd_out, off_out, len, SPLICE_F_MORE);
2843 else if (errsv == ENOSYS || errsv == EINVAL)
2844 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
2845 _("Splice not supported"));
2847 g_set_error (error, G_IO_ERROR,
2848 g_io_error_from_errno (errsv),
2849 _("Error splicing file: %s"),
2850 g_strerror (errsv));
2855 *bytes_transferd = result;
2860 splice_stream_with_progress (GInputStream *in,
2862 GCancellable *cancellable,
2863 GFileProgressCallback progress_callback,
2864 gpointer progress_callback_data,
2867 int buffer[2] = { -1, -1 };
2874 fd_in = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (in));
2875 fd_out = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (out));
2877 if (!g_unix_open_pipe (buffer, FD_CLOEXEC, error))
2881 /* avoid performance impact of querying total size when it's not needed */
2882 if (progress_callback)
2886 if (fstat (fd_in, &sbuf) == 0)
2887 total_size = sbuf.st_size;
2890 if (total_size == -1)
2893 offset_in = offset_out = 0;
2900 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2903 if (!do_splice (fd_in, &offset_in, buffer[1], NULL, 1024*64, &n_read, error))
2914 if (g_cancellable_set_error_if_cancelled (cancellable, error))
2917 if (!do_splice (buffer[0], NULL, fd_out, &offset_out, n_read, &n_written, error))
2920 n_read -= n_written;
2923 if (progress_callback)
2924 progress_callback (offset_in, total_size, progress_callback_data);
2927 /* Make sure we send full copied size */
2928 if (progress_callback)
2929 progress_callback (offset_in, total_size, progress_callback_data);
2931 if (!g_close (buffer[0], error))
2934 if (!g_close (buffer[1], error))
2938 if (buffer[0] != -1)
2939 (void) g_close (buffer[0], NULL);
2940 if (buffer[1] != -1)
2941 (void) g_close (buffer[1], NULL);
2949 btrfs_reflink_with_progress (GInputStream *in,
2952 GCancellable *cancellable,
2953 GFileProgressCallback progress_callback,
2954 gpointer progress_callback_data,
2957 goffset source_size;
2961 fd_in = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (in));
2962 fd_out = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (out));
2964 if (progress_callback)
2965 source_size = g_file_info_get_size (info);
2967 /* Btrfs clone ioctl properties:
2968 * - Works at the inode level
2969 * - Doesn't work with directories
2970 * - Always follows symlinks (source and destination)
2972 * By the time we get here, *in and *out are both regular files */
2973 ret = ioctl (fd_out, BTRFS_IOC_CLONE, fd_in);
2978 g_set_error_literal (error, G_IO_ERROR,
2979 G_IO_ERROR_NOT_SUPPORTED,
2980 _("Copy (reflink/clone) between mounts is not supported"));
2981 else if (errno == EINVAL)
2982 g_set_error_literal (error, G_IO_ERROR,
2983 G_IO_ERROR_NOT_SUPPORTED,
2984 _("Copy (reflink/clone) is not supported or invalid"));
2986 /* Most probably something odd happened; retry with fallback */
2987 g_set_error_literal (error, G_IO_ERROR,
2988 G_IO_ERROR_NOT_SUPPORTED,
2989 _("Copy (reflink/clone) is not supported or didn't work"));
2990 /* We retry with fallback for all error cases because Btrfs is currently
2991 * unstable, and so we can't trust it to do clone properly.
2992 * In addition, any hard errors here would cause the same failure in the
2993 * fallback manual copy as well. */
2997 /* Make sure we send full copied size */
2998 if (progress_callback)
2999 progress_callback (source_size, source_size, progress_callback_data);
3006 file_copy_fallback (GFile *source,
3008 GFileCopyFlags flags,
3009 GCancellable *cancellable,
3010 GFileProgressCallback progress_callback,
3011 gpointer progress_callback_data,
3014 gboolean ret = FALSE;
3015 GInputStream *in = NULL;
3016 GOutputStream *out = NULL;
3017 GFileInfo *info = NULL;
3020 /* need to know the file type */
3021 info = g_file_query_info (source,
3022 G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
3023 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
3029 /* Maybe copy the symlink? */
3030 if ((flags & G_FILE_COPY_NOFOLLOW_SYMLINKS) &&
3031 g_file_info_get_file_type (info) == G_FILE_TYPE_SYMBOLIC_LINK)
3033 target = g_file_info_get_symlink_target (info);
3036 if (!copy_symlink (destination, flags, cancellable, target, error))
3042 /* ... else fall back on a regular file copy */
3044 /* Handle "special" files (pipes, device nodes, ...)? */
3045 else if (g_file_info_get_file_type (info) == G_FILE_TYPE_SPECIAL)
3047 /* FIXME: could try to recreate device nodes and others? */
3048 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
3049 _("Can't copy special file"));
3053 /* Everything else should just fall back on a regular copy. */
3055 in = open_source_for_copy (source, destination, flags, cancellable, error);
3059 if (flags & G_FILE_COPY_OVERWRITE)
3061 out = (GOutputStream *)g_file_replace (destination,
3063 flags & G_FILE_COPY_BACKUP,
3064 G_FILE_CREATE_REPLACE_DESTINATION,
3065 cancellable, error);
3069 out = (GOutputStream *)g_file_create (destination, 0, cancellable, error);
3076 if (G_IS_FILE_DESCRIPTOR_BASED (in) && G_IS_FILE_DESCRIPTOR_BASED (out))
3078 GError *reflink_err = NULL;
3080 if (!btrfs_reflink_with_progress (in, out, info, cancellable,
3081 progress_callback, progress_callback_data,
3084 if (g_error_matches (reflink_err, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
3086 g_clear_error (&reflink_err);
3090 g_propagate_error (error, reflink_err);
3103 if (G_IS_FILE_DESCRIPTOR_BASED (in) && G_IS_FILE_DESCRIPTOR_BASED (out))
3105 GError *splice_err = NULL;
3107 if (!splice_stream_with_progress (in, out, cancellable,
3108 progress_callback, progress_callback_data,
3111 if (g_error_matches (splice_err, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
3113 g_clear_error (&splice_err);
3117 g_propagate_error (error, splice_err);
3130 /* A plain read/write loop */
3131 if (!copy_stream_with_progress (in, out, source, cancellable,
3132 progress_callback, progress_callback_data,
3140 /* Don't care about errors in source here */
3141 (void) g_input_stream_close (in, cancellable, NULL);
3142 g_object_unref (in);
3147 /* But write errors on close are bad! */
3148 if (!g_output_stream_close (out, cancellable, ret ? error : NULL))
3150 g_object_unref (out);
3153 /* Ignore errors here. Failure to copy metadata is not a hard error */
3155 (void) g_file_copy_attributes (source, destination,
3156 flags, cancellable, NULL);
3159 g_clear_object (&info);
3166 * @source: input #GFile
3167 * @destination: destination #GFile
3168 * @flags: set of #GFileCopyFlags
3169 * @cancellable: (allow-none): optional #GCancellable object,
3171 * @progress_callback: (allow-none) (scope call): function to callback with
3172 * progress information, or %NULL if progress information is not needed
3173 * @progress_callback_data: (closure): user data to pass to @progress_callback
3174 * @error: #GError to set on error, or %NULL
3176 * Copies the file @source to the location specified by @destination.
3177 * Can not handle recursive copies of directories.
3179 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
3180 * existing @destination file is overwritten.
3182 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
3183 * will be copied as symlinks, otherwise the target of the
3184 * @source symlink will be copied.
3186 * If @cancellable is not %NULL, then the operation can be cancelled by
3187 * triggering the cancellable object from another thread. If the operation
3188 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3190 * If @progress_callback is not %NULL, then the operation can be monitored
3191 * by setting this to a #GFileProgressCallback function.
3192 * @progress_callback_data will be passed to this function. It is guaranteed
3193 * that this callback will be called after all data has been transferred with
3194 * the total number of bytes copied during the operation.
3196 * If the @source file does not exist, then the %G_IO_ERROR_NOT_FOUND error
3197 * is returned, independent on the status of the @destination.
3199 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then
3200 * the error %G_IO_ERROR_EXISTS is returned.
3202 * If trying to overwrite a file over a directory, the %G_IO_ERROR_IS_DIRECTORY
3203 * error is returned. If trying to overwrite a directory with a directory the
3204 * %G_IO_ERROR_WOULD_MERGE error is returned.
3206 * If the source is a directory and the target does not exist, or
3207 * #G_FILE_COPY_OVERWRITE is specified and the target is a file, then the
3208 * %G_IO_ERROR_WOULD_RECURSE error is returned.
3210 * If you are interested in copying the #GFile object itself (not the on-disk
3211 * file), see g_file_dup().
3213 * Returns: %TRUE on success, %FALSE otherwise.
3216 g_file_copy (GFile *source,
3218 GFileCopyFlags flags,
3219 GCancellable *cancellable,
3220 GFileProgressCallback progress_callback,
3221 gpointer progress_callback_data,
3228 g_return_val_if_fail (G_IS_FILE (source), FALSE);
3229 g_return_val_if_fail (G_IS_FILE (destination), FALSE);
3231 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3234 iface = G_FILE_GET_IFACE (destination);
3238 res = (* iface->copy) (source, destination,
3240 progress_callback, progress_callback_data,
3246 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3248 g_propagate_error (error, my_error);
3252 g_clear_error (&my_error);
3255 /* If the types are different, and the destination method failed
3256 * also try the source method
3258 if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
3260 iface = G_FILE_GET_IFACE (source);
3265 res = (* iface->copy) (source, destination,
3267 progress_callback, progress_callback_data,
3273 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3275 g_propagate_error (error, my_error);
3279 g_clear_error (&my_error);
3283 return file_copy_fallback (source, destination, flags, cancellable,
3284 progress_callback, progress_callback_data,
3289 * g_file_copy_async: (skip)
3290 * @source: input #GFile
3291 * @destination: destination #GFile
3292 * @flags: set of #GFileCopyFlags
3293 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3295 * @cancellable: (allow-none): optional #GCancellable object,
3297 * @progress_callback: (allow-none): function to callback with progress
3298 * information, or %NULL if progress information is not needed
3299 * @progress_callback_data: (closure): user data to pass to @progress_callback
3300 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
3301 * @user_data: the data to pass to callback function
3303 * Copies the file @source to the location specified by @destination
3304 * asynchronously. For details of the behaviour, see g_file_copy().
3306 * If @progress_callback is not %NULL, then that function that will be called
3307 * just like in g_file_copy(), however the callback will run in the main loop,
3308 * not in the thread that is doing the I/O operation.
3310 * When the operation is finished, @callback will be called. You can then call
3311 * g_file_copy_finish() to get the result of the operation.
3314 g_file_copy_async (GFile *source,
3316 GFileCopyFlags flags,
3318 GCancellable *cancellable,
3319 GFileProgressCallback progress_callback,
3320 gpointer progress_callback_data,
3321 GAsyncReadyCallback callback,
3326 g_return_if_fail (G_IS_FILE (source));
3327 g_return_if_fail (G_IS_FILE (destination));
3329 iface = G_FILE_GET_IFACE (source);
3330 (* iface->copy_async) (source,
3336 progress_callback_data,
3342 * g_file_copy_finish:
3343 * @file: input #GFile
3344 * @res: a #GAsyncResult
3345 * @error: a #GError, or %NULL
3347 * Finishes copying the file started with g_file_copy_async().
3349 * Returns: a %TRUE on success, %FALSE on error.
3352 g_file_copy_finish (GFile *file,
3358 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3359 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
3361 if (g_async_result_legacy_propagate_error (res, error))
3364 iface = G_FILE_GET_IFACE (file);
3365 return (* iface->copy_finish) (file, res, error);
3370 * @source: #GFile pointing to the source location
3371 * @destination: #GFile pointing to the destination location
3372 * @flags: set of #GFileCopyFlags
3373 * @cancellable: (allow-none): optional #GCancellable object,
3375 * @progress_callback: (allow-none) (scope call): #GFileProgressCallback
3376 * function for updates
3377 * @progress_callback_data: (closure): gpointer to user data for
3378 * the callback function
3379 * @error: #GError for returning error conditions, or %NULL
3381 * Tries to move the file or directory @source to the location specified
3382 * by @destination. If native move operations are supported then this is
3383 * used, otherwise a copy + delete fallback is used. The native
3384 * implementation may support moving directories (for instance on moves
3385 * inside the same filesystem), but the fallback code does not.
3387 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
3388 * existing @destination file is overwritten.
3390 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
3391 * will be copied as symlinks, otherwise the target of the
3392 * @source symlink will be copied.
3394 * If @cancellable is not %NULL, then the operation can be cancelled by
3395 * triggering the cancellable object from another thread. If the operation
3396 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3398 * If @progress_callback is not %NULL, then the operation can be monitored
3399 * by setting this to a #GFileProgressCallback function.
3400 * @progress_callback_data will be passed to this function. It is
3401 * guaranteed that this callback will be called after all data has been
3402 * transferred with the total number of bytes copied during the operation.
3404 * If the @source file does not exist, then the %G_IO_ERROR_NOT_FOUND
3405 * error is returned, independent on the status of the @destination.
3407 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists,
3408 * then the error %G_IO_ERROR_EXISTS is returned.
3410 * If trying to overwrite a file over a directory, the %G_IO_ERROR_IS_DIRECTORY
3411 * error is returned. If trying to overwrite a directory with a directory the
3412 * %G_IO_ERROR_WOULD_MERGE error is returned.
3414 * If the source is a directory and the target does not exist, or
3415 * #G_FILE_COPY_OVERWRITE is specified and the target is a file, then
3416 * the %G_IO_ERROR_WOULD_RECURSE error may be returned (if the native
3417 * move operation isn't available).
3419 * Returns: %TRUE on successful move, %FALSE otherwise.
3422 g_file_move (GFile *source,
3424 GFileCopyFlags flags,
3425 GCancellable *cancellable,
3426 GFileProgressCallback progress_callback,
3427 gpointer progress_callback_data,
3434 g_return_val_if_fail (G_IS_FILE (source), FALSE);
3435 g_return_val_if_fail (G_IS_FILE (destination), FALSE);
3437 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3440 iface = G_FILE_GET_IFACE (destination);
3444 res = (* iface->move) (source, destination,
3446 progress_callback, progress_callback_data,
3452 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3454 g_propagate_error (error, my_error);
3459 /* If the types are different, and the destination method failed
3460 * also try the source method
3462 if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
3464 iface = G_FILE_GET_IFACE (source);
3469 res = (* iface->move) (source, destination,
3471 progress_callback, progress_callback_data,
3477 if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
3479 g_propagate_error (error, my_error);
3485 if (flags & G_FILE_COPY_NO_FALLBACK_FOR_MOVE)
3487 g_set_error_literal (error, G_IO_ERROR,
3488 G_IO_ERROR_NOT_SUPPORTED,
3489 _("Operation not supported"));
3493 flags |= G_FILE_COPY_ALL_METADATA;
3494 if (!g_file_copy (source, destination, flags, cancellable,
3495 progress_callback, progress_callback_data,
3499 return g_file_delete (source, cancellable, error);
3503 * g_file_make_directory:
3504 * @file: input #GFile
3505 * @cancellable: (allow-none): optional #GCancellable object,
3507 * @error: a #GError, or %NULL
3509 * Creates a directory. Note that this will only create a child directory
3510 * of the immediate parent directory of the path or URI given by the #GFile.
3511 * To recursively create directories, see g_file_make_directory_with_parents().
3512 * This function will fail if the parent directory does not exist, setting
3513 * @error to %G_IO_ERROR_NOT_FOUND. If the file system doesn't support
3514 * creating directories, this function will fail, setting @error to
3515 * %G_IO_ERROR_NOT_SUPPORTED.
3517 * For a local #GFile the newly created directory will have the default
3518 * (current) ownership and permissions of the current process.
3520 * If @cancellable is not %NULL, then the operation can be cancelled by
3521 * triggering the cancellable object from another thread. If the operation
3522 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3524 * Returns: %TRUE on successful creation, %FALSE otherwise.
3527 g_file_make_directory (GFile *file,
3528 GCancellable *cancellable,
3533 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3535 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3538 iface = G_FILE_GET_IFACE (file);
3540 if (iface->make_directory == NULL)
3542 g_set_error_literal (error, G_IO_ERROR,
3543 G_IO_ERROR_NOT_SUPPORTED,
3544 _("Operation not supported"));
3548 return (* iface->make_directory) (file, cancellable, error);
3552 * g_file_make_directory_async:
3553 * @file: input #GFile
3554 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3556 * @cancellable: (allow-none): optional #GCancellable object,
3558 * @callback: a #GAsyncReadyCallback to call
3559 * when the request is satisfied
3560 * @user_data: the data to pass to callback function
3562 * Asynchronously creates a directory.
3564 * Virtual: make_directory_async
3568 g_file_make_directory_async (GFile *file,
3570 GCancellable *cancellable,
3571 GAsyncReadyCallback callback,
3576 g_return_if_fail (G_IS_FILE (file));
3578 iface = G_FILE_GET_IFACE (file);
3579 (* iface->make_directory_async) (file,
3587 * g_file_make_directory_finish:
3588 * @file: input #GFile
3589 * @result: a #GAsyncResult
3590 * @error: a #GError, or %NULL
3592 * Finishes an asynchronous directory creation, started with
3593 * g_file_make_directory_async().
3595 * Virtual: make_directory_finish
3596 * Returns: %TRUE on successful directory creation, %FALSE otherwise.
3600 g_file_make_directory_finish (GFile *file,
3601 GAsyncResult *result,
3606 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3607 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
3609 iface = G_FILE_GET_IFACE (file);
3610 return (* iface->make_directory_finish) (file, result, error);
3614 * g_file_make_directory_with_parents:
3615 * @file: input #GFile
3616 * @cancellable: (allow-none): optional #GCancellable object,
3618 * @error: a #GError, or %NULL
3620 * Creates a directory and any parent directories that may not
3621 * exist similar to 'mkdir -p'. If the file system does not support
3622 * creating directories, this function will fail, setting @error to
3623 * %G_IO_ERROR_NOT_SUPPORTED. If the directory itself already exists,
3624 * this function will fail setting @error to %G_IO_ERROR_EXISTS, unlike
3625 * the similar g_mkdir_with_parents().
3627 * For a local #GFile the newly created directories will have the default
3628 * (current) ownership and permissions of the current process.
3630 * If @cancellable is not %NULL, then the operation can be cancelled by
3631 * triggering the cancellable object from another thread. If the operation
3632 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3634 * Returns: %TRUE if all directories have been successfully created, %FALSE
3640 g_file_make_directory_with_parents (GFile *file,
3641 GCancellable *cancellable,
3644 GFile *work_file = NULL;
3645 GList *list = NULL, *l;
3646 GError *my_error = NULL;
3648 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3650 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3653 g_file_make_directory (file, cancellable, &my_error);
3654 if (my_error == NULL || my_error->code != G_IO_ERROR_NOT_FOUND)
3657 g_propagate_error (error, my_error);
3658 return my_error == NULL;
3661 work_file = g_object_ref (file);
3663 while (my_error != NULL && my_error->code == G_IO_ERROR_NOT_FOUND)
3667 parent_file = g_file_get_parent (work_file);
3668 if (parent_file == NULL)
3671 g_clear_error (&my_error);
3672 g_file_make_directory (parent_file, cancellable, &my_error);
3674 g_object_unref (work_file);
3675 work_file = g_object_ref (parent_file);
3677 if (my_error != NULL && my_error->code == G_IO_ERROR_NOT_FOUND)
3678 list = g_list_prepend (list, parent_file); /* Transfer ownership of ref */
3680 g_object_unref (parent_file);
3683 for (l = list; my_error == NULL && l; l = l->next)
3685 g_file_make_directory ((GFile *) l->data, cancellable, &my_error);
3689 g_object_unref (work_file);
3692 while (list != NULL)
3694 g_object_unref ((GFile *) list->data);
3695 list = g_list_remove (list, list->data);
3698 if (my_error != NULL)
3700 g_propagate_error (error, my_error);
3704 return g_file_make_directory (file, cancellable, error);
3708 * g_file_make_symbolic_link:
3709 * @file: a #GFile with the name of the symlink to create
3710 * @symlink_value: a string with the path for the target of the new symlink
3711 * @cancellable: (allow-none): optional #GCancellable object,
3715 * Creates a symbolic link named @file which contains the string
3718 * If @cancellable is not %NULL, then the operation can be cancelled by
3719 * triggering the cancellable object from another thread. If the operation
3720 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3722 * Returns: %TRUE on the creation of a new symlink, %FALSE otherwise.
3725 g_file_make_symbolic_link (GFile *file,
3726 const char *symlink_value,
3727 GCancellable *cancellable,
3732 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3733 g_return_val_if_fail (symlink_value != NULL, FALSE);
3735 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3738 if (*symlink_value == '\0')
3740 g_set_error_literal (error, G_IO_ERROR,
3741 G_IO_ERROR_INVALID_ARGUMENT,
3742 _("Invalid symlink value given"));
3746 iface = G_FILE_GET_IFACE (file);
3748 if (iface->make_symbolic_link == NULL)
3750 g_set_error_literal (error, G_IO_ERROR,
3751 G_IO_ERROR_NOT_SUPPORTED,
3752 _("Operation not supported"));
3756 return (* iface->make_symbolic_link) (file, symlink_value, cancellable, error);
3761 * @file: input #GFile
3762 * @cancellable: (allow-none): optional #GCancellable object,
3764 * @error: a #GError, or %NULL
3766 * Deletes a file. If the @file is a directory, it will only be
3767 * deleted if it is empty. This has the same semantics as g_unlink().
3769 * If @cancellable is not %NULL, then the operation can be cancelled by
3770 * triggering the cancellable object from another thread. If the operation
3771 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3773 * Virtual: delete_file
3774 * Returns: %TRUE if the file was deleted. %FALSE otherwise.
3777 g_file_delete (GFile *file,
3778 GCancellable *cancellable,
3783 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3785 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3788 iface = G_FILE_GET_IFACE (file);
3790 if (iface->delete_file == NULL)
3792 g_set_error_literal (error, G_IO_ERROR,
3793 G_IO_ERROR_NOT_SUPPORTED,
3794 _("Operation not supported"));
3798 return (* iface->delete_file) (file, cancellable, error);
3802 * g_file_delete_async:
3803 * @file: input #GFile
3804 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3806 * @cancellable: (allow-none): optional #GCancellable object,
3808 * @callback: a #GAsyncReadyCallback to call
3809 * when the request is satisfied
3810 * @user_data: the data to pass to callback function
3812 * Asynchronously delete a file. If the @file is a directory, it will
3813 * only be deleted if it is empty. This has the same semantics as
3816 * Virtual: delete_file_async
3820 g_file_delete_async (GFile *file,
3822 GCancellable *cancellable,
3823 GAsyncReadyCallback callback,
3828 g_return_if_fail (G_IS_FILE (file));
3830 iface = G_FILE_GET_IFACE (file);
3831 (* iface->delete_file_async) (file,
3839 * g_file_delete_finish:
3840 * @file: input #GFile
3841 * @result: a #GAsyncResult
3842 * @error: a #GError, or %NULL
3844 * Finishes deleting a file started with g_file_delete_async().
3846 * Virtual: delete_file_finish
3847 * Returns: %TRUE if the file was deleted. %FALSE otherwise.
3851 g_file_delete_finish (GFile *file,
3852 GAsyncResult *result,
3857 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3858 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
3860 if (g_async_result_legacy_propagate_error (result, error))
3863 iface = G_FILE_GET_IFACE (file);
3864 return (* iface->delete_file_finish) (file, result, error);
3869 * @file: #GFile to send to trash
3870 * @cancellable: (allow-none): optional #GCancellable object,
3872 * @error: a #GError, or %NULL
3874 * Sends @file to the "Trashcan", if possible. This is similar to
3875 * deleting it, but the user can recover it before emptying the trashcan.
3876 * Not all file systems support trashing, so this call can return the
3877 * %G_IO_ERROR_NOT_SUPPORTED error.
3879 * If @cancellable is not %NULL, then the operation can be cancelled by
3880 * triggering the cancellable object from another thread. If the operation
3881 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3884 * Returns: %TRUE on successful trash, %FALSE otherwise.
3887 g_file_trash (GFile *file,
3888 GCancellable *cancellable,
3893 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3895 if (g_cancellable_set_error_if_cancelled (cancellable, error))
3898 iface = G_FILE_GET_IFACE (file);
3900 if (iface->trash == NULL)
3902 g_set_error_literal (error,
3903 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
3904 _("Trash not supported"));
3908 return (* iface->trash) (file, cancellable, error);
3912 * g_file_trash_async:
3913 * @file: input #GFile
3914 * @io_priority: the <link linkend="io-priority">I/O priority</link>
3916 * @cancellable: (allow-none): optional #GCancellable object,
3918 * @callback: a #GAsyncReadyCallback to call
3919 * when the request is satisfied
3920 * @user_data: the data to pass to callback function
3922 * Asynchronously sends @file to the Trash location, if possible.
3924 * Virtual: trash_async
3928 g_file_trash_async (GFile *file,
3930 GCancellable *cancellable,
3931 GAsyncReadyCallback callback,
3936 g_return_if_fail (G_IS_FILE (file));
3938 iface = G_FILE_GET_IFACE (file);
3939 (* iface->trash_async) (file,
3947 * g_file_trash_finish:
3948 * @file: input #GFile
3949 * @result: a #GAsyncResult
3950 * @error: a #GError, or %NULL
3952 * Finishes an asynchronous file trashing operation, started with
3953 * g_file_trash_async().
3955 * Virtual: trash_finish
3956 * Returns: %TRUE on successful trash, %FALSE otherwise.
3960 g_file_trash_finish (GFile *file,
3961 GAsyncResult *result,
3966 g_return_val_if_fail (G_IS_FILE (file), FALSE);
3967 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
3969 iface = G_FILE_GET_IFACE (file);
3970 return (* iface->trash_finish) (file, result, error);
3974 * g_file_set_display_name:
3975 * @file: input #GFile
3976 * @display_name: a string
3977 * @cancellable: (allow-none): optional #GCancellable object,
3979 * @error: a #GError, or %NULL
3981 * Renames @file to the specified display name.
3983 * The display name is converted from UTF-8 to the correct encoding
3984 * for the target filesystem if possible and the @file is renamed to this.
3986 * If you want to implement a rename operation in the user interface the
3987 * edit name (#G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the
3988 * initial value in the rename widget, and then the result after editing
3989 * should be passed to g_file_set_display_name().
3991 * On success the resulting converted filename is returned.
3993 * If @cancellable is not %NULL, then the operation can be cancelled by
3994 * triggering the cancellable object from another thread. If the operation
3995 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3997 * Returns: (transfer full): a #GFile specifying what @file was renamed to,
3998 * or %NULL if there was an error.
3999 * Free the returned object with g_object_unref().
4002 g_file_set_display_name (GFile *file,
4003 const gchar *display_name,
4004 GCancellable *cancellable,
4009 g_return_val_if_fail (G_IS_FILE (file), NULL);
4010 g_return_val_if_fail (display_name != NULL, NULL);
4012 if (strchr (display_name, G_DIR_SEPARATOR) != NULL)
4016 G_IO_ERROR_INVALID_ARGUMENT,
4017 _("File names cannot contain '%c'"), G_DIR_SEPARATOR);
4021 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4024 iface = G_FILE_GET_IFACE (file);
4026 return (* iface->set_display_name) (file, display_name, cancellable, error);
4030 * g_file_set_display_name_async:
4031 * @file: input #GFile
4032 * @display_name: a string
4033 * @io_priority: the <link linkend="io-priority">I/O priority</link>
4035 * @cancellable: (allow-none): optional #GCancellable object,
4037 * @callback: (scope async): a #GAsyncReadyCallback to call
4038 * when the request is satisfied
4039 * @user_data: (closure): the data to pass to callback function
4041 * Asynchronously sets the display name for a given #GFile.
4043 * For more details, see g_file_set_display_name() which is
4044 * the synchronous version of this call.
4046 * When the operation is finished, @callback will be called.
4047 * You can then call g_file_set_display_name_finish() to get
4048 * the result of the operation.
4051 g_file_set_display_name_async (GFile *file,
4052 const gchar *display_name,
4054 GCancellable *cancellable,
4055 GAsyncReadyCallback callback,
4060 g_return_if_fail (G_IS_FILE (file));
4061 g_return_if_fail (display_name != NULL);
4063 iface = G_FILE_GET_IFACE (file);
4064 (* iface->set_display_name_async) (file,
4073 * g_file_set_display_name_finish:
4074 * @file: input #GFile
4075 * @res: a #GAsyncResult
4076 * @error: a #GError, or %NULL
4078 * Finishes setting a display name started with
4079 * g_file_set_display_name_async().
4081 * Returns: (transfer full): a #GFile or %NULL on error.
4082 * Free the returned object with g_object_unref().
4085 g_file_set_display_name_finish (GFile *file,
4091 g_return_val_if_fail (G_IS_FILE (file), NULL);
4092 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
4094 if (g_async_result_legacy_propagate_error (res, error))
4097 iface = G_FILE_GET_IFACE (file);
4098 return (* iface->set_display_name_finish) (file, res, error);
4102 * g_file_query_settable_attributes:
4103 * @file: input #GFile
4104 * @cancellable: (allow-none): optional #GCancellable object,
4106 * @error: a #GError, or %NULL
4108 * Obtain the list of settable attributes for the file.
4110 * Returns the type and full attribute name of all the attributes
4111 * that can be set on this file. This doesn't mean setting it will
4112 * always succeed though, you might get an access failure, or some
4113 * specific file may not support a specific attribute.
4115 * If @cancellable is not %NULL, then the operation can be cancelled by
4116 * triggering the cancellable object from another thread. If the operation
4117 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4119 * Returns: a #GFileAttributeInfoList describing the settable attributes.
4120 * When you are done with it, release it with
4121 * g_file_attribute_info_list_unref()
4123 GFileAttributeInfoList *
4124 g_file_query_settable_attributes (GFile *file,
4125 GCancellable *cancellable,
4130 GFileAttributeInfoList *list;
4132 g_return_val_if_fail (G_IS_FILE (file), NULL);
4134 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4137 iface = G_FILE_GET_IFACE (file);
4139 if (iface->query_settable_attributes == NULL)
4140 return g_file_attribute_info_list_new ();
4143 list = (* iface->query_settable_attributes) (file, cancellable, &my_error);
4147 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
4149 list = g_file_attribute_info_list_new ();
4150 g_error_free (my_error);
4153 g_propagate_error (error, my_error);
4160 * g_file_query_writable_namespaces:
4161 * @file: input #GFile
4162 * @cancellable: (allow-none): optional #GCancellable object,
4164 * @error: a #GError, or %NULL
4166 * Obtain the list of attribute namespaces where new attributes
4167 * can be created by a user. An example of this is extended
4168 * attributes (in the "xattr" namespace).
4170 * If @cancellable is not %NULL, then the operation can be cancelled by
4171 * triggering the cancellable object from another thread. If the operation
4172 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4174 * Returns: a #GFileAttributeInfoList describing the writable namespaces.
4175 * When you are done with it, release it with
4176 * g_file_attribute_info_list_unref()
4178 GFileAttributeInfoList *
4179 g_file_query_writable_namespaces (GFile *file,
4180 GCancellable *cancellable,
4185 GFileAttributeInfoList *list;
4187 g_return_val_if_fail (G_IS_FILE (file), NULL);
4189 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4192 iface = G_FILE_GET_IFACE (file);
4194 if (iface->query_writable_namespaces == NULL)
4195 return g_file_attribute_info_list_new ();
4198 list = (* iface->query_writable_namespaces) (file, cancellable, &my_error);
4202 if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
4204 list = g_file_attribute_info_list_new ();
4205 g_error_free (my_error);
4208 g_propagate_error (error, my_error);
4215 * g_file_set_attribute:
4216 * @file: input #GFile
4217 * @attribute: a string containing the attribute's name
4218 * @type: The type of the attribute
4219 * @value_p: (allow-none): a pointer to the value (or the pointer
4220 * itself if the type is a pointer type)
4221 * @flags: a set of #GFileQueryInfoFlags
4222 * @cancellable: (allow-none): optional #GCancellable object,
4224 * @error: a #GError, or %NULL
4226 * Sets an attribute in the file with attribute name @attribute to @value.
4228 * Some attributes can be unset by setting @attribute to
4229 * %G_FILE_ATTRIBUTE_TYPE_INVALID and @value_p to %NULL.
4231 * If @cancellable is not %NULL, then the operation can be cancelled by
4232 * triggering the cancellable object from another thread. If the operation
4233 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4235 * Returns: %TRUE if the attribute was set, %FALSE otherwise.
4238 g_file_set_attribute (GFile *file,
4239 const gchar *attribute,
4240 GFileAttributeType type,
4242 GFileQueryInfoFlags flags,
4243 GCancellable *cancellable,
4248 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4249 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
4251 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4254 iface = G_FILE_GET_IFACE (file);
4256 if (iface->set_attribute == NULL)
4258 g_set_error_literal (error, G_IO_ERROR,
4259 G_IO_ERROR_NOT_SUPPORTED,
4260 _("Operation not supported"));
4264 return (* iface->set_attribute) (file, attribute, type, value_p, flags, cancellable, error);
4268 * g_file_set_attributes_from_info:
4269 * @file: input #GFile
4270 * @info: a #GFileInfo
4271 * @flags: #GFileQueryInfoFlags
4272 * @cancellable: (allow-none): optional #GCancellable object,
4274 * @error: a #GError, or %NULL
4276 * Tries to set all attributes in the #GFileInfo on the target
4277 * values, not stopping on the first error.
4279 * If there is any error during this operation then @error will
4280 * be set to the first error. Error on particular fields are flagged
4281 * by setting the "status" field in the attribute value to
4282 * %G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can
4283 * also detect further errors.
4285 * If @cancellable is not %NULL, then the operation can be cancelled by
4286 * triggering the cancellable object from another thread. If the operation
4287 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4289 * Returns: %FALSE if there was any error, %TRUE otherwise.
4292 g_file_set_attributes_from_info (GFile *file,
4294 GFileQueryInfoFlags flags,
4295 GCancellable *cancellable,
4300 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4301 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
4303 if (g_cancellable_set_error_if_cancelled (cancellable, error))
4306 g_file_info_clear_status (info);
4308 iface = G_FILE_GET_IFACE (file);
4310 return (* iface->set_attributes_from_info) (file,
4318 g_file_real_set_attributes_from_info (GFile *file,
4320 GFileQueryInfoFlags flags,
4321 GCancellable *cancellable,
4327 GFileAttributeValue *value;
4331 attributes = g_file_info_list_attributes (info, NULL);
4333 for (i = 0; attributes[i] != NULL; i++)
4335 value = _g_file_info_get_attribute_value (info, attributes[i]);
4337 if (value->status != G_FILE_ATTRIBUTE_STATUS_UNSET)
4340 if (!g_file_set_attribute (file, attributes[i],
4341 value->type, _g_file_attribute_value_peek_as_pointer (value),
4342 flags, cancellable, error))
4344 value->status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
4346 /* Don't set error multiple times */
4350 value->status = G_FILE_ATTRIBUTE_STATUS_SET;
4353 g_strfreev (attributes);
4359 * g_file_set_attributes_async:
4360 * @file: input #GFile
4361 * @info: a #GFileInfo
4362 * @flags: a #GFileQueryInfoFlags
4363 * @io_priority: the <link linkend="io-priority">I/O priority</link>
4365 * @cancellable: (allow-none): optional #GCancellable object,
4367 * @callback: (scope async): a #GAsyncReadyCallback
4368 * @user_data: (closure): a #gpointer
4370 * Asynchronously sets the attributes of @file with @info.
4372 * For more details, see g_file_set_attributes_from_info(),
4373 * which is the synchronous version of this call.
4375 * When the operation is finished, @callback will be called.
4376 * You can then call g_file_set_attributes_finish() to get
4377 * the result of the operation.
4380 g_file_set_attributes_async (GFile *file,
4382 GFileQueryInfoFlags flags,
4384 GCancellable *cancellable,
4385 GAsyncReadyCallback callback,
4390 g_return_if_fail (G_IS_FILE (file));
4391 g_return_if_fail (G_IS_FILE_INFO (info));
4393 iface = G_FILE_GET_IFACE (file);
4394 (* iface->set_attributes_async) (file,
4404 * g_file_set_attributes_finish:
4405 * @file: input #GFile
4406 * @result: a #GAsyncResult
4407 * @info: (out) (transfer full): a #GFileInfo
4408 * @error: a #GError, or %NULL
4410 * Finishes setting an attribute started in g_file_set_attributes_async().
4412 * Returns: %TRUE if the attributes were set correctly, %FALSE otherwise.
4415 g_file_set_attributes_finish (GFile *file,
4416 GAsyncResult *result,
4422 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4423 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4425 /* No standard handling of errors here, as we must set info even
4428 iface = G_FILE_GET_IFACE (file);
4429 return (* iface->set_attributes_finish) (file, result, info, error);
4433 * g_file_set_attribute_string:
4434 * @file: input #GFile
4435 * @attribute: a string containing the attribute's name
4436 * @value: a string containing the attribute's value
4437 * @flags: #GFileQueryInfoFlags
4438 * @cancellable: (allow-none): optional #GCancellable object,
4440 * @error: a #GError, or %NULL
4442 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value.
4443 * If @attribute is of a different type, this operation will fail.
4445 * If @cancellable is not %NULL, then the operation can be cancelled by
4446 * triggering the cancellable object from another thread. If the operation
4447 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4449 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
4452 g_file_set_attribute_string (GFile *file,
4453 const char *attribute,
4455 GFileQueryInfoFlags flags,
4456 GCancellable *cancellable,
4459 return g_file_set_attribute (file, attribute,
4460 G_FILE_ATTRIBUTE_TYPE_STRING, (gpointer)value,
4461 flags, cancellable, error);
4465 * g_file_set_attribute_byte_string:
4466 * @file: input #GFile
4467 * @attribute: a string containing the attribute's name
4468 * @value: a string containing the attribute's new value
4469 * @flags: a #GFileQueryInfoFlags
4470 * @cancellable: (allow-none): optional #GCancellable object,
4472 * @error: a #GError, or %NULL
4474 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value.
4475 * If @attribute is of a different type, this operation will fail,
4478 * If @cancellable is not %NULL, then the operation can be cancelled by
4479 * triggering the cancellable object from another thread. If the operation
4480 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4482 * Returns: %TRUE if the @attribute was successfully set to @value
4483 * in the @file, %FALSE otherwise.
4486 g_file_set_attribute_byte_string (GFile *file,
4487 const gchar *attribute,
4489 GFileQueryInfoFlags flags,
4490 GCancellable *cancellable,
4493 return g_file_set_attribute (file, attribute,
4494 G_FILE_ATTRIBUTE_TYPE_BYTE_STRING, (gpointer)value,
4495 flags, cancellable, error);
4499 * g_file_set_attribute_uint32:
4500 * @file: input #GFile
4501 * @attribute: a string containing the attribute's name
4502 * @value: a #guint32 containing the attribute's new value
4503 * @flags: a #GFileQueryInfoFlags
4504 * @cancellable: (allow-none): optional #GCancellable object,
4506 * @error: a #GError, or %NULL
4508 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value.
4509 * If @attribute is of a different type, this operation will fail.
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 * Returns: %TRUE if the @attribute was successfully set to @value
4516 * in the @file, %FALSE otherwise.
4519 g_file_set_attribute_uint32 (GFile *file,
4520 const gchar *attribute,
4522 GFileQueryInfoFlags flags,
4523 GCancellable *cancellable,
4526 return g_file_set_attribute (file, attribute,
4527 G_FILE_ATTRIBUTE_TYPE_UINT32, &value,
4528 flags, cancellable, error);
4532 * g_file_set_attribute_int32:
4533 * @file: input #GFile
4534 * @attribute: a string containing the attribute's name
4535 * @value: a #gint32 containing the attribute's new value
4536 * @flags: a #GFileQueryInfoFlags
4537 * @cancellable: (allow-none): optional #GCancellable object,
4539 * @error: a #GError, or %NULL
4541 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value.
4542 * If @attribute is of a different type, this operation will fail.
4544 * If @cancellable is not %NULL, then the operation can be cancelled by
4545 * triggering the cancellable object from another thread. If the operation
4546 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4548 * Returns: %TRUE if the @attribute was successfully set to @value
4549 * in the @file, %FALSE otherwise.
4552 g_file_set_attribute_int32 (GFile *file,
4553 const gchar *attribute,
4555 GFileQueryInfoFlags flags,
4556 GCancellable *cancellable,
4559 return g_file_set_attribute (file, attribute,
4560 G_FILE_ATTRIBUTE_TYPE_INT32, &value,
4561 flags, cancellable, error);
4565 * g_file_set_attribute_uint64:
4566 * @file: input #GFile
4567 * @attribute: a string containing the attribute's name
4568 * @value: a #guint64 containing the attribute's new value
4569 * @flags: a #GFileQueryInfoFlags
4570 * @cancellable: (allow-none): optional #GCancellable object,
4572 * @error: a #GError, or %NULL
4574 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value.
4575 * If @attribute is of a different type, this operation will fail.
4577 * If @cancellable is not %NULL, then the operation can be cancelled by
4578 * triggering the cancellable object from another thread. If the operation
4579 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4581 * Returns: %TRUE if the @attribute was successfully set to @value
4582 * in the @file, %FALSE otherwise.
4585 g_file_set_attribute_uint64 (GFile *file,
4586 const gchar *attribute,
4588 GFileQueryInfoFlags flags,
4589 GCancellable *cancellable,
4592 return g_file_set_attribute (file, attribute,
4593 G_FILE_ATTRIBUTE_TYPE_UINT64, &value,
4594 flags, cancellable, error);
4598 * g_file_set_attribute_int64:
4599 * @file: input #GFile
4600 * @attribute: a string containing the attribute's name
4601 * @value: a #guint64 containing the attribute's new value
4602 * @flags: a #GFileQueryInfoFlags
4603 * @cancellable: (allow-none): optional #GCancellable object,
4605 * @error: a #GError, or %NULL
4607 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value.
4608 * If @attribute is of a different type, this operation will fail.
4610 * If @cancellable is not %NULL, then the operation can be cancelled by
4611 * triggering the cancellable object from another thread. If the operation
4612 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4614 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
4617 g_file_set_attribute_int64 (GFile *file,
4618 const gchar *attribute,
4620 GFileQueryInfoFlags flags,
4621 GCancellable *cancellable,
4624 return g_file_set_attribute (file, attribute,
4625 G_FILE_ATTRIBUTE_TYPE_INT64, &value,
4626 flags, cancellable, error);
4630 * g_file_mount_mountable:
4631 * @file: input #GFile
4632 * @flags: flags affecting the operation
4633 * @mount_operation: (allow-none): a #GMountOperation,
4634 * or %NULL to avoid user interaction
4635 * @cancellable: (allow-none): optional #GCancellable object,
4637 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call
4638 * when the request is satisfied, or %NULL
4639 * @user_data: (closure): the data to pass to callback function
4641 * Mounts a file of type G_FILE_TYPE_MOUNTABLE.
4642 * Using @mount_operation, you can request callbacks when, for instance,
4643 * passwords are needed during authentication.
4645 * If @cancellable is not %NULL, then the operation can be cancelled by
4646 * triggering the cancellable object from another thread. If the operation
4647 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4649 * When the operation is finished, @callback will be called.
4650 * You can then call g_file_mount_mountable_finish() to get
4651 * the result of the operation.
4654 g_file_mount_mountable (GFile *file,
4655 GMountMountFlags flags,
4656 GMountOperation *mount_operation,
4657 GCancellable *cancellable,
4658 GAsyncReadyCallback callback,
4663 g_return_if_fail (G_IS_FILE (file));
4665 iface = G_FILE_GET_IFACE (file);
4667 if (iface->mount_mountable == NULL)
4669 g_task_report_new_error (file, callback, user_data,
4670 g_file_mount_mountable,
4671 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
4672 _("Operation not supported"));
4676 (* iface->mount_mountable) (file,
4685 * g_file_mount_mountable_finish:
4686 * @file: input #GFile
4687 * @result: a #GAsyncResult
4688 * @error: a #GError, or %NULL
4690 * Finishes a mount operation. See g_file_mount_mountable() for details.
4692 * Finish an asynchronous mount operation that was started
4693 * with g_file_mount_mountable().
4695 * Returns: (transfer full): a #GFile or %NULL on error.
4696 * Free the returned object with g_object_unref().
4699 g_file_mount_mountable_finish (GFile *file,
4700 GAsyncResult *result,
4705 g_return_val_if_fail (G_IS_FILE (file), NULL);
4706 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
4708 if (g_async_result_legacy_propagate_error (result, error))
4710 else if (g_async_result_is_tagged (result, g_file_mount_mountable))
4711 return g_task_propagate_pointer (G_TASK (result), error);
4713 iface = G_FILE_GET_IFACE (file);
4714 return (* iface->mount_mountable_finish) (file, result, error);
4718 * g_file_unmount_mountable:
4719 * @file: input #GFile
4720 * @flags: flags affecting the operation
4721 * @cancellable: (allow-none): optional #GCancellable object,
4723 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call
4724 * when the request is satisfied, or %NULL
4725 * @user_data: (closure): the data to pass to callback function
4727 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
4729 * If @cancellable is not %NULL, then the operation can be cancelled by
4730 * triggering the cancellable object from another thread. If the operation
4731 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4733 * When the operation is finished, @callback will be called.
4734 * You can then call g_file_unmount_mountable_finish() to get
4735 * the result of the operation.
4737 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation() instead.
4740 g_file_unmount_mountable (GFile *file,
4741 GMountUnmountFlags flags,
4742 GCancellable *cancellable,
4743 GAsyncReadyCallback callback,
4748 g_return_if_fail (G_IS_FILE (file));
4750 iface = G_FILE_GET_IFACE (file);
4752 if (iface->unmount_mountable == NULL)
4754 g_task_report_new_error (file, callback, user_data,
4755 g_file_unmount_mountable_with_operation,
4756 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
4757 _("Operation not supported"));
4761 (* iface->unmount_mountable) (file,
4769 * g_file_unmount_mountable_finish:
4770 * @file: input #GFile
4771 * @result: a #GAsyncResult
4772 * @error: a #GError, or %NULL
4774 * Finishes an unmount operation, see g_file_unmount_mountable() for details.
4776 * Finish an asynchronous unmount operation that was started
4777 * with g_file_unmount_mountable().
4779 * Returns: %TRUE if the operation finished successfully.
4782 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation_finish()
4786 g_file_unmount_mountable_finish (GFile *file,
4787 GAsyncResult *result,
4792 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4793 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4795 if (g_async_result_legacy_propagate_error (result, error))
4797 else if (g_async_result_is_tagged (result, g_file_unmount_mountable_with_operation))
4798 return g_task_propagate_boolean (G_TASK (result), error);
4800 iface = G_FILE_GET_IFACE (file);
4801 return (* iface->unmount_mountable_finish) (file, result, error);
4805 * g_file_unmount_mountable_with_operation:
4806 * @file: input #GFile
4807 * @flags: flags affecting the operation
4808 * @mount_operation: (allow-none): a #GMountOperation,
4809 * or %NULL to avoid user interaction
4810 * @cancellable: (allow-none): optional #GCancellable object,
4812 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call
4813 * when the request is satisfied, or %NULL
4814 * @user_data: (closure): the data to pass to callback function
4816 * Unmounts a file of type #G_FILE_TYPE_MOUNTABLE.
4818 * If @cancellable is not %NULL, then the operation can be cancelled by
4819 * triggering the cancellable object from another thread. If the operation
4820 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4822 * When the operation is finished, @callback will be called.
4823 * You can then call g_file_unmount_mountable_finish() to get
4824 * the result of the operation.
4829 g_file_unmount_mountable_with_operation (GFile *file,
4830 GMountUnmountFlags flags,
4831 GMountOperation *mount_operation,
4832 GCancellable *cancellable,
4833 GAsyncReadyCallback callback,
4838 g_return_if_fail (G_IS_FILE (file));
4840 iface = G_FILE_GET_IFACE (file);
4842 if (iface->unmount_mountable == NULL && iface->unmount_mountable_with_operation == NULL)
4844 g_task_report_new_error (file, callback, user_data,
4845 g_file_unmount_mountable_with_operation,
4846 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
4847 _("Operation not supported"));
4851 if (iface->unmount_mountable_with_operation != NULL)
4852 (* iface->unmount_mountable_with_operation) (file,
4859 (* iface->unmount_mountable) (file,
4867 * g_file_unmount_mountable_with_operation_finish:
4868 * @file: input #GFile
4869 * @result: a #GAsyncResult
4870 * @error: a #GError, or %NULL
4872 * Finishes an unmount operation,
4873 * see g_file_unmount_mountable_with_operation() for details.
4875 * Finish an asynchronous unmount operation that was started
4876 * with g_file_unmount_mountable_with_operation().
4878 * Returns: %TRUE if the operation finished successfully.
4884 g_file_unmount_mountable_with_operation_finish (GFile *file,
4885 GAsyncResult *result,
4890 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4891 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4893 if (g_async_result_legacy_propagate_error (result, error))
4895 else if (g_async_result_is_tagged (result, g_file_unmount_mountable_with_operation))
4896 return g_task_propagate_boolean (G_TASK (result), error);
4898 iface = G_FILE_GET_IFACE (file);
4899 if (iface->unmount_mountable_with_operation_finish != NULL)
4900 return (* iface->unmount_mountable_with_operation_finish) (file, result, error);
4902 return (* iface->unmount_mountable_finish) (file, result, error);
4906 * g_file_eject_mountable:
4907 * @file: input #GFile
4908 * @flags: flags affecting the operation
4909 * @cancellable: (allow-none): optional #GCancellable object,
4911 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call
4912 * when the request is satisfied, or %NULL
4913 * @user_data: (closure): the data to pass to callback function
4915 * Starts an asynchronous eject on a mountable.
4916 * When this operation has completed, @callback will be called with
4917 * @user_user data, and the operation can be finalized with
4918 * g_file_eject_mountable_finish().
4920 * If @cancellable is not %NULL, then the operation can be cancelled by
4921 * triggering the cancellable object from another thread. If the operation
4922 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4924 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation() instead.
4927 g_file_eject_mountable (GFile *file,
4928 GMountUnmountFlags flags,
4929 GCancellable *cancellable,
4930 GAsyncReadyCallback callback,
4935 g_return_if_fail (G_IS_FILE (file));
4937 iface = G_FILE_GET_IFACE (file);
4939 if (iface->eject_mountable == NULL)
4941 g_task_report_new_error (file, callback, user_data,
4942 g_file_eject_mountable_with_operation,
4943 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
4944 _("Operation not supported"));
4948 (* iface->eject_mountable) (file,
4956 * g_file_eject_mountable_finish:
4957 * @file: input #GFile
4958 * @result: a #GAsyncResult
4959 * @error: a #GError, or %NULL
4961 * Finishes an asynchronous eject operation started by
4962 * g_file_eject_mountable().
4964 * Returns: %TRUE if the @file was ejected successfully.
4967 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation_finish()
4971 g_file_eject_mountable_finish (GFile *file,
4972 GAsyncResult *result,
4977 g_return_val_if_fail (G_IS_FILE (file), FALSE);
4978 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
4980 if (g_async_result_legacy_propagate_error (result, error))
4982 else if (g_async_result_is_tagged (result, g_file_eject_mountable_with_operation))
4983 return g_task_propagate_boolean (G_TASK (result), error);
4985 iface = G_FILE_GET_IFACE (file);
4986 return (* iface->eject_mountable_finish) (file, result, error);
4990 * g_file_eject_mountable_with_operation:
4991 * @file: input #GFile
4992 * @flags: flags affecting the operation
4993 * @mount_operation: (allow-none): a #GMountOperation,
4994 * or %NULL to avoid user interaction
4995 * @cancellable: (allow-none): optional #GCancellable object,
4997 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call
4998 * when the request is satisfied, or %NULL
4999 * @user_data: (closure): the data to pass to callback function
5001 * Starts an asynchronous eject on a mountable.
5002 * When this operation has completed, @callback will be called with
5003 * @user_user data, and the operation can be finalized with
5004 * g_file_eject_mountable_with_operation_finish().
5006 * If @cancellable is not %NULL, then the operation can be cancelled by
5007 * triggering the cancellable object from another thread. If the operation
5008 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5013 g_file_eject_mountable_with_operation (GFile *file,
5014 GMountUnmountFlags flags,
5015 GMountOperation *mount_operation,
5016 GCancellable *cancellable,
5017 GAsyncReadyCallback callback,
5022 g_return_if_fail (G_IS_FILE (file));
5024 iface = G_FILE_GET_IFACE (file);
5026 if (iface->eject_mountable == NULL && iface->eject_mountable_with_operation == NULL)
5028 g_task_report_new_error (file, callback, user_data,
5029 g_file_eject_mountable_with_operation,
5030 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
5031 _("Operation not supported"));
5035 if (iface->eject_mountable_with_operation != NULL)
5036 (* iface->eject_mountable_with_operation) (file,
5043 (* iface->eject_mountable) (file,
5051 * g_file_eject_mountable_with_operation_finish:
5052 * @file: input #GFile
5053 * @result: a #GAsyncResult
5054 * @error: a #GError, or %NULL
5056 * Finishes an asynchronous eject operation started by
5057 * g_file_eject_mountable_with_operation().
5059 * Returns: %TRUE if the @file was ejected successfully.
5065 g_file_eject_mountable_with_operation_finish (GFile *file,
5066 GAsyncResult *result,
5071 g_return_val_if_fail (G_IS_FILE (file), FALSE);
5072 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
5074 if (g_async_result_legacy_propagate_error (result, error))
5076 else if (g_async_result_is_tagged (result, g_file_eject_mountable_with_operation))
5077 return g_task_propagate_boolean (G_TASK (result), error);
5079 iface = G_FILE_GET_IFACE (file);
5080 if (iface->eject_mountable_with_operation_finish != NULL)
5081 return (* iface->eject_mountable_with_operation_finish) (file, result, error);
5083 return (* iface->eject_mountable_finish) (file, result, error);
5087 * g_file_monitor_directory:
5088 * @file: input #GFile
5089 * @flags: a set of #GFileMonitorFlags
5090 * @cancellable: (allow-none): optional #GCancellable object,
5092 * @error: a #GError, or %NULL
5094 * Obtains a directory monitor for the given file.
5095 * This may fail if directory monitoring is not supported.
5097 * If @cancellable is not %NULL, then the operation can be cancelled by
5098 * triggering the cancellable object from another thread. If the operation
5099 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5101 * It does not make sense for @flags to contain
5102 * %G_FILE_MONITOR_WATCH_HARD_LINKS, since hard links can not be made to
5103 * directories. It is not possible to monitor all the files in a
5104 * directory for changes made via hard links; if you want to do this then
5105 * you must register individual watches with g_file_monitor().
5107 * Virtual: monitor_dir
5108 * Returns: (transfer full): a #GFileMonitor for the given @file,
5109 * or %NULL on error.
5110 * Free the returned object with g_object_unref().
5113 g_file_monitor_directory (GFile *file,
5114 GFileMonitorFlags flags,
5115 GCancellable *cancellable,
5120 g_return_val_if_fail (G_IS_FILE (file), NULL);
5121 g_return_val_if_fail (~flags & G_FILE_MONITOR_WATCH_HARD_LINKS, NULL);
5123 if (g_cancellable_set_error_if_cancelled (cancellable, error))
5126 iface = G_FILE_GET_IFACE (file);
5128 if (iface->monitor_dir == NULL)
5130 g_set_error_literal (error, G_IO_ERROR,
5131 G_IO_ERROR_NOT_SUPPORTED,
5132 _("Operation not supported"));
5136 return (* iface->monitor_dir) (file, flags, cancellable, error);
5140 * g_file_monitor_file:
5141 * @file: input #GFile
5142 * @flags: a set of #GFileMonitorFlags
5143 * @cancellable: (allow-none): optional #GCancellable object,
5145 * @error: a #GError, or %NULL
5147 * Obtains a file monitor for the given file. If no file notification
5148 * mechanism exists, then regular polling of the file is used.
5150 * If @cancellable is not %NULL, then the operation can be cancelled by
5151 * triggering the cancellable object from another thread. If the operation
5152 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5154 * If @flags contains %G_FILE_MONITOR_WATCH_HARD_LINKS then the monitor
5155 * will also attempt to report changes made to the file via another
5156 * filename (ie, a hard link). Without this flag, you can only rely on
5157 * changes made through the filename contained in @file to be
5158 * reported. Using this flag may result in an increase in resource
5159 * usage, and may not have any effect depending on the #GFileMonitor
5160 * backend and/or filesystem type.
5162 * Returns: (transfer full): a #GFileMonitor for the given @file,
5163 * or %NULL on error.
5164 * Free the returned object with g_object_unref().
5167 g_file_monitor_file (GFile *file,
5168 GFileMonitorFlags flags,
5169 GCancellable *cancellable,
5173 GFileMonitor *monitor;
5175 g_return_val_if_fail (G_IS_FILE (file), NULL);
5177 if (g_cancellable_set_error_if_cancelled (cancellable, error))
5180 iface = G_FILE_GET_IFACE (file);
5184 if (iface->monitor_file)
5185 monitor = (* iface->monitor_file) (file, flags, cancellable, NULL);
5187 /* Fallback to polling */
5188 if (monitor == NULL)
5189 monitor = _g_poll_file_monitor_new (file);
5196 * @file: input #GFile
5197 * @flags: a set of #GFileMonitorFlags
5198 * @cancellable: (allow-none): optional #GCancellable object,
5200 * @error: a #GError, or %NULL
5202 * Obtains a file or directory monitor for the given file,
5203 * depending on the type of the file.
5205 * If @cancellable is not %NULL, then the operation can be cancelled by
5206 * triggering the cancellable object from another thread. If the operation
5207 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5209 * Returns: (transfer full): a #GFileMonitor for the given @file,
5210 * or %NULL on error.
5211 * Free the returned object with g_object_unref().
5216 g_file_monitor (GFile *file,
5217 GFileMonitorFlags flags,
5218 GCancellable *cancellable,
5221 if (g_file_query_file_type (file, 0, cancellable) == G_FILE_TYPE_DIRECTORY)
5222 return g_file_monitor_directory (file,
5223 flags & ~G_FILE_MONITOR_WATCH_HARD_LINKS,
5224 cancellable, error);
5226 return g_file_monitor_file (file, flags, cancellable, error);
5229 /********************************************
5230 * Default implementation of async ops *
5231 ********************************************/
5235 GFileQueryInfoFlags flags;
5236 } QueryInfoAsyncData;
5239 query_info_data_free (QueryInfoAsyncData *data)
5241 g_free (data->attributes);
5246 query_info_async_thread (GTask *task,
5249 GCancellable *cancellable)
5251 QueryInfoAsyncData *data = task_data;
5253 GError *error = NULL;
5255 info = g_file_query_info (G_FILE (object), data->attributes, data->flags, cancellable, &error);
5257 g_task_return_pointer (task, info, g_object_unref);
5259 g_task_return_error (task, error);
5263 g_file_real_query_info_async (GFile *file,
5264 const char *attributes,
5265 GFileQueryInfoFlags flags,
5267 GCancellable *cancellable,
5268 GAsyncReadyCallback callback,
5272 QueryInfoAsyncData *data;
5274 data = g_new0 (QueryInfoAsyncData, 1);
5275 data->attributes = g_strdup (attributes);
5276 data->flags = flags;
5278 task = g_task_new (file, cancellable, callback, user_data);
5279 g_task_set_task_data (task, data, (GDestroyNotify)query_info_data_free);
5280 g_task_set_priority (task, io_priority);
5281 g_task_run_in_thread (task, query_info_async_thread);
5282 g_object_unref (task);
5286 g_file_real_query_info_finish (GFile *file,
5290 g_return_val_if_fail (g_task_is_valid (res, file), NULL);
5292 return g_task_propagate_pointer (G_TASK (res), error);
5296 query_filesystem_info_async_thread (GTask *task,
5299 GCancellable *cancellable)
5301 const char *attributes = task_data;
5303 GError *error = NULL;
5305 info = g_file_query_filesystem_info (G_FILE (object), attributes, cancellable, &error);
5307 g_task_return_pointer (task, info, g_object_unref);
5309 g_task_return_error (task, error);
5313 g_file_real_query_filesystem_info_async (GFile *file,
5314 const char *attributes,
5316 GCancellable *cancellable,
5317 GAsyncReadyCallback callback,
5322 task = g_task_new (file, cancellable, callback, user_data);
5323 g_task_set_task_data (task, g_strdup (attributes), g_free);
5324 g_task_set_priority (task, io_priority);
5325 g_task_run_in_thread (task, query_filesystem_info_async_thread);
5326 g_object_unref (task);
5330 g_file_real_query_filesystem_info_finish (GFile *file,
5334 g_return_val_if_fail (g_task_is_valid (res, file), NULL);
5336 return g_task_propagate_pointer (G_TASK (res), error);
5340 enumerate_children_async_thread (GTask *task,
5343 GCancellable *cancellable)
5345 QueryInfoAsyncData *data = task_data;
5346 GFileEnumerator *enumerator;
5347 GError *error = NULL;
5349 enumerator = g_file_enumerate_children (G_FILE (object), data->attributes, data->flags, cancellable, &error);
5351 g_task_return_error (task, error);
5353 g_task_return_pointer (task, enumerator, g_object_unref);
5357 g_file_real_enumerate_children_async (GFile *file,
5358 const char *attributes,
5359 GFileQueryInfoFlags flags,
5361 GCancellable *cancellable,
5362 GAsyncReadyCallback callback,
5366 QueryInfoAsyncData *data;
5368 data = g_new0 (QueryInfoAsyncData, 1);
5369 data->attributes = g_strdup (attributes);
5370 data->flags = flags;
5372 task = g_task_new (file, cancellable, callback, user_data);
5373 g_task_set_task_data (task, data, (GDestroyNotify)query_info_data_free);
5374 g_task_set_priority (task, io_priority);
5375 g_task_run_in_thread (task, enumerate_children_async_thread);
5376 g_object_unref (task);
5379 static GFileEnumerator *
5380 g_file_real_enumerate_children_finish (GFile *file,
5384 g_return_val_if_fail (g_task_is_valid (res, file), NULL);
5386 return g_task_propagate_pointer (G_TASK (res), error);
5390 open_read_async_thread (GTask *task,
5393 GCancellable *cancellable)
5395 GFileInputStream *stream;
5396 GError *error = NULL;
5398 stream = g_file_read (G_FILE (object), cancellable, &error);
5400 g_task_return_pointer (task, stream, g_object_unref);
5402 g_task_return_error (task, error);
5406 g_file_real_read_async (GFile *file,
5408 GCancellable *cancellable,
5409 GAsyncReadyCallback callback,
5414 task = g_task_new (file, cancellable, callback, user_data);
5415 g_task_set_priority (task, io_priority);
5416 g_task_run_in_thread (task, open_read_async_thread);
5417 g_object_unref (task);
5420 static GFileInputStream *
5421 g_file_real_read_finish (GFile *file,
5425 g_return_val_if_fail (g_task_is_valid (res, file), NULL);
5427 return g_task_propagate_pointer (G_TASK (res), error);
5431 append_to_async_thread (GTask *task,
5432 gpointer source_object,
5434 GCancellable *cancellable)
5436 GFileCreateFlags *data = task_data;
5437 GFileOutputStream *stream;
5438 GError *error = NULL;
5440 stream = g_file_append_to (G_FILE (source_object), *data, cancellable, &error);
5442 g_task_return_pointer (task, stream, g_object_unref);
5444 g_task_return_error (task, error);
5448 g_file_real_append_to_async (GFile *file,
5449 GFileCreateFlags flags,
5451 GCancellable *cancellable,
5452 GAsyncReadyCallback callback,
5455 GFileCreateFlags *data;
5458 data = g_new0 (GFileCreateFlags, 1);
5461 task = g_task_new (file, cancellable, callback, user_data);
5462 g_task_set_task_data (task, data, g_free);
5463 g_task_set_priority (task, io_priority);
5465 g_task_run_in_thread (task, append_to_async_thread);
5466 g_object_unref (task);
5469 static GFileOutputStream *
5470 g_file_real_append_to_finish (GFile *file,
5474 g_return_val_if_fail (g_task_is_valid (res, file), NULL);
5476 return g_task_propagate_pointer (G_TASK (res), error);
5480 create_async_thread (GTask *task,
5481 gpointer source_object,
5483 GCancellable *cancellable)
5485 GFileCreateFlags *data = task_data;
5486 GFileOutputStream *stream;
5487 GError *error = NULL;
5489 stream = g_file_create (G_FILE (source_object), *data, cancellable, &error);
5491 g_task_return_pointer (task, stream, g_object_unref);
5493 g_task_return_error (task, error);
5497 g_file_real_create_async (GFile *file,
5498 GFileCreateFlags flags,
5500 GCancellable *cancellable,
5501 GAsyncReadyCallback callback,
5504 GFileCreateFlags *data;
5507 data = g_new0 (GFileCreateFlags, 1);
5510 task = g_task_new (file, cancellable, callback, user_data);
5511 g_task_set_task_data (task, data, g_free);
5512 g_task_set_priority (task, io_priority);
5514 g_task_run_in_thread (task, create_async_thread);
5515 g_object_unref (task);
5518 static GFileOutputStream *
5519 g_file_real_create_finish (GFile *file,
5523 g_return_val_if_fail (g_task_is_valid (res, file), NULL);
5525 return g_task_propagate_pointer (G_TASK (res), error);
5529 GFileOutputStream *stream;
5531 gboolean make_backup;
5532 GFileCreateFlags flags;
5536 replace_async_data_free (ReplaceAsyncData *data)
5539 g_object_unref (data->stream);
5540 g_free (data->etag);
5545 replace_async_thread (GTask *task,
5546 gpointer source_object,
5548 GCancellable *cancellable)
5550 GFileOutputStream *stream;
5551 ReplaceAsyncData *data = task_data;
5552 GError *error = NULL;
5554 stream = g_file_replace (G_FILE (source_object),
5562 g_task_return_pointer (task, stream, g_object_unref);
5564 g_task_return_error (task, error);
5568 g_file_real_replace_async (GFile *file,
5570 gboolean make_backup,
5571 GFileCreateFlags flags,
5573 GCancellable *cancellable,
5574 GAsyncReadyCallback callback,
5578 ReplaceAsyncData *data;
5580 data = g_new0 (ReplaceAsyncData, 1);
5581 data->etag = g_strdup (etag);
5582 data->make_backup = make_backup;
5583 data->flags = flags;
5585 task = g_task_new (file, cancellable, callback, user_data);
5586 g_task_set_task_data (task, data, (GDestroyNotify)replace_async_data_free);
5587 g_task_set_priority (task, io_priority);
5589 g_task_run_in_thread (task, replace_async_thread);
5590 g_object_unref (task);
5593 static GFileOutputStream *
5594 g_file_real_replace_finish (GFile *file,
5598 g_return_val_if_fail (g_task_is_valid (res, file), NULL);
5600 return g_task_propagate_pointer (G_TASK (res), error);
5604 delete_async_thread (GTask *task,
5607 GCancellable *cancellable)
5609 GError *error = NULL;
5611 if (g_file_delete (G_FILE (object), cancellable, &error))
5612 g_task_return_boolean (task, TRUE);
5614 g_task_return_error (task, error);
5618 g_file_real_delete_async (GFile *file,
5620 GCancellable *cancellable,
5621 GAsyncReadyCallback callback,
5626 task = g_task_new (file, cancellable, callback, user_data);
5627 g_task_set_priority (task, io_priority);
5628 g_task_run_in_thread (task, delete_async_thread);
5629 g_object_unref (task);
5633 g_file_real_delete_finish (GFile *file,
5637 g_return_val_if_fail (g_task_is_valid (res, file), FALSE);
5639 return g_task_propagate_boolean (G_TASK (res), error);
5643 trash_async_thread (GTask *task,
5646 GCancellable *cancellable)
5648 GError *error = NULL;
5650 if (g_file_trash (G_FILE (object), cancellable, &error))
5651 g_task_return_boolean (task, TRUE);
5653 g_task_return_error (task, error);
5657 g_file_real_trash_async (GFile *file,
5659 GCancellable *cancellable,
5660 GAsyncReadyCallback callback,
5665 task = g_task_new (file, cancellable, callback, user_data);
5666 g_task_set_priority (task, io_priority);
5667 g_task_run_in_thread (task, trash_async_thread);
5668 g_object_unref (task);
5672 g_file_real_trash_finish (GFile *file,
5676 g_return_val_if_fail (g_task_is_valid (res, file), FALSE);
5678 return g_task_propagate_boolean (G_TASK (res), error);
5682 make_directory_async_thread (GTask *task,
5685 GCancellable *cancellable)
5687 GError *error = NULL;
5689 if (g_file_make_directory (G_FILE (object), cancellable, &error))
5690 g_task_return_boolean (task, TRUE);
5692 g_task_return_error (task, error);
5696 g_file_real_make_directory_async (GFile *file,
5698 GCancellable *cancellable,
5699 GAsyncReadyCallback callback,
5704 task = g_task_new (file, cancellable, callback, user_data);
5705 g_task_set_priority (task, io_priority);
5706 g_task_run_in_thread (task, make_directory_async_thread);
5707 g_object_unref (task);
5711 g_file_real_make_directory_finish (GFile *file,
5715 g_return_val_if_fail (g_task_is_valid (res, file), FALSE);
5717 return g_task_propagate_boolean (G_TASK (res), error);
5721 open_readwrite_async_thread (GTask *task,
5724 GCancellable *cancellable)
5726 GFileIOStream *stream;
5727 GError *error = NULL;
5729 stream = g_file_open_readwrite (G_FILE (object), cancellable, &error);
5732 g_task_return_error (task, error);
5734 g_task_return_pointer (task, stream, g_object_unref);
5738 g_file_real_open_readwrite_async (GFile *file,
5740 GCancellable *cancellable,
5741 GAsyncReadyCallback callback,
5746 task = g_task_new (file, cancellable, callback, user_data);
5747 g_task_set_priority (task, io_priority);
5749 g_task_run_in_thread (task, open_readwrite_async_thread);
5750 g_object_unref (task);
5753 static GFileIOStream *
5754 g_file_real_open_readwrite_finish (GFile *file,
5758 g_return_val_if_fail (g_task_is_valid (res, file), NULL);
5760 return g_task_propagate_pointer (G_TASK (res), error);
5764 create_readwrite_async_thread (GTask *task,
5767 GCancellable *cancellable)
5769 GFileCreateFlags *data = task_data;
5770 GFileIOStream *stream;
5771 GError *error = NULL;
5773 stream = g_file_create_readwrite (G_FILE (object), *data, cancellable, &error);
5776 g_task_return_error (task, error);
5778 g_task_return_pointer (task, stream, g_object_unref);
5782 g_file_real_create_readwrite_async (GFile *file,
5783 GFileCreateFlags flags,
5785 GCancellable *cancellable,
5786 GAsyncReadyCallback callback,
5789 GFileCreateFlags *data;
5792 data = g_new0 (GFileCreateFlags, 1);
5795 task = g_task_new (file, cancellable, callback, user_data);
5796 g_task_set_task_data (task, data, g_free);
5797 g_task_set_priority (task, io_priority);
5799 g_task_run_in_thread (task, create_readwrite_async_thread);
5800 g_object_unref (task);
5803 static GFileIOStream *
5804 g_file_real_create_readwrite_finish (GFile *file,
5808 g_return_val_if_fail (g_task_is_valid (res, file), NULL);
5810 return g_task_propagate_pointer (G_TASK (res), error);
5815 gboolean make_backup;
5816 GFileCreateFlags flags;
5817 } ReplaceRWAsyncData;
5820 replace_rw_async_data_free (ReplaceRWAsyncData *data)
5822 g_free (data->etag);
5827 replace_readwrite_async_thread (GTask *task,
5830 GCancellable *cancellable)
5832 GFileIOStream *stream;
5833 GError *error = NULL;
5834 ReplaceRWAsyncData *data = task_data;
5836 stream = g_file_replace_readwrite (G_FILE (object),
5844 g_task_return_error (task, error);
5846 g_task_return_pointer (task, stream, g_object_unref);
5850 g_file_real_replace_readwrite_async (GFile *file,
5852 gboolean make_backup,
5853 GFileCreateFlags flags,
5855 GCancellable *cancellable,
5856 GAsyncReadyCallback callback,
5860 ReplaceRWAsyncData *data;
5862 data = g_new0 (ReplaceRWAsyncData, 1);
5863 data->etag = g_strdup (etag);
5864 data->make_backup = make_backup;
5865 data->flags = flags;
5867 task = g_task_new (file, cancellable, callback, user_data);
5868 g_task_set_task_data (task, data, (GDestroyNotify)replace_rw_async_data_free);
5869 g_task_set_priority (task, io_priority);
5871 g_task_run_in_thread (task, replace_readwrite_async_thread);
5872 g_object_unref (task);
5875 static GFileIOStream *
5876 g_file_real_replace_readwrite_finish (GFile *file,
5880 g_return_val_if_fail (g_task_is_valid (res, file), NULL);
5882 return g_task_propagate_pointer (G_TASK (res), error);
5886 set_display_name_async_thread (GTask *task,
5889 GCancellable *cancellable)
5891 GError *error = NULL;
5892 char *name = task_data;
5895 file = g_file_set_display_name (G_FILE (object), name, cancellable, &error);
5898 g_task_return_error (task, error);
5900 g_task_return_pointer (task, file, g_object_unref);
5904 g_file_real_set_display_name_async (GFile *file,
5905 const char *display_name,
5907 GCancellable *cancellable,
5908 GAsyncReadyCallback callback,
5913 task = g_task_new (file, cancellable, callback, user_data);
5914 g_task_set_task_data (task, g_strdup (display_name), g_free);
5915 g_task_set_priority (task, io_priority);
5917 g_task_run_in_thread (task, set_display_name_async_thread);
5918 g_object_unref (task);
5922 g_file_real_set_display_name_finish (GFile *file,
5926 g_return_val_if_fail (g_task_is_valid (res, file), NULL);
5928 return g_task_propagate_pointer (G_TASK (res), error);
5932 GFileQueryInfoFlags flags;
5939 set_info_data_free (SetInfoAsyncData *data)
5942 g_object_unref (data->info);
5944 g_error_free (data->error);
5949 set_info_async_thread (GTask *task,
5952 GCancellable *cancellable)
5954 SetInfoAsyncData *data = task_data;
5957 data->res = g_file_set_attributes_from_info (G_FILE (object),
5965 g_file_real_set_attributes_async (GFile *file,
5967 GFileQueryInfoFlags flags,
5969 GCancellable *cancellable,
5970 GAsyncReadyCallback callback,
5974 SetInfoAsyncData *data;
5976 data = g_new0 (SetInfoAsyncData, 1);
5977 data->info = g_file_info_dup (info);
5978 data->flags = flags;
5980 task = g_task_new (file, cancellable, callback, user_data);
5981 g_task_set_task_data (task, data, (GDestroyNotify)set_info_data_free);
5982 g_task_set_priority (task, io_priority);
5984 g_task_run_in_thread (task, set_info_async_thread);
5985 g_object_unref (task);
5989 g_file_real_set_attributes_finish (GFile *file,
5994 SetInfoAsyncData *data;
5996 g_return_val_if_fail (g_task_is_valid (res, file), FALSE);
5998 data = g_task_get_task_data (G_TASK (res));
6001 *info = g_object_ref (data->info);
6003 if (error != NULL && data->error)
6004 *error = g_error_copy (data->error);
6010 find_enclosing_mount_async_thread (GTask *task,
6013 GCancellable *cancellable)
6015 GError *error = NULL;
6018 mount = g_file_find_enclosing_mount (G_FILE (object), cancellable, &error);
6021 g_task_return_error (task, error);
6023 g_task_return_pointer (task, mount, g_object_unref);
6027 g_file_real_find_enclosing_mount_async (GFile *file,
6029 GCancellable *cancellable,
6030 GAsyncReadyCallback callback,
6035 task = g_task_new (file, cancellable, callback, user_data);
6036 g_task_set_priority (task, io_priority);
6038 g_task_run_in_thread (task, find_enclosing_mount_async_thread);
6039 g_object_unref (task);
6043 g_file_real_find_enclosing_mount_finish (GFile *file,
6047 g_return_val_if_fail (g_task_is_valid (res, file), NULL);
6049 return g_task_propagate_pointer (G_TASK (res), error);
6056 GFileCopyFlags flags;
6057 GFileProgressCallback progress_cb;
6058 gpointer progress_cb_data;
6062 copy_async_data_free (CopyAsyncData *data)
6064 g_object_unref (data->source);
6065 g_object_unref (data->destination);
6066 g_slice_free (CopyAsyncData, data);
6070 CopyAsyncData *data;
6071 goffset current_num_bytes;
6072 goffset total_num_bytes;
6076 copy_async_progress_in_main (gpointer user_data)
6078 ProgressData *progress = user_data;
6079 CopyAsyncData *data = progress->data;
6081 data->progress_cb (progress->current_num_bytes,
6082 progress->total_num_bytes,
6083 data->progress_cb_data);
6089 copy_async_progress_callback (goffset current_num_bytes,
6090 goffset total_num_bytes,
6093 GTask *task = user_data;
6094 CopyAsyncData *data = g_task_get_task_data (task);
6095 ProgressData *progress;
6097 progress = g_new (ProgressData, 1);
6098 progress->data = data;
6099 progress->current_num_bytes = current_num_bytes;
6100 progress->total_num_bytes = total_num_bytes;
6102 g_main_context_invoke_full (g_task_get_context (task),
6103 g_task_get_priority (task),
6104 copy_async_progress_in_main,
6110 copy_async_thread (GTask *task,
6113 GCancellable *cancellable)
6115 CopyAsyncData *data = task_data;
6117 GError *error = NULL;
6119 result = g_file_copy (data->source,
6123 (data->progress_cb != NULL) ? copy_async_progress_callback : NULL,
6127 g_task_return_boolean (task, TRUE);
6129 g_task_return_error (task, error);
6133 g_file_real_copy_async (GFile *source,
6135 GFileCopyFlags flags,
6137 GCancellable *cancellable,
6138 GFileProgressCallback progress_callback,
6139 gpointer progress_callback_data,
6140 GAsyncReadyCallback callback,
6144 CopyAsyncData *data;
6146 data = g_slice_new (CopyAsyncData);
6147 data->source = g_object_ref (source);
6148 data->destination = g_object_ref (destination);
6149 data->flags = flags;
6150 data->progress_cb = progress_callback;
6151 data->progress_cb_data = progress_callback_data;
6153 task = g_task_new (source, cancellable, callback, user_data);
6154 g_task_set_task_data (task, data, (GDestroyNotify)copy_async_data_free);
6155 g_task_set_priority (task, io_priority);
6156 g_task_run_in_thread (task, copy_async_thread);
6157 g_object_unref (task);
6161 g_file_real_copy_finish (GFile *file,
6165 g_return_val_if_fail (g_task_is_valid (res, file), FALSE);
6167 return g_task_propagate_boolean (G_TASK (res), error);
6171 /********************************************
6172 * Default VFS operations *
6173 ********************************************/
6176 * g_file_new_for_path:
6177 * @path: a string containing a relative or absolute path.
6178 * The string must be encoded in the glib filename encoding.
6180 * Constructs a #GFile for a given path. This operation never
6181 * fails, but the returned object might not support any I/O
6182 * operation if @path is malformed.
6184 * Returns: (transfer full): a new #GFile for the given @path.
6185 * Free the returned object with g_object_unref().
6188 g_file_new_for_path (const char *path)
6190 g_return_val_if_fail (path != NULL, NULL);
6192 return g_vfs_get_file_for_path (g_vfs_get_default (), path);
6196 * g_file_new_for_uri:
6197 * @uri: a UTF-8 string containing a URI
6199 * Constructs a #GFile for a given URI. This operation never
6200 * fails, but the returned object might not support any I/O
6201 * operation if @uri is malformed or if the uri type is
6204 * Returns: (transfer full): a new #GFile for the given @uri.
6205 * Free the returned object with g_object_unref().
6208 g_file_new_for_uri (const char *uri)
6210 g_return_val_if_fail (uri != NULL, NULL);
6212 return g_vfs_get_file_for_uri (g_vfs_get_default (), uri);
6217 * @tmpl: (type filename) (allow-none): Template for the file
6218 * name, as in g_file_open_tmp(), or %NULL for a default template
6219 * @iostream: (out): on return, a #GFileIOStream for the created file
6220 * @error: a #GError, or %NULL
6222 * Opens a file in the preferred directory for temporary files (as
6223 * returned by g_get_tmp_dir()) and returns a #GFile and
6224 * #GFileIOStream pointing to it.
6226 * @tmpl should be a string in the GLib file name encoding
6227 * containing a sequence of six 'X' characters, and containing no
6228 * directory components. If it is %NULL, a default template is used.
6230 * Unlike the other #GFile constructors, this will return %NULL if
6231 * a temporary file could not be created.
6233 * Returns: (transfer full): a new #GFile.
6234 * Free the returned object with g_object_unref().
6239 g_file_new_tmp (const char *tmpl,
6240 GFileIOStream **iostream,
6246 GFileOutputStream *output;
6248 g_return_val_if_fail (iostream != NULL, NULL);
6250 fd = g_file_open_tmp (tmpl, &path, error);
6254 file = g_file_new_for_path (path);
6256 output = _g_local_file_output_stream_new (fd);
6257 *iostream = _g_local_file_io_stream_new (G_LOCAL_FILE_OUTPUT_STREAM (output));
6259 g_object_unref (output);
6266 * g_file_parse_name:
6267 * @parse_name: a file name or path to be parsed
6269 * Constructs a #GFile with the given @parse_name (i.e. something
6270 * given by g_file_get_parse_name()). This operation never fails,
6271 * but the returned object might not support any I/O operation if
6272 * the @parse_name cannot be parsed.
6274 * Returns: (transfer full): a new #GFile.
6277 g_file_parse_name (const char *parse_name)
6279 g_return_val_if_fail (parse_name != NULL, NULL);
6281 return g_vfs_parse_name (g_vfs_get_default (), parse_name);
6285 is_valid_scheme_character (char c)
6287 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
6290 /* Following RFC 2396, valid schemes are built like:
6291 * scheme = alpha *( alpha | digit | "+" | "-" | "." )
6294 has_valid_scheme (const char *uri)
6300 if (!g_ascii_isalpha (*p))
6305 } while (is_valid_scheme_character (*p));
6311 new_for_cmdline_arg (const gchar *arg,
6317 if (g_path_is_absolute (arg))
6318 return g_file_new_for_path (arg);
6320 if (has_valid_scheme (arg))
6321 return g_file_new_for_uri (arg);
6327 current_dir = g_get_current_dir ();
6328 filename = g_build_filename (current_dir, arg, NULL);
6329 g_free (current_dir);
6332 filename = g_build_filename (cwd, arg, NULL);
6334 file = g_file_new_for_path (filename);
6341 * g_file_new_for_commandline_arg:
6342 * @arg: a command line string
6344 * Creates a #GFile with the given argument from the command line.
6345 * The value of @arg can be either a URI, an absolute path or a
6346 * relative path resolved relative to the current working directory.
6347 * This operation never fails, but the returned object might not
6348 * support any I/O operation if @arg points to a malformed path.
6350 * Returns: (transfer full): a new #GFile.
6351 * Free the returned object with g_object_unref().
6354 g_file_new_for_commandline_arg (const char *arg)
6356 g_return_val_if_fail (arg != NULL, NULL);
6358 return new_for_cmdline_arg (arg, NULL);
6362 * g_file_new_for_commandline_arg_and_cwd:
6363 * @arg: a command line string
6364 * @cwd: the current working directory of the commandline
6366 * Creates a #GFile with the given argument from the command line.
6368 * This function is similar to g_file_new_for_commandline_arg() except
6369 * that it allows for passing the current working directory as an
6370 * argument instead of using the current working directory of the
6373 * This is useful if the commandline argument was given in a context
6374 * other than the invocation of the current process.
6376 * See also g_application_command_line_create_file_for_arg().
6378 * Returns: (transfer full): a new #GFile
6383 g_file_new_for_commandline_arg_and_cwd (const gchar *arg,
6386 g_return_val_if_fail (arg != NULL, NULL);
6387 g_return_val_if_fail (cwd != NULL, NULL);
6389 return new_for_cmdline_arg (arg, cwd);
6393 * g_file_mount_enclosing_volume:
6394 * @location: input #GFile
6395 * @flags: flags affecting the operation
6396 * @mount_operation: (allow-none): a #GMountOperation
6397 * or %NULL to avoid user interaction
6398 * @cancellable: (allow-none): optional #GCancellable object,
6400 * @callback: (allow-none): a #GAsyncReadyCallback to call
6401 * when the request is satisfied, or %NULL
6402 * @user_data: the data to pass to callback function
6404 * Starts a @mount_operation, mounting the volume that contains
6405 * the file @location.
6407 * When this operation has completed, @callback will be called with
6408 * @user_user data, and the operation can be finalized with
6409 * g_file_mount_enclosing_volume_finish().
6411 * If @cancellable is not %NULL, then the operation can be cancelled by
6412 * triggering the cancellable object from another thread. If the operation
6413 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6416 g_file_mount_enclosing_volume (GFile *location,
6417 GMountMountFlags flags,
6418 GMountOperation *mount_operation,
6419 GCancellable *cancellable,
6420 GAsyncReadyCallback callback,
6425 g_return_if_fail (G_IS_FILE (location));
6427 iface = G_FILE_GET_IFACE (location);
6429 if (iface->mount_enclosing_volume == NULL)
6431 g_task_report_new_error (location, callback, user_data,
6432 g_file_mount_enclosing_volume,
6433 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
6434 _("volume doesn't implement mount"));
6438 (* iface->mount_enclosing_volume) (location, flags, mount_operation, cancellable, callback, user_data);
6443 * g_file_mount_enclosing_volume_finish:
6444 * @location: input #GFile
6445 * @result: a #GAsyncResult
6446 * @error: a #GError, or %NULL
6448 * Finishes a mount operation started by g_file_mount_enclosing_volume().
6450 * Returns: %TRUE if successful. If an error has occurred,
6451 * this function will return %FALSE and set @error
6452 * appropriately if present.
6455 g_file_mount_enclosing_volume_finish (GFile *location,
6456 GAsyncResult *result,
6461 g_return_val_if_fail (G_IS_FILE (location), FALSE);
6462 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
6464 if (g_async_result_legacy_propagate_error (result, error))
6466 else if (g_async_result_is_tagged (result, g_file_mount_enclosing_volume))
6467 return g_task_propagate_boolean (G_TASK (result), error);
6469 iface = G_FILE_GET_IFACE (location);
6471 return (* iface->mount_enclosing_volume_finish) (location, result, error);
6474 /********************************************
6475 * Utility functions *
6476 ********************************************/
6479 * g_file_query_default_handler:
6480 * @file: a #GFile to open
6481 * @cancellable: optional #GCancellable object, %NULL to ignore
6482 * @error: a #GError, or %NULL
6484 * Returns the #GAppInfo that is registered as the default
6485 * application to handle the file specified by @file.
6487 * If @cancellable is not %NULL, then the operation can be cancelled by
6488 * triggering the cancellable object from another thread. If the operation
6489 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6491 * Returns: (transfer full): a #GAppInfo if the handle was found,
6492 * %NULL if there were errors.
6493 * When you are done with it, release it with g_object_unref()
6496 g_file_query_default_handler (GFile *file,
6497 GCancellable *cancellable,
6501 const char *content_type;
6506 uri_scheme = g_file_get_uri_scheme (file);
6507 if (uri_scheme && uri_scheme[0] != '\0')
6509 appinfo = g_app_info_get_default_for_uri_scheme (uri_scheme);
6510 g_free (uri_scheme);
6512 if (appinfo != NULL)
6516 info = g_file_query_info (file,
6517 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
6526 content_type = g_file_info_get_content_type (info);
6529 /* Don't use is_native(), as we want to support fuse paths if available */
6530 path = g_file_get_path (file);
6531 appinfo = g_app_info_get_default_for_type (content_type,
6536 g_object_unref (info);
6538 if (appinfo != NULL)
6541 g_set_error_literal (error, G_IO_ERROR,
6542 G_IO_ERROR_NOT_SUPPORTED,
6543 _("No application is registered as handling this file"));
6547 #define GET_CONTENT_BLOCK_SIZE 8192
6550 * g_file_load_contents:
6551 * @file: input #GFile
6552 * @cancellable: optional #GCancellable object, %NULL to ignore
6553 * @contents: (out) (transfer full) (element-type guint8) (array length=length): a location to place the contents of the file
6554 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6555 * or %NULL if the length is not needed
6556 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6557 * or %NULL if the entity tag is not needed
6558 * @error: a #GError, or %NULL
6560 * Loads the content of the file into memory. The data is always
6561 * zero-terminated, but this is not included in the resultant @length.
6562 * The returned @content should be freed with g_free() when no longer
6565 * If @cancellable is not %NULL, then the operation can be cancelled by
6566 * triggering the cancellable object from another thread. If the operation
6567 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6569 * Returns: %TRUE if the @file's contents were successfully loaded.
6570 * %FALSE if there were errors.
6573 g_file_load_contents (GFile *file,
6574 GCancellable *cancellable,
6580 GFileInputStream *in;
6581 GByteArray *content;
6586 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6587 g_return_val_if_fail (contents != NULL, FALSE);
6589 in = g_file_read (file, cancellable, error);
6593 content = g_byte_array_new ();
6596 g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
6597 while ((res = g_input_stream_read (G_INPUT_STREAM (in),
6598 content->data + pos,
6599 GET_CONTENT_BLOCK_SIZE,
6600 cancellable, error)) > 0)
6603 g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
6610 info = g_file_input_stream_query_info (in,
6611 G_FILE_ATTRIBUTE_ETAG_VALUE,
6616 *etag_out = g_strdup (g_file_info_get_etag (info));
6617 g_object_unref (info);
6621 /* Ignore errors on close */
6622 g_input_stream_close (G_INPUT_STREAM (in), cancellable, NULL);
6623 g_object_unref (in);
6627 /* error is set already */
6628 g_byte_array_free (content, TRUE);
6635 /* Zero terminate (we got an extra byte allocated for this */
6636 content->data[pos] = 0;
6638 *contents = (char *)g_byte_array_free (content, FALSE);
6645 GFileReadMoreCallback read_more_callback;
6646 GByteArray *content;
6653 load_contents_data_free (LoadContentsData *data)
6656 g_byte_array_free (data->content, TRUE);
6657 g_free (data->etag);
6662 load_contents_close_callback (GObject *obj,
6663 GAsyncResult *close_res,
6666 GInputStream *stream = G_INPUT_STREAM (obj);
6667 LoadContentsData *data = user_data;
6669 /* Ignore errors here, we're only reading anyway */
6670 g_input_stream_close_finish (stream, close_res, NULL);
6671 g_object_unref (stream);
6673 g_task_return_boolean (data->task, TRUE);
6674 g_object_unref (data->task);
6678 load_contents_fstat_callback (GObject *obj,
6679 GAsyncResult *stat_res,
6682 GInputStream *stream = G_INPUT_STREAM (obj);
6683 LoadContentsData *data = user_data;
6686 info = g_file_input_stream_query_info_finish (G_FILE_INPUT_STREAM (stream),
6690 data->etag = g_strdup (g_file_info_get_etag (info));
6691 g_object_unref (info);
6694 g_input_stream_close_async (stream, 0,
6695 g_task_get_cancellable (data->task),
6696 load_contents_close_callback, data);
6700 load_contents_read_callback (GObject *obj,
6701 GAsyncResult *read_res,
6704 GInputStream *stream = G_INPUT_STREAM (obj);
6705 LoadContentsData *data = user_data;
6706 GError *error = NULL;
6709 read_size = g_input_stream_read_finish (stream, read_res, &error);
6713 g_task_return_error (data->task, error);
6714 g_object_unref (data->task);
6716 /* Close the file ignoring any error */
6717 g_input_stream_close_async (stream, 0, NULL, NULL, NULL);
6718 g_object_unref (stream);
6720 else if (read_size == 0)
6722 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
6723 G_FILE_ATTRIBUTE_ETAG_VALUE,
6725 g_task_get_cancellable (data->task),
6726 load_contents_fstat_callback,
6729 else if (read_size > 0)
6731 data->pos += read_size;
6733 g_byte_array_set_size (data->content,
6734 data->pos + GET_CONTENT_BLOCK_SIZE);
6737 if (data->read_more_callback &&
6738 !data->read_more_callback ((char *)data->content->data, data->pos,
6739 g_async_result_get_user_data (G_ASYNC_RESULT (data->task))))
6740 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
6741 G_FILE_ATTRIBUTE_ETAG_VALUE,
6743 g_task_get_cancellable (data->task),
6744 load_contents_fstat_callback,
6747 g_input_stream_read_async (stream,
6748 data->content->data + data->pos,
6749 GET_CONTENT_BLOCK_SIZE,
6751 g_task_get_cancellable (data->task),
6752 load_contents_read_callback,
6758 load_contents_open_callback (GObject *obj,
6759 GAsyncResult *open_res,
6762 GFile *file = G_FILE (obj);
6763 GFileInputStream *stream;
6764 LoadContentsData *data = user_data;
6765 GError *error = NULL;
6767 stream = g_file_read_finish (file, open_res, &error);
6771 g_byte_array_set_size (data->content,
6772 data->pos + GET_CONTENT_BLOCK_SIZE);
6773 g_input_stream_read_async (G_INPUT_STREAM (stream),
6774 data->content->data + data->pos,
6775 GET_CONTENT_BLOCK_SIZE,
6777 g_task_get_cancellable (data->task),
6778 load_contents_read_callback,
6783 g_task_return_error (data->task, error);
6784 g_object_unref (data->task);
6789 * g_file_load_partial_contents_async: (skip)
6790 * @file: input #GFile
6791 * @cancellable: optional #GCancellable object, %NULL to ignore
6792 * @read_more_callback: a #GFileReadMoreCallback to receive partial data
6793 * and to specify whether further data should be read
6794 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6795 * @user_data: the data to pass to the callback functions
6797 * Reads the partial contents of a file. A #GFileReadMoreCallback should
6798 * be used to stop reading from the file when appropriate, else this
6799 * function will behave exactly as g_file_load_contents_async(). This
6800 * operation can be finished by g_file_load_partial_contents_finish().
6802 * Users of this function should be aware that @user_data is passed to
6803 * both the @read_more_callback and the @callback.
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.
6810 g_file_load_partial_contents_async (GFile *file,
6811 GCancellable *cancellable,
6812 GFileReadMoreCallback read_more_callback,
6813 GAsyncReadyCallback callback,
6816 LoadContentsData *data;
6818 g_return_if_fail (G_IS_FILE (file));
6820 data = g_new0 (LoadContentsData, 1);
6821 data->read_more_callback = read_more_callback;
6822 data->content = g_byte_array_new ();
6824 data->task = g_task_new (file, cancellable, callback, user_data);
6825 g_task_set_task_data (data->task, data, (GDestroyNotify)load_contents_data_free);
6827 g_file_read_async (file,
6829 g_task_get_cancellable (data->task),
6830 load_contents_open_callback,
6835 * g_file_load_partial_contents_finish:
6836 * @file: input #GFile
6837 * @res: a #GAsyncResult
6838 * @contents: (out) (transfer full) (element-type guint8) (array length=length): a location to place the contents of the file
6839 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6840 * or %NULL if the length is not needed
6841 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6842 * or %NULL if the entity tag is not needed
6843 * @error: a #GError, or %NULL
6845 * Finishes an asynchronous partial load operation that was started
6846 * with g_file_load_partial_contents_async(). The data is always
6847 * zero-terminated, but this is not included in the resultant @length.
6848 * The returned @content should be freed with g_free() when no longer
6851 * Returns: %TRUE if the load was successful. If %FALSE and @error is
6852 * present, it will be set appropriately.
6855 g_file_load_partial_contents_finish (GFile *file,
6863 LoadContentsData *data;
6865 g_return_val_if_fail (G_IS_FILE (file), FALSE);
6866 g_return_val_if_fail (g_task_is_valid (res, file), FALSE);
6867 g_return_val_if_fail (contents != NULL, FALSE);
6869 task = G_TASK (res);
6871 if (!g_task_propagate_boolean (task, error))
6878 data = g_task_get_task_data (task);
6881 *length = data->pos;
6885 *etag_out = data->etag;
6889 /* Zero terminate */
6890 g_byte_array_set_size (data->content, data->pos + 1);
6891 data->content->data[data->pos] = 0;
6893 *contents = (char *)g_byte_array_free (data->content, FALSE);
6894 data->content = NULL;
6900 * g_file_load_contents_async:
6901 * @file: input #GFile
6902 * @cancellable: optional #GCancellable object, %NULL to ignore
6903 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6904 * @user_data: the data to pass to callback function
6906 * Starts an asynchronous load of the @file's contents.
6908 * For more details, see g_file_load_contents() which is
6909 * the synchronous version of this call.
6911 * When the load operation has completed, @callback will be called
6912 * with @user data. To finish the operation, call
6913 * g_file_load_contents_finish() with the #GAsyncResult returned by
6916 * If @cancellable is not %NULL, then the operation can be cancelled by
6917 * triggering the cancellable object from another thread. If the operation
6918 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6921 g_file_load_contents_async (GFile *file,
6922 GCancellable *cancellable,
6923 GAsyncReadyCallback callback,
6926 g_file_load_partial_contents_async (file,
6929 callback, user_data);
6933 * g_file_load_contents_finish:
6934 * @file: input #GFile
6935 * @res: a #GAsyncResult
6936 * @contents: (out) (transfer full) (element-type guint8) (array length=length): a location to place the contents of the file
6937 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6938 * or %NULL if the length is not needed
6939 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6940 * or %NULL if the entity tag is not needed
6941 * @error: a #GError, or %NULL
6943 * Finishes an asynchronous load of the @file's contents.
6944 * The contents are placed in @contents, and @length is set to the
6945 * size of the @contents string. The @content should be freed with
6946 * g_free() when no longer needed. If @etag_out is present, it will be
6947 * set to the new entity tag for the @file.
6949 * Returns: %TRUE if the load was successful. If %FALSE and @error is
6950 * present, it will be set appropriately.
6953 g_file_load_contents_finish (GFile *file,
6960 return g_file_load_partial_contents_finish (file,
6969 * g_file_replace_contents:
6970 * @file: input #GFile
6971 * @contents: (element-type guint8) (array length=length): a string containing the new contents for @file
6972 * @length: the length of @contents in bytes
6973 * @etag: (allow-none): the old <link linkend="gfile-etag">entity tag</link>
6974 * for the document, or %NULL
6975 * @make_backup: %TRUE if a backup should be created
6976 * @flags: a set of #GFileCreateFlags
6977 * @new_etag: (allow-none) (out): a location to a new <link linkend="gfile-etag">entity tag</link>
6978 * for the document. This should be freed with g_free() when no longer
6980 * @cancellable: optional #GCancellable object, %NULL to ignore
6981 * @error: a #GError, or %NULL
6983 * Replaces the contents of @file with @contents of @length bytes.
6985 * If @etag is specified (not %NULL), any existing file must have that etag,
6986 * or the error %G_IO_ERROR_WRONG_ETAG will be returned.
6988 * If @make_backup is %TRUE, this function will attempt to make a backup
6991 * If @cancellable is not %NULL, then the operation can be cancelled by
6992 * triggering the cancellable object from another thread. If the operation
6993 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6995 * The returned @new_etag can be used to verify that the file hasn't
6996 * changed the next time it is saved over.
6998 * Returns: %TRUE if successful. If an error has occurred, this function
6999 * will return %FALSE and set @error appropriately if present.
7002 g_file_replace_contents (GFile *file,
7003 const char *contents,
7006 gboolean make_backup,
7007 GFileCreateFlags flags,
7009 GCancellable *cancellable,
7012 GFileOutputStream *out;
7013 gsize pos, remainder;
7017 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7018 g_return_val_if_fail (contents != NULL, FALSE);
7020 out = g_file_replace (file, etag, make_backup, flags, cancellable, error);
7026 while (remainder > 0 &&
7027 (res = g_output_stream_write (G_OUTPUT_STREAM (out),
7029 MIN (remainder, GET_CONTENT_BLOCK_SIZE),
7037 if (remainder > 0 && res < 0)
7039 /* Ignore errors on close */
7040 g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, NULL);
7041 g_object_unref (out);
7043 /* error is set already */
7047 ret = g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, error);
7050 *new_etag = g_file_output_stream_get_etag (out);
7052 g_object_unref (out);
7059 const char *content;
7064 } ReplaceContentsData;
7067 replace_contents_data_free (ReplaceContentsData *data)
7069 g_free (data->etag);
7074 replace_contents_close_callback (GObject *obj,
7075 GAsyncResult *close_res,
7078 GOutputStream *stream = G_OUTPUT_STREAM (obj);
7079 ReplaceContentsData *data = user_data;
7081 /* Ignore errors here, we're only reading anyway */
7082 g_output_stream_close_finish (stream, close_res, NULL);
7083 g_object_unref (stream);
7087 data->etag = g_file_output_stream_get_etag (G_FILE_OUTPUT_STREAM (stream));
7088 g_task_return_boolean (data->task, TRUE);
7090 g_object_unref (data->task);
7094 replace_contents_write_callback (GObject *obj,
7095 GAsyncResult *read_res,
7098 GOutputStream *stream = G_OUTPUT_STREAM (obj);
7099 ReplaceContentsData *data = user_data;
7100 GError *error = NULL;
7103 write_size = g_output_stream_write_finish (stream, read_res, &error);
7105 if (write_size <= 0)
7107 /* Error or EOF, close the file */
7110 data->failed = TRUE;
7111 g_task_return_error (data->task, error);
7113 g_output_stream_close_async (stream, 0,
7114 g_task_get_cancellable (data->task),
7115 replace_contents_close_callback, data);
7117 else if (write_size > 0)
7119 data->pos += write_size;
7121 if (data->pos >= data->length)
7122 g_output_stream_close_async (stream, 0,
7123 g_task_get_cancellable (data->task),
7124 replace_contents_close_callback, data);
7126 g_output_stream_write_async (stream,
7127 data->content + data->pos,
7128 data->length - data->pos,
7130 g_task_get_cancellable (data->task),
7131 replace_contents_write_callback,
7137 replace_contents_open_callback (GObject *obj,
7138 GAsyncResult *open_res,
7141 GFile *file = G_FILE (obj);
7142 GFileOutputStream *stream;
7143 ReplaceContentsData *data = user_data;
7144 GError *error = NULL;
7146 stream = g_file_replace_finish (file, open_res, &error);
7150 g_output_stream_write_async (G_OUTPUT_STREAM (stream),
7151 data->content + data->pos,
7152 data->length - data->pos,
7154 g_task_get_cancellable (data->task),
7155 replace_contents_write_callback,
7160 g_task_return_error (data->task, error);
7161 g_object_unref (data->task);
7166 * g_file_replace_contents_async:
7167 * @file: input #GFile
7168 * @contents: (element-type guint8) (array length=length): string of contents to replace the file with
7169 * @length: the length of @contents in bytes
7170 * @etag: (allow-none): a new <link linkend="gfile-etag">entity tag</link> for the @file, or %NULL
7171 * @make_backup: %TRUE if a backup should be created
7172 * @flags: a set of #GFileCreateFlags
7173 * @cancellable: optional #GCancellable object, %NULL to ignore
7174 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
7175 * @user_data: the data to pass to callback function
7177 * Starts an asynchronous replacement of @file with the given
7178 * @contents of @length bytes. @etag will replace the document's
7179 * current entity tag.
7181 * When this operation has completed, @callback will be called with
7182 * @user_user data, and the operation can be finalized with
7183 * g_file_replace_contents_finish().
7185 * If @cancellable is not %NULL, then the operation can be cancelled by
7186 * triggering the cancellable object from another thread. If the operation
7187 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7189 * If @make_backup is %TRUE, this function will attempt to
7190 * make a backup of @file.
7193 g_file_replace_contents_async (GFile *file,
7194 const char *contents,
7197 gboolean make_backup,
7198 GFileCreateFlags flags,
7199 GCancellable *cancellable,
7200 GAsyncReadyCallback callback,
7203 ReplaceContentsData *data;
7205 g_return_if_fail (G_IS_FILE (file));
7206 g_return_if_fail (contents != NULL);
7208 data = g_new0 (ReplaceContentsData, 1);
7210 data->content = contents;
7211 data->length = length;
7213 data->task = g_task_new (file, cancellable, callback, user_data);
7214 g_task_set_task_data (data->task, data, (GDestroyNotify)replace_contents_data_free);
7216 g_file_replace_async (file,
7221 g_task_get_cancellable (data->task),
7222 replace_contents_open_callback,
7227 * g_file_replace_contents_finish:
7228 * @file: input #GFile
7229 * @res: a #GAsyncResult
7230 * @new_etag: (out) (allow-none): a location of a new <link linkend="gfile-etag">entity tag</link>
7231 * for the document. This should be freed with g_free() when it is no
7232 * longer needed, or %NULL
7233 * @error: a #GError, or %NULL
7235 * Finishes an asynchronous replace of the given @file. See
7236 * g_file_replace_contents_async(). Sets @new_etag to the new entity
7237 * tag for the document, if present.
7239 * Returns: %TRUE on success, %FALSE on failure.
7242 g_file_replace_contents_finish (GFile *file,
7248 ReplaceContentsData *data;
7250 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7251 g_return_val_if_fail (g_task_is_valid (res, file), FALSE);
7253 task = G_TASK (res);
7255 if (!g_task_propagate_boolean (task, error))
7258 data = g_task_get_task_data (task);
7262 *new_etag = data->etag;
7263 data->etag = NULL; /* Take ownership */
7270 * g_file_start_mountable:
7271 * @file: input #GFile
7272 * @flags: flags affecting the operation
7273 * @start_operation: (allow-none): a #GMountOperation, or %NULL to avoid user interaction
7274 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
7275 * @callback: (allow-none): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL
7276 * @user_data: the data to pass to callback function
7278 * Starts a file of type #G_FILE_TYPE_MOUNTABLE.
7279 * Using @start_operation, you can request callbacks when, for instance,
7280 * passwords are needed during authentication.
7282 * If @cancellable is not %NULL, then the operation can be cancelled by
7283 * triggering the cancellable object from another thread. If the operation
7284 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7286 * When the operation is finished, @callback will be called.
7287 * You can then call g_file_mount_mountable_finish() to get
7288 * the result of the operation.
7293 g_file_start_mountable (GFile *file,
7294 GDriveStartFlags flags,
7295 GMountOperation *start_operation,
7296 GCancellable *cancellable,
7297 GAsyncReadyCallback callback,
7302 g_return_if_fail (G_IS_FILE (file));
7304 iface = G_FILE_GET_IFACE (file);
7306 if (iface->start_mountable == NULL)
7308 g_task_report_new_error (file, callback, user_data,
7309 g_file_start_mountable,
7310 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
7311 _("Operation not supported"));
7315 (* iface->start_mountable) (file,
7324 * g_file_start_mountable_finish:
7325 * @file: input #GFile
7326 * @result: a #GAsyncResult
7327 * @error: a #GError, or %NULL
7329 * Finishes a start operation. See g_file_start_mountable() for details.
7331 * Finish an asynchronous start operation that was started
7332 * with g_file_start_mountable().
7334 * Returns: %TRUE if the operation finished successfully. %FALSE
7340 g_file_start_mountable_finish (GFile *file,
7341 GAsyncResult *result,
7346 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7347 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7349 if (g_async_result_legacy_propagate_error (result, error))
7351 else if (g_async_result_is_tagged (result, g_file_start_mountable))
7352 return g_task_propagate_boolean (G_TASK (result), error);
7354 iface = G_FILE_GET_IFACE (file);
7355 return (* iface->start_mountable_finish) (file, result, error);
7359 * g_file_stop_mountable:
7360 * @file: input #GFile
7361 * @flags: flags affecting the operation
7362 * @mount_operation: (allow-none): a #GMountOperation,
7363 * or %NULL to avoid user interaction.
7364 * @cancellable: (allow-none): optional #GCancellable object,
7366 * @callback: (allow-none): a #GAsyncReadyCallback to call
7367 * when the request is satisfied, or %NULL
7368 * @user_data: the data to pass to callback function
7370 * Stops a file of type #G_FILE_TYPE_MOUNTABLE.
7372 * If @cancellable is not %NULL, then the operation can be cancelled by
7373 * triggering the cancellable object from another thread. If the operation
7374 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7376 * When the operation is finished, @callback will be called.
7377 * You can then call g_file_stop_mountable_finish() to get
7378 * the result of the operation.
7383 g_file_stop_mountable (GFile *file,
7384 GMountUnmountFlags flags,
7385 GMountOperation *mount_operation,
7386 GCancellable *cancellable,
7387 GAsyncReadyCallback callback,
7392 g_return_if_fail (G_IS_FILE (file));
7394 iface = G_FILE_GET_IFACE (file);
7396 if (iface->stop_mountable == NULL)
7398 g_task_report_new_error (file, callback, user_data,
7399 g_file_stop_mountable,
7400 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
7401 _("Operation not supported"));
7405 (* iface->stop_mountable) (file,
7414 * g_file_stop_mountable_finish:
7415 * @file: input #GFile
7416 * @result: a #GAsyncResult
7417 * @error: a #GError, or %NULL
7419 * Finishes an stop operation, see g_file_stop_mountable() for details.
7421 * Finish an asynchronous stop operation that was started
7422 * with g_file_stop_mountable().
7424 * Returns: %TRUE if the operation finished successfully.
7430 g_file_stop_mountable_finish (GFile *file,
7431 GAsyncResult *result,
7436 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7437 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7439 if (g_async_result_legacy_propagate_error (result, error))
7441 else if (g_async_result_is_tagged (result, g_file_stop_mountable))
7442 return g_task_propagate_boolean (G_TASK (result), error);
7444 iface = G_FILE_GET_IFACE (file);
7445 return (* iface->stop_mountable_finish) (file, result, error);
7449 * g_file_poll_mountable:
7450 * @file: input #GFile
7451 * @cancellable: optional #GCancellable object, %NULL to ignore
7452 * @callback: (allow-none): a #GAsyncReadyCallback to call
7453 * when the request is satisfied, or %NULL
7454 * @user_data: the data to pass to callback function
7456 * Polls a file of type #G_FILE_TYPE_MOUNTABLE.
7458 * If @cancellable is not %NULL, then the operation can be cancelled by
7459 * triggering the cancellable object from another thread. If the operation
7460 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7462 * When the operation is finished, @callback will be called.
7463 * You can then call g_file_mount_mountable_finish() to get
7464 * the result of the operation.
7469 g_file_poll_mountable (GFile *file,
7470 GCancellable *cancellable,
7471 GAsyncReadyCallback callback,
7476 g_return_if_fail (G_IS_FILE (file));
7478 iface = G_FILE_GET_IFACE (file);
7480 if (iface->poll_mountable == NULL)
7482 g_task_report_new_error (file, callback, user_data,
7483 g_file_poll_mountable,
7484 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
7485 _("Operation not supported"));
7489 (* iface->poll_mountable) (file,
7496 * g_file_poll_mountable_finish:
7497 * @file: input #GFile
7498 * @result: a #GAsyncResult
7499 * @error: a #GError, or %NULL
7501 * Finishes a poll operation. See g_file_poll_mountable() for details.
7503 * Finish an asynchronous poll operation that was polled
7504 * with g_file_poll_mountable().
7506 * Returns: %TRUE if the operation finished successfully. %FALSE
7512 g_file_poll_mountable_finish (GFile *file,
7513 GAsyncResult *result,
7518 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7519 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
7521 if (g_async_result_legacy_propagate_error (result, error))
7523 else if (g_async_result_is_tagged (result, g_file_poll_mountable))
7524 return g_task_propagate_boolean (G_TASK (result), error);
7526 iface = G_FILE_GET_IFACE (file);
7527 return (* iface->poll_mountable_finish) (file, result, error);
7531 * g_file_supports_thread_contexts:
7534 * Checks if @file supports <link
7535 * linkend="g-main-context-push-thread-default-context">thread-default
7536 * contexts</link>. If this returns %FALSE, you cannot perform
7537 * asynchronous operations on @file in a thread that has a
7538 * thread-default context.
7540 * Returns: Whether or not @file supports thread-default contexts.
7545 g_file_supports_thread_contexts (GFile *file)
7549 g_return_val_if_fail (G_IS_FILE (file), FALSE);
7551 iface = G_FILE_GET_IFACE (file);
7552 return iface->supports_thread_contexts;