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, see <http://www.gnu.org/licenses/>.
20 * Author: Alexander Larsson <alexl@redhat.com>
26 #include <sys/ioctl.h>
28 /* See linux.git/fs/btrfs/ioctl.h */
29 #define BTRFS_IOCTL_MAGIC 0x94
30 #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
41 #include <sys/types.h>
44 #include "glib/gstdio.h"
46 #include "glib-unix.h"
50 #include "gfileattribute-priv.h"
51 #include "gfiledescriptorbased.h"
52 #include "gpollfilemonitor.h"
54 #include "gfileinputstream.h"
55 #include "gfileoutputstream.h"
56 #include "glocalfileoutputstream.h"
57 #include "glocalfileiostream.h"
58 #include "glocalfile.h"
59 #include "gcancellable.h"
60 #include "gasyncresult.h"
67 * @short_description: File and Directory Handling
69 * @see_also: #GFileInfo, #GFileEnumerator
71 * #GFile is a high level abstraction for manipulating files on a
72 * virtual file system. #GFiles are lightweight, immutable objects
73 * that do no I/O upon creation. It is necessary to understand that
74 * #GFile objects do not represent files, merely an identifier for a
75 * file. All file content I/O is implemented as streaming operations
76 * (see #GInputStream and #GOutputStream).
78 * To construct a #GFile, you can use:
79 * - g_file_new_for_path() if you have a path.
80 * - g_file_new_for_uri() if you have a URI.
81 * - g_file_new_for_commandline_arg() for a command line argument.
82 * - g_file_new_tmp() to create a temporary file from a template.
83 * - g_file_parse_name() from a UTF-8 string gotten from g_file_get_parse_name().
85 * One way to think of a #GFile is as an abstraction of a pathname. For
86 * normal files the system pathname is what is stored internally, but as
87 * #GFiles are extensible it could also be something else that corresponds
88 * to a pathname in a userspace implementation of a filesystem.
90 * #GFiles make up hierarchies of directories and files that correspond to
91 * the files on a filesystem. You can move through the file system with
92 * #GFile using g_file_get_parent() to get an identifier for the parent
93 * directory, g_file_get_child() to get a child within a directory,
94 * g_file_resolve_relative_path() to resolve a relative path between two
95 * #GFiles. There can be multiple hierarchies, so you may not end up at
96 * the same root if you repeatedly call g_file_get_parent() on two different
99 * All #GFiles have a basename (get with g_file_get_basename()). These names
100 * are byte strings that are used to identify the file on the filesystem
101 * (relative to its parent directory) and there is no guarantees that they
102 * have any particular charset encoding or even make any sense at all. If
103 * you want to use filenames in a user interface you should use the display
104 * name that you can get by requesting the
105 * %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info().
106 * This is guaranteed to be in UTF-8 and can be used in a user interface.
107 * But always store the real basename or the #GFile to use to actually
108 * access the file, because there is no way to go from a display name to
111 * Using #GFile as an identifier has the same weaknesses as using a path
112 * in that there may be multiple aliases for the same file. For instance,
113 * hard or soft links may cause two different #GFiles to refer to the same
114 * file. Other possible causes for aliases are: case insensitive filesystems,
115 * short and long names on FAT/NTFS, or bind mounts in Linux. If you want to
116 * check if two #GFiles point to the same file you can query for the
117 * %G_FILE_ATTRIBUTE_ID_FILE attribute. Note that #GFile does some trivial
118 * canonicalization of pathnames passed in, so that trivial differences in
119 * the path string used at creation (duplicated slashes, slash at end of
120 * path, "." or ".." path segments, etc) does not create different #GFiles.
122 * Many #GFile operations have both synchronous and asynchronous versions
123 * to suit your application. Asynchronous versions of synchronous functions
124 * simply have _async() appended to their function names. The asynchronous
125 * I/O functions call a #GAsyncReadyCallback which is then used to finalize
126 * the operation, producing a GAsyncResult which is then passed to the
127 * function's matching _finish() operation.
129 * Some #GFile operations do not have synchronous analogs, as they may
130 * take a very long time to finish, and blocking may leave an application
131 * unusable. Notable cases include:
132 * - g_file_mount_mountable() to mount a mountable file.
133 * - g_file_unmount_mountable_with_operation() to unmount a mountable file.
134 * - g_file_eject_mountable_with_operation() to eject a mountable file.
136 * ## Entity Tags # {#gfile-etag}
138 * One notable feature of #GFiles are entity tags, or "etags" for
139 * short. Entity tags are somewhat like a more abstract version of the
140 * traditional mtime, and can be used to quickly determine if the file
141 * has been modified from the version on the file system. See the
143 * [specification](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)
144 * for HTTP Etag headers, which are a very similar concept.
147 static void g_file_real_query_info_async (GFile
*file
,
148 const char *attributes
,
149 GFileQueryInfoFlags flags
,
151 GCancellable
*cancellable
,
152 GAsyncReadyCallback callback
,
154 static GFileInfo
* g_file_real_query_info_finish (GFile
*file
,
157 static void g_file_real_query_filesystem_info_async (GFile
*file
,
158 const char *attributes
,
160 GCancellable
*cancellable
,
161 GAsyncReadyCallback callback
,
163 static GFileInfo
* g_file_real_query_filesystem_info_finish (GFile
*file
,
166 static void g_file_real_enumerate_children_async (GFile
*file
,
167 const char *attributes
,
168 GFileQueryInfoFlags flags
,
170 GCancellable
*cancellable
,
171 GAsyncReadyCallback callback
,
173 static GFileEnumerator
* g_file_real_enumerate_children_finish (GFile
*file
,
176 static void g_file_real_read_async (GFile
*file
,
178 GCancellable
*cancellable
,
179 GAsyncReadyCallback callback
,
181 static GFileInputStream
* g_file_real_read_finish (GFile
*file
,
184 static void g_file_real_append_to_async (GFile
*file
,
185 GFileCreateFlags flags
,
187 GCancellable
*cancellable
,
188 GAsyncReadyCallback callback
,
190 static GFileOutputStream
*g_file_real_append_to_finish (GFile
*file
,
193 static void g_file_real_create_async (GFile
*file
,
194 GFileCreateFlags flags
,
196 GCancellable
*cancellable
,
197 GAsyncReadyCallback callback
,
199 static GFileOutputStream
*g_file_real_create_finish (GFile
*file
,
202 static void g_file_real_replace_async (GFile
*file
,
204 gboolean make_backup
,
205 GFileCreateFlags flags
,
207 GCancellable
*cancellable
,
208 GAsyncReadyCallback callback
,
210 static GFileOutputStream
*g_file_real_replace_finish (GFile
*file
,
213 static void g_file_real_delete_async (GFile
*file
,
215 GCancellable
*cancellable
,
216 GAsyncReadyCallback callback
,
218 static gboolean
g_file_real_delete_finish (GFile
*file
,
221 static void g_file_real_trash_async (GFile
*file
,
223 GCancellable
*cancellable
,
224 GAsyncReadyCallback callback
,
226 static gboolean
g_file_real_trash_finish (GFile
*file
,
229 static void g_file_real_make_directory_async (GFile
*file
,
231 GCancellable
*cancellable
,
232 GAsyncReadyCallback callback
,
234 static gboolean
g_file_real_make_directory_finish (GFile
*file
,
237 static void g_file_real_open_readwrite_async (GFile
*file
,
239 GCancellable
*cancellable
,
240 GAsyncReadyCallback callback
,
242 static GFileIOStream
* g_file_real_open_readwrite_finish (GFile
*file
,
245 static void g_file_real_create_readwrite_async (GFile
*file
,
246 GFileCreateFlags flags
,
248 GCancellable
*cancellable
,
249 GAsyncReadyCallback callback
,
251 static GFileIOStream
* g_file_real_create_readwrite_finish (GFile
*file
,
254 static void g_file_real_replace_readwrite_async (GFile
*file
,
256 gboolean make_backup
,
257 GFileCreateFlags flags
,
259 GCancellable
*cancellable
,
260 GAsyncReadyCallback callback
,
262 static GFileIOStream
* g_file_real_replace_readwrite_finish (GFile
*file
,
265 static gboolean
g_file_real_set_attributes_from_info (GFile
*file
,
267 GFileQueryInfoFlags flags
,
268 GCancellable
*cancellable
,
270 static void g_file_real_set_display_name_async (GFile
*file
,
271 const char *display_name
,
273 GCancellable
*cancellable
,
274 GAsyncReadyCallback callback
,
276 static GFile
* g_file_real_set_display_name_finish (GFile
*file
,
279 static void g_file_real_set_attributes_async (GFile
*file
,
281 GFileQueryInfoFlags flags
,
283 GCancellable
*cancellable
,
284 GAsyncReadyCallback callback
,
286 static gboolean
g_file_real_set_attributes_finish (GFile
*file
,
290 static void g_file_real_find_enclosing_mount_async (GFile
*file
,
292 GCancellable
*cancellable
,
293 GAsyncReadyCallback callback
,
295 static GMount
* g_file_real_find_enclosing_mount_finish (GFile
*file
,
298 static void g_file_real_copy_async (GFile
*source
,
300 GFileCopyFlags flags
,
302 GCancellable
*cancellable
,
303 GFileProgressCallback progress_callback
,
304 gpointer progress_callback_data
,
305 GAsyncReadyCallback callback
,
307 static gboolean
g_file_real_copy_finish (GFile
*file
,
311 static gboolean
g_file_real_measure_disk_usage (GFile
*file
,
312 GFileMeasureFlags flags
,
313 GCancellable
*cancellable
,
314 GFileMeasureProgressCallback progress_callback
,
315 gpointer progress_data
,
320 static void g_file_real_measure_disk_usage_async (GFile
*file
,
321 GFileMeasureFlags flags
,
323 GCancellable
*cancellable
,
324 GFileMeasureProgressCallback progress_callback
,
325 gpointer progress_data
,
326 GAsyncReadyCallback callback
,
328 static gboolean
g_file_real_measure_disk_usage_finish (GFile
*file
,
329 GAsyncResult
*result
,
335 typedef GFileIface GFileInterface
;
336 G_DEFINE_INTERFACE (GFile
, g_file
, G_TYPE_OBJECT
)
339 g_file_default_init (GFileIface
*iface
)
341 iface
->enumerate_children_async
= g_file_real_enumerate_children_async
;
342 iface
->enumerate_children_finish
= g_file_real_enumerate_children_finish
;
343 iface
->set_display_name_async
= g_file_real_set_display_name_async
;
344 iface
->set_display_name_finish
= g_file_real_set_display_name_finish
;
345 iface
->query_info_async
= g_file_real_query_info_async
;
346 iface
->query_info_finish
= g_file_real_query_info_finish
;
347 iface
->query_filesystem_info_async
= g_file_real_query_filesystem_info_async
;
348 iface
->query_filesystem_info_finish
= g_file_real_query_filesystem_info_finish
;
349 iface
->set_attributes_async
= g_file_real_set_attributes_async
;
350 iface
->set_attributes_finish
= g_file_real_set_attributes_finish
;
351 iface
->read_async
= g_file_real_read_async
;
352 iface
->read_finish
= g_file_real_read_finish
;
353 iface
->append_to_async
= g_file_real_append_to_async
;
354 iface
->append_to_finish
= g_file_real_append_to_finish
;
355 iface
->create_async
= g_file_real_create_async
;
356 iface
->create_finish
= g_file_real_create_finish
;
357 iface
->replace_async
= g_file_real_replace_async
;
358 iface
->replace_finish
= g_file_real_replace_finish
;
359 iface
->delete_file_async
= g_file_real_delete_async
;
360 iface
->delete_file_finish
= g_file_real_delete_finish
;
361 iface
->trash_async
= g_file_real_trash_async
;
362 iface
->trash_finish
= g_file_real_trash_finish
;
363 iface
->make_directory_async
= g_file_real_make_directory_async
;
364 iface
->make_directory_finish
= g_file_real_make_directory_finish
;
365 iface
->open_readwrite_async
= g_file_real_open_readwrite_async
;
366 iface
->open_readwrite_finish
= g_file_real_open_readwrite_finish
;
367 iface
->create_readwrite_async
= g_file_real_create_readwrite_async
;
368 iface
->create_readwrite_finish
= g_file_real_create_readwrite_finish
;
369 iface
->replace_readwrite_async
= g_file_real_replace_readwrite_async
;
370 iface
->replace_readwrite_finish
= g_file_real_replace_readwrite_finish
;
371 iface
->find_enclosing_mount_async
= g_file_real_find_enclosing_mount_async
;
372 iface
->find_enclosing_mount_finish
= g_file_real_find_enclosing_mount_finish
;
373 iface
->set_attributes_from_info
= g_file_real_set_attributes_from_info
;
374 iface
->copy_async
= g_file_real_copy_async
;
375 iface
->copy_finish
= g_file_real_copy_finish
;
376 iface
->measure_disk_usage
= g_file_real_measure_disk_usage
;
377 iface
->measure_disk_usage_async
= g_file_real_measure_disk_usage_async
;
378 iface
->measure_disk_usage_finish
= g_file_real_measure_disk_usage_finish
;
384 * @file: input #GFile
386 * Checks to see if a file is native to the platform.
388 * A native file s one expressed in the platform-native filename format,
389 * e.g. "C:\Windows" or "/usr/bin/". This does not mean the file is local,
390 * as it might be on a locally mounted remote filesystem.
392 * On some systems non-native files may be available using the native
393 * filesystem via a userspace filesystem (FUSE), in these cases this call
394 * will return %FALSE, but g_file_get_path() will still return a native path.
396 * This call does no blocking I/O.
398 * Returns: %TRUE if @file is native
401 g_file_is_native (GFile
*file
)
405 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
407 iface
= G_FILE_GET_IFACE (file
);
409 return (* iface
->is_native
) (file
);
414 * g_file_has_uri_scheme:
415 * @file: input #GFile
416 * @uri_scheme: a string containing a URI scheme
418 * Checks to see if a #GFile has a given URI scheme.
420 * This call does no blocking I/O.
422 * Returns: %TRUE if #GFile's backend supports the
423 * given URI scheme, %FALSE if URI scheme is %NULL,
424 * not supported, or #GFile is invalid.
427 g_file_has_uri_scheme (GFile
*file
,
428 const char *uri_scheme
)
432 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
433 g_return_val_if_fail (uri_scheme
!= NULL
, FALSE
);
435 iface
= G_FILE_GET_IFACE (file
);
437 return (* iface
->has_uri_scheme
) (file
, uri_scheme
);
442 * g_file_get_uri_scheme:
443 * @file: input #GFile
445 * Gets the URI scheme for a #GFile.
446 * RFC 3986 decodes the scheme as:
448 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
450 * Common schemes include "file", "http", "ftp", etc.
452 * This call does no blocking I/O.
454 * Returns: a string containing the URI scheme for the given
455 * #GFile. The returned string should be freed with g_free()
456 * when no longer needed.
459 g_file_get_uri_scheme (GFile
*file
)
463 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
465 iface
= G_FILE_GET_IFACE (file
);
467 return (* iface
->get_uri_scheme
) (file
);
472 * g_file_get_basename:
473 * @file: input #GFile
475 * Gets the base name (the last component of the path) for a given #GFile.
477 * If called for the top level of a system (such as the filesystem root
478 * or a uri like sftp://host/) it will return a single directory separator
479 * (and on Windows, possibly a drive letter).
481 * The base name is a byte string (not UTF-8). It has no defined encoding
482 * or rules other than it may not contain zero bytes. If you want to use
483 * filenames in a user interface you should use the display name that you
484 * can get by requesting the %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
485 * attribute with g_file_query_info().
487 * This call does no blocking I/O.
489 * Returns: (nullable): string containing the #GFile's base name, or
490 * %NULL if given #GFile is invalid. The returned string should be
491 * freed with g_free() when no longer needed.
494 g_file_get_basename (GFile
*file
)
498 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
500 iface
= G_FILE_GET_IFACE (file
);
502 return (* iface
->get_basename
) (file
);
507 * @file: input #GFile
509 * Gets the local pathname for #GFile, if one exists.
511 * This call does no blocking I/O.
513 * Returns: (nullable): string containing the #GFile's path, or %NULL
514 * if no such path exists. The returned string should be freed
515 * with g_free() when no longer needed.
518 g_file_get_path (GFile
*file
)
522 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
524 iface
= G_FILE_GET_IFACE (file
);
526 return (* iface
->get_path
) (file
);
531 * @file: input #GFile
533 * Gets the URI for the @file.
535 * This call does no blocking I/O.
537 * Returns: a string containing the #GFile's URI.
538 * The returned string should be freed with g_free()
539 * when no longer needed.
542 g_file_get_uri (GFile
*file
)
546 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
548 iface
= G_FILE_GET_IFACE (file
);
550 return (* iface
->get_uri
) (file
);
554 * g_file_get_parse_name:
555 * @file: input #GFile
557 * Gets the parse name of the @file.
558 * A parse name is a UTF-8 string that describes the
559 * file such that one can get the #GFile back using
560 * g_file_parse_name().
562 * This is generally used to show the #GFile as a nice
563 * full-pathname kind of string in a user interface,
564 * like in a location entry.
566 * For local files with names that can safely be converted
567 * to UTF-8 the pathname is used, otherwise the IRI is used
568 * (a form of URI that allows UTF-8 characters unescaped).
570 * This call does no blocking I/O.
572 * Returns: a string containing the #GFile's parse name.
573 * The returned string should be freed with g_free()
574 * when no longer needed.
577 g_file_get_parse_name (GFile
*file
)
581 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
583 iface
= G_FILE_GET_IFACE (file
);
585 return (* iface
->get_parse_name
) (file
);
590 * @file: input #GFile
592 * Duplicates a #GFile handle. This operation does not duplicate
593 * the actual file or directory represented by the #GFile; see
594 * g_file_copy() if attempting to copy a file.
596 * This call does no blocking I/O.
598 * Returns: (transfer full): a new #GFile that is a duplicate
599 * of the given #GFile.
602 g_file_dup (GFile
*file
)
606 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
608 iface
= G_FILE_GET_IFACE (file
);
610 return (* iface
->dup
) (file
);
615 * @file: (type GFile): #gconstpointer to a #GFile
617 * Creates a hash value for a #GFile.
619 * This call does no blocking I/O.
622 * Returns: 0 if @file is not a valid #GFile, otherwise an
623 * integer that can be used as hash value for the #GFile.
624 * This function is intended for easily hashing a #GFile to
625 * add to a #GHashTable or similar data structure.
628 g_file_hash (gconstpointer file
)
632 g_return_val_if_fail (G_IS_FILE (file
), 0);
634 iface
= G_FILE_GET_IFACE (file
);
636 return (* iface
->hash
) ((GFile
*)file
);
641 * @file1: the first #GFile
642 * @file2: the second #GFile
644 * Checks equality of two given #GFiles.
646 * Note that two #GFiles that differ can still refer to the same
647 * file on the filesystem due to various forms of filename
650 * This call does no blocking I/O.
652 * Returns: %TRUE if @file1 and @file2 are equal.
653 * %FALSE if either is not a #GFile.
656 g_file_equal (GFile
*file1
,
661 g_return_val_if_fail (G_IS_FILE (file1
), FALSE
);
662 g_return_val_if_fail (G_IS_FILE (file2
), FALSE
);
664 if (G_TYPE_FROM_INSTANCE (file1
) != G_TYPE_FROM_INSTANCE (file2
))
667 iface
= G_FILE_GET_IFACE (file1
);
669 return (* iface
->equal
) (file1
, file2
);
675 * @file: input #GFile
677 * Gets the parent directory for the @file.
678 * If the @file represents the root directory of the
679 * file system, then %NULL will be returned.
681 * This call does no blocking I/O.
683 * Returns: (nullable) (transfer full): a #GFile structure to the
684 * parent of the given #GFile or %NULL if there is no parent. Free
685 * the returned object with g_object_unref().
688 g_file_get_parent (GFile
*file
)
692 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
694 iface
= G_FILE_GET_IFACE (file
);
696 return (* iface
->get_parent
) (file
);
701 * @file: input #GFile
702 * @parent: (allow-none): the parent to check for, or %NULL
704 * Checks if @file has a parent, and optionally, if it is @parent.
706 * If @parent is %NULL then this function returns %TRUE if @file has any
707 * parent at all. If @parent is non-%NULL then %TRUE is only returned
708 * if @file is a child of @parent.
710 * Returns: %TRUE if @file is a child of @parent (or any parent in the
711 * case that @parent is %NULL).
716 g_file_has_parent (GFile
*file
,
719 GFile
*actual_parent
;
722 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
723 g_return_val_if_fail (parent
== NULL
|| G_IS_FILE (parent
), FALSE
);
725 actual_parent
= g_file_get_parent (file
);
727 if (actual_parent
!= NULL
)
730 result
= g_file_equal (parent
, actual_parent
);
734 g_object_unref (actual_parent
);
744 * @file: input #GFile
745 * @name: string containing the child's basename
747 * Gets a child of @file with basename equal to @name.
749 * Note that the file with that specific name might not exist, but
750 * you can still have a #GFile that points to it. You can use this
751 * for instance to create that file.
753 * This call does no blocking I/O.
755 * Returns: (transfer full): a #GFile to a child specified by @name.
756 * Free the returned object with g_object_unref().
759 g_file_get_child (GFile
*file
,
762 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
763 g_return_val_if_fail (name
!= NULL
, NULL
);
765 return g_file_resolve_relative_path (file
, name
);
769 * g_file_get_child_for_display_name:
770 * @file: input #GFile
771 * @display_name: string to a possible child
772 * @error: return location for an error
774 * Gets the child of @file for a given @display_name (i.e. a UTF-8
775 * version of the name). If this function fails, it returns %NULL
776 * and @error will be set. This is very useful when constructing a
777 * #GFile for a new file and the user entered the filename in the
778 * user interface, for instance when you select a directory and
779 * type a filename in the file selector.
781 * This call does no blocking I/O.
783 * Returns: (transfer full): a #GFile to the specified child, or
784 * %NULL if the display name couldn't be converted.
785 * Free the returned object with g_object_unref().
788 g_file_get_child_for_display_name (GFile
*file
,
789 const char *display_name
,
794 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
795 g_return_val_if_fail (display_name
!= NULL
, NULL
);
797 iface
= G_FILE_GET_IFACE (file
);
799 return (* iface
->get_child_for_display_name
) (file
, display_name
, error
);
804 * @file: input #GFile
805 * @prefix: input #GFile
807 * Checks whether @file has the prefix specified by @prefix.
809 * In other words, if the names of initial elements of @file's
810 * pathname match @prefix. Only full pathname elements are matched,
811 * so a path like /foo is not considered a prefix of /foobar, only
814 * This call does no I/O, as it works purely on names. As such it can
815 * sometimes return %FALSE even if @file is inside a @prefix (from a
816 * filesystem point of view), because the prefix of @file is an alias
819 * Virtual: prefix_matches
820 * Returns: %TRUE if the @files's parent, grandparent, etc is @prefix,
824 g_file_has_prefix (GFile
*file
,
829 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
830 g_return_val_if_fail (G_IS_FILE (prefix
), FALSE
);
832 if (G_TYPE_FROM_INSTANCE (file
) != G_TYPE_FROM_INSTANCE (prefix
))
835 iface
= G_FILE_GET_IFACE (file
);
837 /* The vtable function differs in arg order since
838 * we're using the old contains_file call
840 return (* iface
->prefix_matches
) (prefix
, file
);
844 * g_file_get_relative_path:
845 * @parent: input #GFile
846 * @descendant: input #GFile
848 * Gets the path for @descendant relative to @parent.
850 * This call does no blocking I/O.
852 * Returns: (nullable): string with the relative path from @descendant
853 * to @parent, or %NULL if @descendant doesn't have @parent as
854 * prefix. The returned string should be freed with g_free() when
858 g_file_get_relative_path (GFile
*parent
,
863 g_return_val_if_fail (G_IS_FILE (parent
), NULL
);
864 g_return_val_if_fail (G_IS_FILE (descendant
), NULL
);
866 if (G_TYPE_FROM_INSTANCE (parent
) != G_TYPE_FROM_INSTANCE (descendant
))
869 iface
= G_FILE_GET_IFACE (parent
);
871 return (* iface
->get_relative_path
) (parent
, descendant
);
875 * g_file_resolve_relative_path:
876 * @file: input #GFile
877 * @relative_path: a given relative path string
879 * Resolves a relative path for @file to an absolute path.
881 * This call does no blocking I/O.
883 * Returns: (transfer full): #GFile to the resolved path.
884 * %NULL if @relative_path is %NULL or if @file is invalid.
885 * Free the returned object with g_object_unref().
888 g_file_resolve_relative_path (GFile
*file
,
889 const char *relative_path
)
893 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
894 g_return_val_if_fail (relative_path
!= NULL
, NULL
);
896 iface
= G_FILE_GET_IFACE (file
);
898 return (* iface
->resolve_relative_path
) (file
, relative_path
);
902 * g_file_enumerate_children:
903 * @file: input #GFile
904 * @attributes: an attribute query string
905 * @flags: a set of #GFileQueryInfoFlags
906 * @cancellable: (allow-none): optional #GCancellable object,
908 * @error: #GError for error reporting
910 * Gets the requested information about the files in a directory.
911 * The result is a #GFileEnumerator object that will give out
912 * #GFileInfo objects for all the files in the directory.
914 * The @attributes value is a string that specifies the file
915 * attributes that should be gathered. It is not an error if
916 * it's not possible to read a particular requested attribute
917 * from a file - it just won't be set. @attributes should
918 * be a comma-separated list of attributes or attribute wildcards.
919 * The wildcard "*" means all attributes, and a wildcard like
920 * "standard::*" means all attributes in the standard namespace.
921 * An example attribute query be "standard::*,owner::user".
922 * The standard attributes are available as defines, like
923 * #G_FILE_ATTRIBUTE_STANDARD_NAME.
925 * If @cancellable is not %NULL, then the operation can be cancelled
926 * by triggering the cancellable object from another thread. If the
927 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
930 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will
931 * be returned. If the file is not a directory, the %G_IO_ERROR_NOT_DIRECTORY
932 * error will be returned. Other errors are possible too.
934 * Returns: (transfer full): A #GFileEnumerator if successful,
935 * %NULL on error. Free the returned object with g_object_unref().
938 g_file_enumerate_children (GFile
*file
,
939 const char *attributes
,
940 GFileQueryInfoFlags flags
,
941 GCancellable
*cancellable
,
946 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
948 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
951 iface
= G_FILE_GET_IFACE (file
);
953 if (iface
->enumerate_children
== NULL
)
955 g_set_error_literal (error
, G_IO_ERROR
,
956 G_IO_ERROR_NOT_SUPPORTED
,
957 _("Operation not supported"));
961 return (* iface
->enumerate_children
) (file
, attributes
, flags
,
966 * g_file_enumerate_children_async:
967 * @file: input #GFile
968 * @attributes: an attribute query string
969 * @flags: a set of #GFileQueryInfoFlags
970 * @io_priority: the [I/O priority][io-priority] of the request
971 * @cancellable: (allow-none): optional #GCancellable object,
973 * @callback: (scope async): a #GAsyncReadyCallback to call when the
974 * request is satisfied
975 * @user_data: (closure): the data to pass to callback function
977 * Asynchronously gets the requested information about the files
978 * in a directory. The result is a #GFileEnumerator object that will
979 * give out #GFileInfo objects for all the files in the directory.
981 * For more details, see g_file_enumerate_children() which is
982 * the synchronous version of this call.
984 * When the operation is finished, @callback will be called. You can
985 * then call g_file_enumerate_children_finish() to get the result of
989 g_file_enumerate_children_async (GFile
*file
,
990 const char *attributes
,
991 GFileQueryInfoFlags flags
,
993 GCancellable
*cancellable
,
994 GAsyncReadyCallback callback
,
999 g_return_if_fail (G_IS_FILE (file
));
1001 iface
= G_FILE_GET_IFACE (file
);
1002 (* iface
->enumerate_children_async
) (file
,
1012 * g_file_enumerate_children_finish:
1013 * @file: input #GFile
1014 * @res: a #GAsyncResult
1017 * Finishes an async enumerate children operation.
1018 * See g_file_enumerate_children_async().
1020 * Returns: (transfer full): a #GFileEnumerator or %NULL
1021 * if an error occurred.
1022 * Free the returned object with g_object_unref().
1025 g_file_enumerate_children_finish (GFile
*file
,
1031 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1032 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), NULL
);
1034 if (g_async_result_legacy_propagate_error (res
, error
))
1037 iface
= G_FILE_GET_IFACE (file
);
1038 return (* iface
->enumerate_children_finish
) (file
, res
, error
);
1042 * g_file_query_exists:
1043 * @file: input #GFile
1044 * @cancellable: (allow-none): optional #GCancellable object,
1047 * Utility function to check if a particular file exists. This is
1048 * implemented using g_file_query_info() and as such does blocking I/O.
1050 * Note that in many cases it is racy to first check for file existence
1051 * and then execute something based on the outcome of that, because the
1052 * file might have been created or removed in between the operations. The
1053 * general approach to handling that is to not check, but just do the
1054 * operation and handle the errors as they come.
1056 * As an example of race-free checking, take the case of reading a file,
1057 * and if it doesn't exist, creating it. There are two racy versions: read
1058 * it, and on error create it; and: check if it exists, if not create it.
1059 * These can both result in two processes creating the file (with perhaps
1060 * a partially written file as the result). The correct approach is to
1061 * always try to create the file with g_file_create() which will either
1062 * atomically create the file or fail with a %G_IO_ERROR_EXISTS error.
1064 * However, in many cases an existence check is useful in a user interface,
1065 * for instance to make a menu item sensitive/insensitive, so that you don't
1066 * have to fool users that something is possible and then just show an error
1067 * dialog. If you do this, you should make sure to also handle the errors
1068 * that can happen due to races when you execute the operation.
1070 * Returns: %TRUE if the file exists (and can be detected without error),
1071 * %FALSE otherwise (or if cancelled).
1074 g_file_query_exists (GFile
*file
,
1075 GCancellable
*cancellable
)
1079 g_return_val_if_fail (G_IS_FILE(file
), FALSE
);
1081 info
= g_file_query_info (file
, G_FILE_ATTRIBUTE_STANDARD_TYPE
,
1082 G_FILE_QUERY_INFO_NONE
, cancellable
, NULL
);
1085 g_object_unref (info
);
1093 * g_file_query_file_type:
1094 * @file: input #GFile
1095 * @flags: a set of #GFileQueryInfoFlags passed to g_file_query_info()
1096 * @cancellable: (allow-none): optional #GCancellable object,
1099 * Utility function to inspect the #GFileType of a file. This is
1100 * implemented using g_file_query_info() and as such does blocking I/O.
1102 * The primary use case of this method is to check if a file is
1103 * a regular file, directory, or symlink.
1105 * Returns: The #GFileType of the file and #G_FILE_TYPE_UNKNOWN
1106 * if the file does not exist
1111 g_file_query_file_type (GFile
*file
,
1112 GFileQueryInfoFlags flags
,
1113 GCancellable
*cancellable
)
1116 GFileType file_type
;
1118 g_return_val_if_fail (G_IS_FILE(file
), G_FILE_TYPE_UNKNOWN
);
1119 info
= g_file_query_info (file
, G_FILE_ATTRIBUTE_STANDARD_TYPE
, flags
,
1123 file_type
= g_file_info_get_file_type (info
);
1124 g_object_unref (info
);
1127 file_type
= G_FILE_TYPE_UNKNOWN
;
1133 * g_file_query_info:
1134 * @file: input #GFile
1135 * @attributes: an attribute query string
1136 * @flags: a set of #GFileQueryInfoFlags
1137 * @cancellable: (allow-none): optional #GCancellable object,
1141 * Gets the requested information about specified @file.
1142 * The result is a #GFileInfo object that contains key-value
1143 * attributes (such as the type or size of the file).
1145 * The @attributes value is a string that specifies the file
1146 * attributes that should be gathered. It is not an error if
1147 * it's not possible to read a particular requested attribute
1148 * from a file - it just won't be set. @attributes should be a
1149 * comma-separated list of attributes or attribute wildcards.
1150 * The wildcard "*" means all attributes, and a wildcard like
1151 * "standard::*" means all attributes in the standard namespace.
1152 * An example attribute query be "standard::*,owner::user".
1153 * The standard attributes are available as defines, like
1154 * #G_FILE_ATTRIBUTE_STANDARD_NAME.
1156 * If @cancellable is not %NULL, then the operation can be cancelled
1157 * by triggering the cancellable object from another thread. If the
1158 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1161 * For symlinks, normally the information about the target of the
1162 * symlink is returned, rather than information about the symlink
1163 * itself. However if you pass #G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
1164 * in @flags the information about the symlink itself will be returned.
1165 * Also, for symlinks that point to non-existing files the information
1166 * about the symlink itself will be returned.
1168 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will be
1169 * returned. Other errors are possible too, and depend on what kind of
1170 * filesystem the file is on.
1172 * Returns: (transfer full): a #GFileInfo for the given @file, or %NULL
1173 * on error. Free the returned object with g_object_unref().
1176 g_file_query_info (GFile
*file
,
1177 const char *attributes
,
1178 GFileQueryInfoFlags flags
,
1179 GCancellable
*cancellable
,
1184 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1186 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
1189 iface
= G_FILE_GET_IFACE (file
);
1191 if (iface
->query_info
== NULL
)
1193 g_set_error_literal (error
, G_IO_ERROR
,
1194 G_IO_ERROR_NOT_SUPPORTED
,
1195 _("Operation not supported"));
1199 return (* iface
->query_info
) (file
, attributes
, flags
, cancellable
, error
);
1203 * g_file_query_info_async:
1204 * @file: input #GFile
1205 * @attributes: an attribute query string
1206 * @flags: a set of #GFileQueryInfoFlags
1207 * @io_priority: the [I/O priority][io-priority] of the request
1208 * @cancellable: (allow-none): optional #GCancellable object,
1210 * @callback: (scope async): a #GAsyncReadyCallback to call when the
1211 * request is satisfied
1212 * @user_data: (closure): the data to pass to callback function
1214 * Asynchronously gets the requested information about specified @file.
1215 * The result is a #GFileInfo object that contains key-value attributes
1216 * (such as type or size for the file).
1218 * For more details, see g_file_query_info() which is the synchronous
1219 * version of this call.
1221 * When the operation is finished, @callback will be called. You can
1222 * then call g_file_query_info_finish() to get the result of the operation.
1225 g_file_query_info_async (GFile
*file
,
1226 const char *attributes
,
1227 GFileQueryInfoFlags flags
,
1229 GCancellable
*cancellable
,
1230 GAsyncReadyCallback callback
,
1235 g_return_if_fail (G_IS_FILE (file
));
1237 iface
= G_FILE_GET_IFACE (file
);
1238 (* iface
->query_info_async
) (file
,
1248 * g_file_query_info_finish:
1249 * @file: input #GFile
1250 * @res: a #GAsyncResult
1253 * Finishes an asynchronous file info query.
1254 * See g_file_query_info_async().
1256 * Returns: (transfer full): #GFileInfo for given @file
1257 * or %NULL on error. Free the returned object with
1261 g_file_query_info_finish (GFile
*file
,
1267 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1268 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), NULL
);
1270 if (g_async_result_legacy_propagate_error (res
, error
))
1273 iface
= G_FILE_GET_IFACE (file
);
1274 return (* iface
->query_info_finish
) (file
, res
, error
);
1278 * g_file_query_filesystem_info:
1279 * @file: input #GFile
1280 * @attributes: an attribute query string
1281 * @cancellable: (allow-none): optional #GCancellable object,
1285 * Similar to g_file_query_info(), but obtains information
1286 * about the filesystem the @file is on, rather than the file itself.
1287 * For instance the amount of space available and the type of
1290 * The @attributes value is a string that specifies the attributes
1291 * that should be gathered. It is not an error if it's not possible
1292 * to read a particular requested attribute from a file - it just
1293 * won't be set. @attributes should be a comma-separated list of
1294 * attributes or attribute wildcards. The wildcard "*" means all
1295 * attributes, and a wildcard like "filesystem::*" means all attributes
1296 * in the filesystem namespace. The standard namespace for filesystem
1297 * attributes is "filesystem". Common attributes of interest are
1298 * #G_FILE_ATTRIBUTE_FILESYSTEM_SIZE (the total size of the filesystem
1299 * in bytes), #G_FILE_ATTRIBUTE_FILESYSTEM_FREE (number of bytes available),
1300 * and #G_FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).
1302 * If @cancellable is not %NULL, then the operation can be cancelled
1303 * by triggering the cancellable object from another thread. If the
1304 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1307 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will
1308 * be returned. Other errors are possible too, and depend on what
1309 * kind of filesystem the file is on.
1311 * Returns: (transfer full): a #GFileInfo or %NULL if there was an error.
1312 * Free the returned object with g_object_unref().
1315 g_file_query_filesystem_info (GFile
*file
,
1316 const char *attributes
,
1317 GCancellable
*cancellable
,
1322 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1324 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
1327 iface
= G_FILE_GET_IFACE (file
);
1329 if (iface
->query_filesystem_info
== NULL
)
1331 g_set_error_literal (error
, G_IO_ERROR
,
1332 G_IO_ERROR_NOT_SUPPORTED
,
1333 _("Operation not supported"));
1337 return (* iface
->query_filesystem_info
) (file
, attributes
, cancellable
, error
);
1341 * g_file_query_filesystem_info_async:
1342 * @file: input #GFile
1343 * @attributes: an attribute query string
1344 * @io_priority: the [I/O priority][io-priority] of the request
1345 * @cancellable: (allow-none): optional #GCancellable object,
1347 * @callback: (scope async): a #GAsyncReadyCallback to call
1348 * when the request is satisfied
1349 * @user_data: (closure): the data to pass to callback function
1351 * Asynchronously gets the requested information about the filesystem
1352 * that the specified @file is on. The result is a #GFileInfo object
1353 * that contains key-value attributes (such as type or size for the
1356 * For more details, see g_file_query_filesystem_info() which is the
1357 * synchronous version of this call.
1359 * When the operation is finished, @callback will be called. You can
1360 * then call g_file_query_info_finish() to get the result of the
1364 g_file_query_filesystem_info_async (GFile
*file
,
1365 const char *attributes
,
1367 GCancellable
*cancellable
,
1368 GAsyncReadyCallback callback
,
1373 g_return_if_fail (G_IS_FILE (file
));
1375 iface
= G_FILE_GET_IFACE (file
);
1376 (* iface
->query_filesystem_info_async
) (file
,
1385 * g_file_query_filesystem_info_finish:
1386 * @file: input #GFile
1387 * @res: a #GAsyncResult
1390 * Finishes an asynchronous filesystem info query.
1391 * See g_file_query_filesystem_info_async().
1393 * Returns: (transfer full): #GFileInfo for given @file
1394 * or %NULL on error.
1395 * Free the returned object with g_object_unref().
1398 g_file_query_filesystem_info_finish (GFile
*file
,
1404 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1405 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), NULL
);
1407 if (g_async_result_legacy_propagate_error (res
, error
))
1410 iface
= G_FILE_GET_IFACE (file
);
1411 return (* iface
->query_filesystem_info_finish
) (file
, res
, error
);
1415 * g_file_find_enclosing_mount:
1416 * @file: input #GFile
1417 * @cancellable: (allow-none): optional #GCancellable object,
1421 * Gets a #GMount for the #GFile.
1423 * If the #GFileIface for @file does not have a mount (e.g.
1424 * possibly a remote share), @error will be set to %G_IO_ERROR_NOT_FOUND
1425 * and %NULL will be returned.
1427 * If @cancellable is not %NULL, then the operation can be cancelled by
1428 * triggering the cancellable object from another thread. If the operation
1429 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1431 * Returns: (transfer full): a #GMount where the @file is located
1432 * or %NULL on error.
1433 * Free the returned object with g_object_unref().
1436 g_file_find_enclosing_mount (GFile
*file
,
1437 GCancellable
*cancellable
,
1442 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1444 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
1447 iface
= G_FILE_GET_IFACE (file
);
1448 if (iface
->find_enclosing_mount
== NULL
)
1451 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_NOT_FOUND
,
1452 /* Translators: This is an error message when
1453 * trying to find the enclosing (user visible)
1454 * mount of a file, but none exists.
1456 _("Containing mount does not exist"));
1460 return (* iface
->find_enclosing_mount
) (file
, cancellable
, error
);
1464 * g_file_find_enclosing_mount_async:
1466 * @io_priority: the [I/O priority][io-priority] of the request
1467 * @cancellable: (allow-none): optional #GCancellable object,
1469 * @callback: (scope async): a #GAsyncReadyCallback to call
1470 * when the request is satisfied
1471 * @user_data: (closure): the data to pass to callback function
1473 * Asynchronously gets the mount for the file.
1475 * For more details, see g_file_find_enclosing_mount() which is
1476 * the synchronous version of this call.
1478 * When the operation is finished, @callback will be called.
1479 * You can then call g_file_find_enclosing_mount_finish() to
1480 * get the result of the operation.
1483 g_file_find_enclosing_mount_async (GFile
*file
,
1485 GCancellable
*cancellable
,
1486 GAsyncReadyCallback callback
,
1491 g_return_if_fail (G_IS_FILE (file
));
1493 iface
= G_FILE_GET_IFACE (file
);
1494 (* iface
->find_enclosing_mount_async
) (file
,
1502 * g_file_find_enclosing_mount_finish:
1504 * @res: a #GAsyncResult
1507 * Finishes an asynchronous find mount request.
1508 * See g_file_find_enclosing_mount_async().
1510 * Returns: (transfer full): #GMount for given @file or %NULL on error.
1511 * Free the returned object with g_object_unref().
1514 g_file_find_enclosing_mount_finish (GFile
*file
,
1520 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1521 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), NULL
);
1523 if (g_async_result_legacy_propagate_error (res
, error
))
1526 iface
= G_FILE_GET_IFACE (file
);
1527 return (* iface
->find_enclosing_mount_finish
) (file
, res
, error
);
1533 * @file: #GFile to read
1534 * @cancellable: (allow-none): a #GCancellable
1535 * @error: a #GError, or %NULL
1537 * Opens a file for reading. The result is a #GFileInputStream that
1538 * can be used to read the contents of the file.
1540 * If @cancellable is not %NULL, then the operation can be cancelled by
1541 * triggering the cancellable object from another thread. If the operation
1542 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
1544 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will be
1545 * returned. If the file is a directory, the %G_IO_ERROR_IS_DIRECTORY
1546 * error will be returned. Other errors are possible too, and depend
1547 * on what kind of filesystem the file is on.
1550 * Returns: (transfer full): #GFileInputStream or %NULL on error.
1551 * Free the returned object with g_object_unref().
1554 g_file_read (GFile
*file
,
1555 GCancellable
*cancellable
,
1560 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1562 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
1565 iface
= G_FILE_GET_IFACE (file
);
1567 if (iface
->read_fn
== NULL
)
1569 g_set_error_literal (error
, G_IO_ERROR
,
1570 G_IO_ERROR_NOT_SUPPORTED
,
1571 _("Operation not supported"));
1575 return (* iface
->read_fn
) (file
, cancellable
, error
);
1580 * @file: input #GFile
1581 * @flags: a set of #GFileCreateFlags
1582 * @cancellable: (allow-none): optional #GCancellable object,
1584 * @error: a #GError, or %NULL
1586 * Gets an output stream for appending data to the file.
1587 * If the file doesn't already exist it is created.
1589 * By default files created are generally readable by everyone,
1590 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1591 * will be made readable only to the current user, to the level that
1592 * is supported on the target filesystem.
1594 * If @cancellable is not %NULL, then the operation can be cancelled
1595 * by triggering the cancellable object from another thread. If the
1596 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1599 * Some file systems don't allow all file names, and may return an
1600 * %G_IO_ERROR_INVALID_FILENAME error. If the file is a directory the
1601 * %G_IO_ERROR_IS_DIRECTORY error will be returned. Other errors are
1602 * possible too, and depend on what kind of filesystem the file is on.
1604 * Returns: (transfer full): a #GFileOutputStream, or %NULL on error.
1605 * Free the returned object with g_object_unref().
1608 g_file_append_to (GFile
*file
,
1609 GFileCreateFlags flags
,
1610 GCancellable
*cancellable
,
1615 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1617 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
1620 iface
= G_FILE_GET_IFACE (file
);
1622 if (iface
->append_to
== NULL
)
1624 g_set_error_literal (error
, G_IO_ERROR
,
1625 G_IO_ERROR_NOT_SUPPORTED
,
1626 _("Operation not supported"));
1630 return (* iface
->append_to
) (file
, flags
, cancellable
, error
);
1635 * @file: input #GFile
1636 * @flags: a set of #GFileCreateFlags
1637 * @cancellable: (allow-none): optional #GCancellable object,
1639 * @error: a #GError, or %NULL
1641 * Creates a new file and returns an output stream for writing to it.
1642 * The file must not already exist.
1644 * By default files created are generally readable by everyone,
1645 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1646 * will be made readable only to the current user, to the level
1647 * that is supported on the target filesystem.
1649 * If @cancellable is not %NULL, then the operation can be cancelled
1650 * by triggering the cancellable object from another thread. If the
1651 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1654 * If a file or directory with this name already exists the
1655 * %G_IO_ERROR_EXISTS error will be returned. Some file systems don't
1656 * allow all file names, and may return an %G_IO_ERROR_INVALID_FILENAME
1657 * error, and if the name is to long %G_IO_ERROR_FILENAME_TOO_LONG will
1658 * be returned. Other errors are possible too, and depend on what kind
1659 * of filesystem the file is on.
1661 * Returns: (transfer full): a #GFileOutputStream for the newly created
1662 * file, or %NULL on error.
1663 * Free the returned object with g_object_unref().
1666 g_file_create (GFile
*file
,
1667 GFileCreateFlags flags
,
1668 GCancellable
*cancellable
,
1673 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1675 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
1678 iface
= G_FILE_GET_IFACE (file
);
1680 if (iface
->create
== NULL
)
1682 g_set_error_literal (error
, G_IO_ERROR
,
1683 G_IO_ERROR_NOT_SUPPORTED
,
1684 _("Operation not supported"));
1688 return (* iface
->create
) (file
, flags
, cancellable
, error
);
1693 * @file: input #GFile
1694 * @etag: (allow-none): an optional [entity tag][gfile-etag]
1695 * for the current #GFile, or #NULL to ignore
1696 * @make_backup: %TRUE if a backup should be created
1697 * @flags: a set of #GFileCreateFlags
1698 * @cancellable: (allow-none): optional #GCancellable object,
1700 * @error: a #GError, or %NULL
1702 * Returns an output stream for overwriting the file, possibly
1703 * creating a backup copy of the file first. If the file doesn't exist,
1704 * it will be created.
1706 * This will try to replace the file in the safest way possible so
1707 * that any errors during the writing will not affect an already
1708 * existing copy of the file. For instance, for local files it
1709 * may write to a temporary file and then atomically rename over
1710 * the destination when the stream is closed.
1712 * By default files created are generally readable by everyone,
1713 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1714 * will be made readable only to the current user, to the level that
1715 * is supported on the target filesystem.
1717 * If @cancellable is not %NULL, then the operation can be cancelled
1718 * by triggering the cancellable object from another thread. If the
1719 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1722 * If you pass in a non-%NULL @etag value, then this value is
1723 * compared to the current entity tag of the file, and if they differ
1724 * an %G_IO_ERROR_WRONG_ETAG error is returned. This generally means
1725 * that the file has been changed since you last read it. You can get
1726 * the new etag from g_file_output_stream_get_etag() after you've
1727 * finished writing and closed the #GFileOutputStream. When you load
1728 * a new file you can use g_file_input_stream_query_info() to get
1729 * the etag of the file.
1731 * If @make_backup is %TRUE, this function will attempt to make a
1732 * backup of the current file before overwriting it. If this fails
1733 * a %G_IO_ERROR_CANT_CREATE_BACKUP error will be returned. If you
1734 * want to replace anyway, try again with @make_backup set to %FALSE.
1736 * If the file is a directory the %G_IO_ERROR_IS_DIRECTORY error will
1737 * be returned, and if the file is some other form of non-regular file
1738 * then a %G_IO_ERROR_NOT_REGULAR_FILE error will be returned. Some
1739 * file systems don't allow all file names, and may return an
1740 * %G_IO_ERROR_INVALID_FILENAME error, and if the name is to long
1741 * %G_IO_ERROR_FILENAME_TOO_LONG will be returned. Other errors are
1742 * possible too, and depend on what kind of filesystem the file is on.
1744 * Returns: (transfer full): a #GFileOutputStream or %NULL on error.
1745 * Free the returned object with g_object_unref().
1748 g_file_replace (GFile
*file
,
1750 gboolean make_backup
,
1751 GFileCreateFlags flags
,
1752 GCancellable
*cancellable
,
1757 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1759 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
1762 iface
= G_FILE_GET_IFACE (file
);
1764 if (iface
->replace
== NULL
)
1766 g_set_error_literal (error
, G_IO_ERROR
,
1767 G_IO_ERROR_NOT_SUPPORTED
,
1768 _("Operation not supported"));
1772 /* Handle empty tag string as NULL in consistent way. */
1773 if (etag
&& *etag
== 0)
1776 return (* iface
->replace
) (file
, etag
, make_backup
, flags
, cancellable
, error
);
1780 * g_file_open_readwrite:
1781 * @file: #GFile to open
1782 * @cancellable: (allow-none): a #GCancellable
1783 * @error: a #GError, or %NULL
1785 * Opens an existing file for reading and writing. The result is
1786 * a #GFileIOStream that can be used to read and write the contents
1789 * If @cancellable is not %NULL, then the operation can be cancelled
1790 * by triggering the cancellable object from another thread. If the
1791 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1794 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will
1795 * be returned. If the file is a directory, the %G_IO_ERROR_IS_DIRECTORY
1796 * error will be returned. Other errors are possible too, and depend on
1797 * what kind of filesystem the file is on. Note that in many non-local
1798 * file cases read and write streams are not supported, so make sure you
1799 * really need to do read and write streaming, rather than just opening
1800 * for reading or writing.
1802 * Returns: (transfer full): #GFileIOStream or %NULL on error.
1803 * Free the returned object with g_object_unref().
1808 g_file_open_readwrite (GFile
*file
,
1809 GCancellable
*cancellable
,
1814 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1816 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
1819 iface
= G_FILE_GET_IFACE (file
);
1821 if (iface
->open_readwrite
== NULL
)
1823 g_set_error_literal (error
, G_IO_ERROR
,
1824 G_IO_ERROR_NOT_SUPPORTED
,
1825 _("Operation not supported"));
1829 return (* iface
->open_readwrite
) (file
, cancellable
, error
);
1833 * g_file_create_readwrite:
1835 * @flags: a set of #GFileCreateFlags
1836 * @cancellable: (allow-none): optional #GCancellable object,
1838 * @error: return location for a #GError, or %NULL
1840 * Creates a new file and returns a stream for reading and
1841 * writing to it. The file must not already exist.
1843 * By default files created are generally readable by everyone,
1844 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
1845 * will be made readable only to the current user, to the level
1846 * that is supported on the target filesystem.
1848 * If @cancellable is not %NULL, then the operation can be cancelled
1849 * by triggering the cancellable object from another thread. If the
1850 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
1853 * If a file or directory with this name already exists, the
1854 * %G_IO_ERROR_EXISTS error will be returned. Some file systems don't
1855 * allow all file names, and may return an %G_IO_ERROR_INVALID_FILENAME
1856 * error, and if the name is too long, %G_IO_ERROR_FILENAME_TOO_LONG
1857 * will be returned. Other errors are possible too, and depend on what
1858 * kind of filesystem the file is on.
1860 * Note that in many non-local file cases read and write streams are
1861 * not supported, so make sure you really need to do read and write
1862 * streaming, rather than just opening for reading or writing.
1864 * Returns: (transfer full): a #GFileIOStream for the newly created
1865 * file, or %NULL on error.
1866 * Free the returned object with g_object_unref().
1871 g_file_create_readwrite (GFile
*file
,
1872 GFileCreateFlags flags
,
1873 GCancellable
*cancellable
,
1878 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1880 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
1883 iface
= G_FILE_GET_IFACE (file
);
1885 if (iface
->create_readwrite
== NULL
)
1887 g_set_error_literal (error
, G_IO_ERROR
,
1888 G_IO_ERROR_NOT_SUPPORTED
,
1889 _("Operation not supported"));
1893 return (* iface
->create_readwrite
) (file
, flags
, cancellable
, error
);
1897 * g_file_replace_readwrite:
1899 * @etag: (allow-none): an optional [entity tag][gfile-etag]
1900 * for the current #GFile, or #NULL to ignore
1901 * @make_backup: %TRUE if a backup should be created
1902 * @flags: a set of #GFileCreateFlags
1903 * @cancellable: (allow-none): optional #GCancellable object,
1905 * @error: return location for a #GError, or %NULL
1907 * Returns an output stream for overwriting the file in readwrite mode,
1908 * possibly creating a backup copy of the file first. If the file doesn't
1909 * exist, it will be created.
1911 * For details about the behaviour, see g_file_replace() which does the
1912 * same thing but returns an output stream only.
1914 * Note that in many non-local file cases read and write streams are not
1915 * supported, so make sure you really need to do read and write streaming,
1916 * rather than just opening for reading or writing.
1918 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
1919 * Free the returned object with g_object_unref().
1924 g_file_replace_readwrite (GFile
*file
,
1926 gboolean make_backup
,
1927 GFileCreateFlags flags
,
1928 GCancellable
*cancellable
,
1933 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
1935 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
1938 iface
= G_FILE_GET_IFACE (file
);
1940 if (iface
->replace_readwrite
== NULL
)
1942 g_set_error_literal (error
, G_IO_ERROR
,
1943 G_IO_ERROR_NOT_SUPPORTED
,
1944 _("Operation not supported"));
1948 return (* iface
->replace_readwrite
) (file
, etag
, make_backup
, flags
, cancellable
, error
);
1952 * g_file_read_async:
1953 * @file: input #GFile
1954 * @io_priority: the [I/O priority][io-priority] of the request
1955 * @cancellable: (allow-none): optional #GCancellable object,
1957 * @callback: (scope async): a #GAsyncReadyCallback to call
1958 * when the request is satisfied
1959 * @user_data: (closure): the data to pass to callback function
1961 * Asynchronously opens @file for reading.
1963 * For more details, see g_file_read() which is
1964 * the synchronous version of this call.
1966 * When the operation is finished, @callback will be called.
1967 * You can then call g_file_read_finish() to get the result
1971 g_file_read_async (GFile
*file
,
1973 GCancellable
*cancellable
,
1974 GAsyncReadyCallback callback
,
1979 g_return_if_fail (G_IS_FILE (file
));
1981 iface
= G_FILE_GET_IFACE (file
);
1982 (* iface
->read_async
) (file
,
1990 * g_file_read_finish:
1991 * @file: input #GFile
1992 * @res: a #GAsyncResult
1993 * @error: a #GError, or %NULL
1995 * Finishes an asynchronous file read operation started with
1996 * g_file_read_async().
1998 * Returns: (transfer full): a #GFileInputStream or %NULL on error.
1999 * Free the returned object with g_object_unref().
2002 g_file_read_finish (GFile
*file
,
2008 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
2009 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), NULL
);
2011 if (g_async_result_legacy_propagate_error (res
, error
))
2014 iface
= G_FILE_GET_IFACE (file
);
2015 return (* iface
->read_finish
) (file
, res
, error
);
2019 * g_file_append_to_async:
2020 * @file: input #GFile
2021 * @flags: a set of #GFileCreateFlags
2022 * @io_priority: the [I/O priority][io-priority] of the request
2023 * @cancellable: (allow-none): optional #GCancellable object,
2025 * @callback: (scope async): a #GAsyncReadyCallback to call
2026 * when the request is satisfied
2027 * @user_data: (closure): the data to pass to callback function
2029 * Asynchronously opens @file for appending.
2031 * For more details, see g_file_append_to() which is
2032 * the synchronous version of this call.
2034 * When the operation is finished, @callback will be called.
2035 * You can then call g_file_append_to_finish() to get the result
2039 g_file_append_to_async (GFile
*file
,
2040 GFileCreateFlags flags
,
2042 GCancellable
*cancellable
,
2043 GAsyncReadyCallback callback
,
2048 g_return_if_fail (G_IS_FILE (file
));
2050 iface
= G_FILE_GET_IFACE (file
);
2051 (* iface
->append_to_async
) (file
,
2060 * g_file_append_to_finish:
2061 * @file: input #GFile
2062 * @res: #GAsyncResult
2063 * @error: a #GError, or %NULL
2065 * Finishes an asynchronous file append operation started with
2066 * g_file_append_to_async().
2068 * Returns: (transfer full): a valid #GFileOutputStream
2069 * or %NULL on error.
2070 * Free the returned object with g_object_unref().
2073 g_file_append_to_finish (GFile
*file
,
2079 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
2080 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), NULL
);
2082 if (g_async_result_legacy_propagate_error (res
, error
))
2085 iface
= G_FILE_GET_IFACE (file
);
2086 return (* iface
->append_to_finish
) (file
, res
, error
);
2090 * g_file_create_async:
2091 * @file: input #GFile
2092 * @flags: a set of #GFileCreateFlags
2093 * @io_priority: the [I/O priority][io-priority] of the request
2094 * @cancellable: (allow-none): optional #GCancellable object,
2096 * @callback: (scope async): a #GAsyncReadyCallback to call
2097 * when the request is satisfied
2098 * @user_data: (closure): the data to pass to callback function
2100 * Asynchronously creates a new file and returns an output stream
2101 * for writing to it. The file must not already exist.
2103 * For more details, see g_file_create() which is
2104 * the synchronous version of this call.
2106 * When the operation is finished, @callback will be called.
2107 * You can then call g_file_create_finish() to get the result
2111 g_file_create_async (GFile
*file
,
2112 GFileCreateFlags flags
,
2114 GCancellable
*cancellable
,
2115 GAsyncReadyCallback callback
,
2120 g_return_if_fail (G_IS_FILE (file
));
2122 iface
= G_FILE_GET_IFACE (file
);
2123 (* iface
->create_async
) (file
,
2132 * g_file_create_finish:
2133 * @file: input #GFile
2134 * @res: a #GAsyncResult
2135 * @error: a #GError, or %NULL
2137 * Finishes an asynchronous file create operation started with
2138 * g_file_create_async().
2140 * Returns: (transfer full): a #GFileOutputStream or %NULL on error.
2141 * Free the returned object with g_object_unref().
2144 g_file_create_finish (GFile
*file
,
2150 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
2151 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), NULL
);
2153 if (g_async_result_legacy_propagate_error (res
, error
))
2156 iface
= G_FILE_GET_IFACE (file
);
2157 return (* iface
->create_finish
) (file
, res
, error
);
2161 * g_file_replace_async:
2162 * @file: input #GFile
2163 * @etag: (allow-none): an [entity tag][gfile-etag] for the current #GFile,
2164 * or %NULL to ignore
2165 * @make_backup: %TRUE if a backup should be created
2166 * @flags: a set of #GFileCreateFlags
2167 * @io_priority: the [I/O priority][io-priority] of the request
2168 * @cancellable: (allow-none): optional #GCancellable object,
2170 * @callback: (scope async): a #GAsyncReadyCallback to call
2171 * when the request is satisfied
2172 * @user_data: (closure): the data to pass to callback function
2174 * Asynchronously overwrites the file, replacing the contents,
2175 * possibly creating a backup copy of the file first.
2177 * For more details, see g_file_replace() which is
2178 * the synchronous version of this call.
2180 * When the operation is finished, @callback will be called.
2181 * You can then call g_file_replace_finish() to get the result
2185 g_file_replace_async (GFile
*file
,
2187 gboolean make_backup
,
2188 GFileCreateFlags flags
,
2190 GCancellable
*cancellable
,
2191 GAsyncReadyCallback callback
,
2196 g_return_if_fail (G_IS_FILE (file
));
2198 iface
= G_FILE_GET_IFACE (file
);
2199 (* iface
->replace_async
) (file
,
2210 * g_file_replace_finish:
2211 * @file: input #GFile
2212 * @res: a #GAsyncResult
2213 * @error: a #GError, or %NULL
2215 * Finishes an asynchronous file replace operation started with
2216 * g_file_replace_async().
2218 * Returns: (transfer full): a #GFileOutputStream, or %NULL on error.
2219 * Free the returned object with g_object_unref().
2222 g_file_replace_finish (GFile
*file
,
2228 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
2229 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), NULL
);
2231 if (g_async_result_legacy_propagate_error (res
, error
))
2234 iface
= G_FILE_GET_IFACE (file
);
2235 return (* iface
->replace_finish
) (file
, res
, error
);
2239 * g_file_open_readwrite_async
2240 * @file: input #GFile
2241 * @io_priority: the [I/O priority][io-priority] of the request
2242 * @cancellable: (allow-none): optional #GCancellable object,
2244 * @callback: (scope async): a #GAsyncReadyCallback to call
2245 * when the request is satisfied
2246 * @user_data: (closure): the data to pass to callback function
2248 * Asynchronously opens @file for reading and writing.
2250 * For more details, see g_file_open_readwrite() which is
2251 * the synchronous version of this call.
2253 * When the operation is finished, @callback will be called.
2254 * You can then call g_file_open_readwrite_finish() to get
2255 * the result of the operation.
2260 g_file_open_readwrite_async (GFile
*file
,
2262 GCancellable
*cancellable
,
2263 GAsyncReadyCallback callback
,
2268 g_return_if_fail (G_IS_FILE (file
));
2270 iface
= G_FILE_GET_IFACE (file
);
2271 (* iface
->open_readwrite_async
) (file
,
2279 * g_file_open_readwrite_finish:
2280 * @file: input #GFile
2281 * @res: a #GAsyncResult
2282 * @error: a #GError, or %NULL
2284 * Finishes an asynchronous file read operation started with
2285 * g_file_open_readwrite_async().
2287 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
2288 * Free the returned object with g_object_unref().
2293 g_file_open_readwrite_finish (GFile
*file
,
2299 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
2300 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), NULL
);
2302 if (g_async_result_legacy_propagate_error (res
, error
))
2305 iface
= G_FILE_GET_IFACE (file
);
2306 return (* iface
->open_readwrite_finish
) (file
, res
, error
);
2310 * g_file_create_readwrite_async:
2311 * @file: input #GFile
2312 * @flags: a set of #GFileCreateFlags
2313 * @io_priority: the [I/O priority][io-priority] of the request
2314 * @cancellable: (allow-none): optional #GCancellable object,
2316 * @callback: (scope async): a #GAsyncReadyCallback to call
2317 * when the request is satisfied
2318 * @user_data: (closure): the data to pass to callback function
2320 * Asynchronously creates a new file and returns a stream
2321 * for reading and writing to it. The file must not already exist.
2323 * For more details, see g_file_create_readwrite() which is
2324 * the synchronous version of this call.
2326 * When the operation is finished, @callback will be called.
2327 * You can then call g_file_create_readwrite_finish() to get
2328 * the result of the operation.
2333 g_file_create_readwrite_async (GFile
*file
,
2334 GFileCreateFlags flags
,
2336 GCancellable
*cancellable
,
2337 GAsyncReadyCallback callback
,
2342 g_return_if_fail (G_IS_FILE (file
));
2344 iface
= G_FILE_GET_IFACE (file
);
2345 (* iface
->create_readwrite_async
) (file
,
2354 * g_file_create_readwrite_finish:
2355 * @file: input #GFile
2356 * @res: a #GAsyncResult
2357 * @error: a #GError, or %NULL
2359 * Finishes an asynchronous file create operation started with
2360 * g_file_create_readwrite_async().
2362 * Returns: (transfer full): a #GFileIOStream or %NULL on error.
2363 * Free the returned object with g_object_unref().
2368 g_file_create_readwrite_finish (GFile
*file
,
2374 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
2375 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), NULL
);
2377 if (g_async_result_legacy_propagate_error (res
, error
))
2380 iface
= G_FILE_GET_IFACE (file
);
2381 return (* iface
->create_readwrite_finish
) (file
, res
, error
);
2385 * g_file_replace_readwrite_async:
2386 * @file: input #GFile
2387 * @etag: (allow-none): an [entity tag][gfile-etag] for the current #GFile,
2388 * or %NULL to ignore
2389 * @make_backup: %TRUE if a backup should be created
2390 * @flags: a set of #GFileCreateFlags
2391 * @io_priority: the [I/O priority][io-priority] of the request
2392 * @cancellable: (allow-none): optional #GCancellable object,
2394 * @callback: (scope async): a #GAsyncReadyCallback to call
2395 * when the request is satisfied
2396 * @user_data: (closure): the data to pass to callback function
2398 * Asynchronously overwrites the file in read-write mode,
2399 * replacing the contents, possibly creating a backup copy
2400 * of the file first.
2402 * For more details, see g_file_replace_readwrite() which is
2403 * the synchronous version of this call.
2405 * When the operation is finished, @callback will be called.
2406 * You can then call g_file_replace_readwrite_finish() to get
2407 * the result of the operation.
2412 g_file_replace_readwrite_async (GFile
*file
,
2414 gboolean make_backup
,
2415 GFileCreateFlags flags
,
2417 GCancellable
*cancellable
,
2418 GAsyncReadyCallback callback
,
2423 g_return_if_fail (G_IS_FILE (file
));
2425 iface
= G_FILE_GET_IFACE (file
);
2426 (* iface
->replace_readwrite_async
) (file
,
2437 * g_file_replace_readwrite_finish:
2438 * @file: input #GFile
2439 * @res: a #GAsyncResult
2440 * @error: a #GError, or %NULL
2442 * Finishes an asynchronous file replace operation started with
2443 * g_file_replace_readwrite_async().
2445 * Returns: (transfer full): a #GFileIOStream, or %NULL on error.
2446 * Free the returned object with g_object_unref().
2451 g_file_replace_readwrite_finish (GFile
*file
,
2457 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
2458 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), NULL
);
2460 if (g_async_result_legacy_propagate_error (res
, error
))
2463 iface
= G_FILE_GET_IFACE (file
);
2464 return (* iface
->replace_readwrite_finish
) (file
, res
, error
);
2468 copy_symlink (GFile
*destination
,
2469 GFileCopyFlags flags
,
2470 GCancellable
*cancellable
,
2475 gboolean tried_delete
;
2477 GFileType file_type
;
2479 tried_delete
= FALSE
;
2483 if (!g_file_make_symbolic_link (destination
, target
, cancellable
, &my_error
))
2485 /* Maybe it already existed, and we want to overwrite? */
2486 if (!tried_delete
&& (flags
& G_FILE_COPY_OVERWRITE
) &&
2487 my_error
->domain
== G_IO_ERROR
&& my_error
->code
== G_IO_ERROR_EXISTS
)
2489 g_clear_error (&my_error
);
2491 /* Don't overwrite if the destination is a directory */
2492 info
= g_file_query_info (destination
, G_FILE_ATTRIBUTE_STANDARD_TYPE
,
2493 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
,
2494 cancellable
, &my_error
);
2497 file_type
= g_file_info_get_file_type (info
);
2498 g_object_unref (info
);
2500 if (file_type
== G_FILE_TYPE_DIRECTORY
)
2502 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_IS_DIRECTORY
,
2503 _("Can't copy over directory"));
2508 if (!g_file_delete (destination
, cancellable
, error
))
2511 tried_delete
= TRUE
;
2515 g_propagate_error (error
, my_error
);
2522 static GFileInputStream
*
2523 open_source_for_copy (GFile
*source
,
2525 GFileCopyFlags flags
,
2526 GCancellable
*cancellable
,
2530 GFileInputStream
*ret
;
2532 GFileType file_type
;
2535 ret
= g_file_read (source
, cancellable
, &my_error
);
2539 /* There was an error opening the source, try to set a good error for it: */
2540 if (my_error
->domain
== G_IO_ERROR
&& my_error
->code
== G_IO_ERROR_IS_DIRECTORY
)
2542 /* The source is a directory, don't fail with WOULD_RECURSE immediately,
2543 * as that is less useful to the app. Better check for errors on the
2546 g_error_free (my_error
);
2549 info
= g_file_query_info (destination
, G_FILE_ATTRIBUTE_STANDARD_TYPE
,
2550 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
,
2551 cancellable
, &my_error
);
2553 g_file_info_has_attribute (info
, G_FILE_ATTRIBUTE_STANDARD_TYPE
))
2555 file_type
= g_file_info_get_file_type (info
);
2556 g_object_unref (info
);
2558 if (flags
& G_FILE_COPY_OVERWRITE
)
2560 if (file_type
== G_FILE_TYPE_DIRECTORY
)
2562 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_WOULD_MERGE
,
2563 _("Can't copy directory over directory"));
2566 /* continue to would_recurse error */
2570 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_EXISTS
,
2571 _("Target file exists"));
2577 /* Error getting info from target, return that error
2578 * (except for NOT_FOUND, which is no error here)
2580 g_clear_object (&info
);
2581 if (my_error
!= NULL
&& !g_error_matches (my_error
, G_IO_ERROR
, G_IO_ERROR_NOT_FOUND
))
2583 g_propagate_error (error
, my_error
);
2586 g_clear_error (&my_error
);
2589 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_WOULD_RECURSE
,
2590 _("Can't recursively copy directory"));
2594 g_propagate_error (error
, my_error
);
2599 should_copy (GFileAttributeInfo
*info
,
2600 gboolean copy_all_attributes
,
2601 gboolean skip_perms
)
2603 if (skip_perms
&& strcmp(info
->name
, "unix::mode") == 0)
2606 if (copy_all_attributes
)
2607 return info
->flags
& G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED
;
2608 return info
->flags
& G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE
;
2612 build_attribute_list_for_copy (GFile
*file
,
2613 GFileCopyFlags flags
,
2614 char **out_attributes
,
2615 GCancellable
*cancellable
,
2618 gboolean ret
= FALSE
;
2619 GFileAttributeInfoList
*attributes
= NULL
, *namespaces
= NULL
;
2623 gboolean copy_all_attributes
;
2624 gboolean skip_perms
;
2626 copy_all_attributes
= flags
& G_FILE_COPY_ALL_METADATA
;
2627 skip_perms
= (flags
& G_FILE_COPY_TARGET_DEFAULT_PERMS
) != 0;
2629 /* Ignore errors here, if the target supports no attributes there is
2630 * nothing to copy. We still honor the cancellable though.
2632 attributes
= g_file_query_settable_attributes (file
, cancellable
, NULL
);
2633 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
2636 namespaces
= g_file_query_writable_namespaces (file
, cancellable
, NULL
);
2637 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
2640 if (attributes
== NULL
&& namespaces
== NULL
)
2644 s
= g_string_new ("");
2648 for (i
= 0; i
< attributes
->n_infos
; i
++)
2650 if (should_copy (&attributes
->infos
[i
], copy_all_attributes
, skip_perms
))
2655 g_string_append_c (s
, ',');
2657 g_string_append (s
, attributes
->infos
[i
].name
);
2664 for (i
= 0; i
< namespaces
->n_infos
; i
++)
2666 if (should_copy (&namespaces
->infos
[i
], copy_all_attributes
, FALSE
))
2671 g_string_append_c (s
, ',');
2673 g_string_append (s
, namespaces
->infos
[i
].name
);
2674 g_string_append (s
, "::*");
2680 *out_attributes
= g_string_free (s
, FALSE
);
2684 g_string_free (s
, TRUE
);
2686 g_file_attribute_info_list_unref (attributes
);
2688 g_file_attribute_info_list_unref (namespaces
);
2694 * g_file_copy_attributes:
2695 * @source: a #GFile with attributes
2696 * @destination: a #GFile to copy attributes to
2697 * @flags: a set of #GFileCopyFlags
2698 * @cancellable: (allow-none): optional #GCancellable object,
2700 * @error: a #GError, %NULL to ignore
2702 * Copies the file attributes from @source to @destination.
2704 * Normally only a subset of the file attributes are copied,
2705 * those that are copies in a normal file copy operation
2706 * (which for instance does not include e.g. owner). However
2707 * if #G_FILE_COPY_ALL_METADATA is specified in @flags, then
2708 * all the metadata that is possible to copy is copied. This
2709 * is useful when implementing move by copy + delete source.
2711 * Returns: %TRUE if the attributes were copied successfully,
2715 g_file_copy_attributes (GFile
*source
,
2717 GFileCopyFlags flags
,
2718 GCancellable
*cancellable
,
2721 char *attrs_to_read
;
2724 gboolean source_nofollow_symlinks
;
2726 if (!build_attribute_list_for_copy (destination
, flags
, &attrs_to_read
,
2727 cancellable
, error
))
2730 source_nofollow_symlinks
= flags
& G_FILE_COPY_NOFOLLOW_SYMLINKS
;
2732 /* Ignore errors here, if we can't read some info (e.g. if it doesn't exist)
2733 * we just don't copy it.
2735 info
= g_file_query_info (source
, attrs_to_read
,
2736 source_nofollow_symlinks
? G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
:0,
2740 g_free (attrs_to_read
);
2745 res
= g_file_set_attributes_from_info (destination
,
2747 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
,
2750 g_object_unref (info
);
2757 copy_stream_with_progress (GInputStream
*in
,
2760 GCancellable
*cancellable
,
2761 GFileProgressCallback progress_callback
,
2762 gpointer progress_callback_data
,
2765 gssize n_read
, n_written
;
2766 goffset current_size
;
2767 char buffer
[1024*64], *p
;
2773 /* avoid performance impact of querying total size when it's not needed */
2774 if (progress_callback
)
2776 info
= g_file_input_stream_query_info (G_FILE_INPUT_STREAM (in
),
2777 G_FILE_ATTRIBUTE_STANDARD_SIZE
,
2781 if (g_file_info_has_attribute (info
, G_FILE_ATTRIBUTE_STANDARD_SIZE
))
2782 total_size
= g_file_info_get_size (info
);
2783 g_object_unref (info
);
2786 if (total_size
== -1)
2788 info
= g_file_query_info (source
,
2789 G_FILE_ATTRIBUTE_STANDARD_SIZE
,
2790 G_FILE_QUERY_INFO_NONE
,
2794 if (g_file_info_has_attribute (info
, G_FILE_ATTRIBUTE_STANDARD_SIZE
))
2795 total_size
= g_file_info_get_size (info
);
2796 g_object_unref (info
);
2801 if (total_size
== -1)
2808 n_read
= g_input_stream_read (in
, buffer
, sizeof (buffer
), cancellable
, error
);
2818 current_size
+= n_read
;
2823 n_written
= g_output_stream_write (out
, p
, n_read
, cancellable
, error
);
2824 if (n_written
== -1)
2831 n_read
-= n_written
;
2837 if (progress_callback
)
2838 progress_callback (current_size
, total_size
, progress_callback_data
);
2841 /* Make sure we send full copied size */
2842 if (progress_callback
)
2843 progress_callback (current_size
, total_size
, progress_callback_data
);
2851 do_splice (int fd_in
,
2856 long *bytes_transferd
,
2862 result
= splice (fd_in
, off_in
, fd_out
, off_out
, len
, SPLICE_F_MORE
);
2870 else if (errsv
== ENOSYS
|| errsv
== EINVAL
)
2871 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
2872 _("Splice not supported"));
2874 g_set_error (error
, G_IO_ERROR
,
2875 g_io_error_from_errno (errsv
),
2876 _("Error splicing file: %s"),
2877 g_strerror (errsv
));
2882 *bytes_transferd
= result
;
2887 splice_stream_with_progress (GInputStream
*in
,
2889 GCancellable
*cancellable
,
2890 GFileProgressCallback progress_callback
,
2891 gpointer progress_callback_data
,
2894 int buffer
[2] = { -1, -1 };
2901 fd_in
= g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (in
));
2902 fd_out
= g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (out
));
2904 if (!g_unix_open_pipe (buffer
, FD_CLOEXEC
, error
))
2908 /* avoid performance impact of querying total size when it's not needed */
2909 if (progress_callback
)
2913 if (fstat (fd_in
, &sbuf
) == 0)
2914 total_size
= sbuf
.st_size
;
2917 if (total_size
== -1)
2920 offset_in
= offset_out
= 0;
2927 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
2930 if (!do_splice (fd_in
, &offset_in
, buffer
[1], NULL
, 1024*64, &n_read
, error
))
2941 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
2944 if (!do_splice (buffer
[0], NULL
, fd_out
, &offset_out
, n_read
, &n_written
, error
))
2947 n_read
-= n_written
;
2950 if (progress_callback
)
2951 progress_callback (offset_in
, total_size
, progress_callback_data
);
2954 /* Make sure we send full copied size */
2955 if (progress_callback
)
2956 progress_callback (offset_in
, total_size
, progress_callback_data
);
2958 if (!g_close (buffer
[0], error
))
2961 if (!g_close (buffer
[1], error
))
2965 if (buffer
[0] != -1)
2966 (void) g_close (buffer
[0], NULL
);
2967 if (buffer
[1] != -1)
2968 (void) g_close (buffer
[1], NULL
);
2976 btrfs_reflink_with_progress (GInputStream
*in
,
2979 GCancellable
*cancellable
,
2980 GFileProgressCallback progress_callback
,
2981 gpointer progress_callback_data
,
2984 goffset source_size
;
2988 fd_in
= g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (in
));
2989 fd_out
= g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (out
));
2991 if (progress_callback
)
2992 source_size
= g_file_info_get_size (info
);
2994 /* Btrfs clone ioctl properties:
2995 * - Works at the inode level
2996 * - Doesn't work with directories
2997 * - Always follows symlinks (source and destination)
2999 * By the time we get here, *in and *out are both regular files */
3000 ret
= ioctl (fd_out
, BTRFS_IOC_CLONE
, fd_in
);
3005 g_set_error_literal (error
, G_IO_ERROR
,
3006 G_IO_ERROR_NOT_SUPPORTED
,
3007 _("Copy (reflink/clone) between mounts is not supported"));
3008 else if (errno
== EINVAL
)
3009 g_set_error_literal (error
, G_IO_ERROR
,
3010 G_IO_ERROR_NOT_SUPPORTED
,
3011 _("Copy (reflink/clone) is not supported or invalid"));
3013 /* Most probably something odd happened; retry with fallback */
3014 g_set_error_literal (error
, G_IO_ERROR
,
3015 G_IO_ERROR_NOT_SUPPORTED
,
3016 _("Copy (reflink/clone) is not supported or didn't work"));
3017 /* We retry with fallback for all error cases because Btrfs is currently
3018 * unstable, and so we can't trust it to do clone properly.
3019 * In addition, any hard errors here would cause the same failure in the
3020 * fallback manual copy as well. */
3024 /* Make sure we send full copied size */
3025 if (progress_callback
)
3026 progress_callback (source_size
, source_size
, progress_callback_data
);
3033 file_copy_fallback (GFile
*source
,
3035 GFileCopyFlags flags
,
3036 GCancellable
*cancellable
,
3037 GFileProgressCallback progress_callback
,
3038 gpointer progress_callback_data
,
3041 gboolean ret
= FALSE
;
3042 GFileInputStream
*file_in
= NULL
;
3043 GInputStream
*in
= NULL
;
3044 GOutputStream
*out
= NULL
;
3045 GFileInfo
*info
= NULL
;
3047 char *attrs_to_read
;
3048 gboolean do_set_attributes
= FALSE
;
3050 /* need to know the file type */
3051 info
= g_file_query_info (source
,
3052 G_FILE_ATTRIBUTE_STANDARD_TYPE
"," G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET
,
3053 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
,
3059 /* Maybe copy the symlink? */
3060 if ((flags
& G_FILE_COPY_NOFOLLOW_SYMLINKS
) &&
3061 g_file_info_get_file_type (info
) == G_FILE_TYPE_SYMBOLIC_LINK
)
3063 target
= g_file_info_get_symlink_target (info
);
3066 if (!copy_symlink (destination
, flags
, cancellable
, target
, error
))
3072 /* ... else fall back on a regular file copy */
3074 /* Handle "special" files (pipes, device nodes, ...)? */
3075 else if (g_file_info_get_file_type (info
) == G_FILE_TYPE_SPECIAL
)
3077 /* FIXME: could try to recreate device nodes and others? */
3078 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
3079 _("Can't copy special file"));
3083 /* Everything else should just fall back on a regular copy. */
3085 file_in
= open_source_for_copy (source
, destination
, flags
, cancellable
, error
);
3088 in
= G_INPUT_STREAM (file_in
);
3090 if (!build_attribute_list_for_copy (destination
, flags
, &attrs_to_read
,
3091 cancellable
, error
))
3094 if (attrs_to_read
!= NULL
)
3096 GError
*tmp_error
= NULL
;
3098 /* Ok, ditch the previous lightweight info (on Unix we just
3099 * called lstat()); at this point we gather all the information
3100 * we need about the source from the opened file descriptor.
3102 g_object_unref (info
);
3104 info
= g_file_input_stream_query_info (file_in
, attrs_to_read
,
3105 cancellable
, &tmp_error
);
3108 /* Not all gvfs backends implement query_info_on_read(), we
3109 * can just fall back to the pathname again.
3110 * https://bugzilla.gnome.org/706254
3112 if (g_error_matches (tmp_error
, G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
))
3114 g_clear_error (&tmp_error
);
3115 info
= g_file_query_info (source
, attrs_to_read
, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
,
3116 cancellable
, error
);
3120 g_free (attrs_to_read
);
3121 g_propagate_error (error
, tmp_error
);
3125 g_free (attrs_to_read
);
3129 do_set_attributes
= TRUE
;
3132 /* In the local file path, we pass down the source info which
3133 * includes things like unix::mode, to ensure that the target file
3134 * is not created with different permissions from the source file.
3136 * If a future API like g_file_replace_with_info() is added, switch
3137 * this code to use that.
3139 if (G_IS_LOCAL_FILE (destination
))
3141 if (flags
& G_FILE_COPY_OVERWRITE
)
3142 out
= (GOutputStream
*)_g_local_file_output_stream_replace (_g_local_file_get_filename (G_LOCAL_FILE (destination
)),
3144 flags
& G_FILE_COPY_BACKUP
,
3145 G_FILE_CREATE_REPLACE_DESTINATION
,
3147 cancellable
, error
);
3149 out
= (GOutputStream
*)_g_local_file_output_stream_create (_g_local_file_get_filename (G_LOCAL_FILE (destination
)),
3151 cancellable
, error
);
3153 else if (flags
& G_FILE_COPY_OVERWRITE
)
3155 out
= (GOutputStream
*)g_file_replace (destination
,
3157 flags
& G_FILE_COPY_BACKUP
,
3158 G_FILE_CREATE_REPLACE_DESTINATION
,
3159 cancellable
, error
);
3163 out
= (GOutputStream
*)g_file_create (destination
, 0, cancellable
, error
);
3170 if (G_IS_FILE_DESCRIPTOR_BASED (in
) && G_IS_FILE_DESCRIPTOR_BASED (out
))
3172 GError
*reflink_err
= NULL
;
3174 if (!btrfs_reflink_with_progress (in
, out
, info
, cancellable
,
3175 progress_callback
, progress_callback_data
,
3178 if (g_error_matches (reflink_err
, G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
))
3180 g_clear_error (&reflink_err
);
3184 g_propagate_error (error
, reflink_err
);
3197 if (G_IS_FILE_DESCRIPTOR_BASED (in
) && G_IS_FILE_DESCRIPTOR_BASED (out
))
3199 GError
*splice_err
= NULL
;
3201 if (!splice_stream_with_progress (in
, out
, cancellable
,
3202 progress_callback
, progress_callback_data
,
3205 if (g_error_matches (splice_err
, G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
))
3207 g_clear_error (&splice_err
);
3211 g_propagate_error (error
, splice_err
);
3224 /* A plain read/write loop */
3225 if (!copy_stream_with_progress (in
, out
, source
, cancellable
,
3226 progress_callback
, progress_callback_data
,
3234 /* Don't care about errors in source here */
3235 (void) g_input_stream_close (in
, cancellable
, NULL
);
3236 g_object_unref (in
);
3241 /* But write errors on close are bad! */
3242 if (!g_output_stream_close (out
, cancellable
, ret
? error
: NULL
))
3244 g_object_unref (out
);
3247 /* Ignore errors here. Failure to copy metadata is not a hard error */
3248 /* TODO: set these attributes /before/ we do the rename() on Unix */
3249 if (ret
&& do_set_attributes
)
3251 g_file_set_attributes_from_info (destination
,
3253 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
,
3258 g_clear_object (&info
);
3265 * @source: input #GFile
3266 * @destination: destination #GFile
3267 * @flags: set of #GFileCopyFlags
3268 * @cancellable: (allow-none): optional #GCancellable object,
3270 * @progress_callback: (allow-none) (scope call): function to callback with
3271 * progress information, or %NULL if progress information is not needed
3272 * @progress_callback_data: (closure): user data to pass to @progress_callback
3273 * @error: #GError to set on error, or %NULL
3275 * Copies the file @source to the location specified by @destination.
3276 * Can not handle recursive copies of directories.
3278 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
3279 * existing @destination file is overwritten.
3281 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
3282 * will be copied as symlinks, otherwise the target of the
3283 * @source symlink will be copied.
3285 * If @cancellable is not %NULL, then the operation can be cancelled by
3286 * triggering the cancellable object from another thread. If the operation
3287 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3289 * If @progress_callback is not %NULL, then the operation can be monitored
3290 * by setting this to a #GFileProgressCallback function.
3291 * @progress_callback_data will be passed to this function. It is guaranteed
3292 * that this callback will be called after all data has been transferred with
3293 * the total number of bytes copied during the operation.
3295 * If the @source file does not exist, then the %G_IO_ERROR_NOT_FOUND error
3296 * is returned, independent on the status of the @destination.
3298 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then
3299 * the error %G_IO_ERROR_EXISTS is returned.
3301 * If trying to overwrite a file over a directory, the %G_IO_ERROR_IS_DIRECTORY
3302 * error is returned. If trying to overwrite a directory with a directory the
3303 * %G_IO_ERROR_WOULD_MERGE error is returned.
3305 * If the source is a directory and the target does not exist, or
3306 * #G_FILE_COPY_OVERWRITE is specified and the target is a file, then the
3307 * %G_IO_ERROR_WOULD_RECURSE error is returned.
3309 * If you are interested in copying the #GFile object itself (not the on-disk
3310 * file), see g_file_dup().
3312 * Returns: %TRUE on success, %FALSE otherwise.
3315 g_file_copy (GFile
*source
,
3317 GFileCopyFlags flags
,
3318 GCancellable
*cancellable
,
3319 GFileProgressCallback progress_callback
,
3320 gpointer progress_callback_data
,
3327 g_return_val_if_fail (G_IS_FILE (source
), FALSE
);
3328 g_return_val_if_fail (G_IS_FILE (destination
), FALSE
);
3330 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
3333 iface
= G_FILE_GET_IFACE (destination
);
3337 res
= (* iface
->copy
) (source
, destination
,
3339 progress_callback
, progress_callback_data
,
3345 if (my_error
->domain
!= G_IO_ERROR
|| my_error
->code
!= G_IO_ERROR_NOT_SUPPORTED
)
3347 g_propagate_error (error
, my_error
);
3351 g_clear_error (&my_error
);
3354 /* If the types are different, and the destination method failed
3355 * also try the source method
3357 if (G_OBJECT_TYPE (source
) != G_OBJECT_TYPE (destination
))
3359 iface
= G_FILE_GET_IFACE (source
);
3364 res
= (* iface
->copy
) (source
, destination
,
3366 progress_callback
, progress_callback_data
,
3372 if (my_error
->domain
!= G_IO_ERROR
|| my_error
->code
!= G_IO_ERROR_NOT_SUPPORTED
)
3374 g_propagate_error (error
, my_error
);
3378 g_clear_error (&my_error
);
3382 return file_copy_fallback (source
, destination
, flags
, cancellable
,
3383 progress_callback
, progress_callback_data
,
3388 * g_file_copy_async: (skip)
3389 * @source: input #GFile
3390 * @destination: destination #GFile
3391 * @flags: set of #GFileCopyFlags
3392 * @io_priority: the [I/O priority][io-priority] of the request
3393 * @cancellable: (allow-none): optional #GCancellable object,
3395 * @progress_callback: (allow-none): function to callback with progress
3396 * information, or %NULL if progress information is not needed
3397 * @progress_callback_data: (closure): user data to pass to @progress_callback
3398 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
3399 * @user_data: the data to pass to callback function
3401 * Copies the file @source to the location specified by @destination
3402 * asynchronously. For details of the behaviour, see g_file_copy().
3404 * If @progress_callback is not %NULL, then that function that will be called
3405 * just like in g_file_copy(). The callback will run in the default main context
3406 * of the thread calling g_file_copy_async() — the same context as @callback is
3409 * When the operation is finished, @callback will be called. You can then call
3410 * g_file_copy_finish() to get the result of the operation.
3413 g_file_copy_async (GFile
*source
,
3415 GFileCopyFlags flags
,
3417 GCancellable
*cancellable
,
3418 GFileProgressCallback progress_callback
,
3419 gpointer progress_callback_data
,
3420 GAsyncReadyCallback callback
,
3425 g_return_if_fail (G_IS_FILE (source
));
3426 g_return_if_fail (G_IS_FILE (destination
));
3428 iface
= G_FILE_GET_IFACE (source
);
3429 (* iface
->copy_async
) (source
,
3435 progress_callback_data
,
3441 * g_file_copy_finish:
3442 * @file: input #GFile
3443 * @res: a #GAsyncResult
3444 * @error: a #GError, or %NULL
3446 * Finishes copying the file started with g_file_copy_async().
3448 * Returns: a %TRUE on success, %FALSE on error.
3451 g_file_copy_finish (GFile
*file
,
3457 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
3458 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), FALSE
);
3460 if (g_async_result_legacy_propagate_error (res
, error
))
3463 iface
= G_FILE_GET_IFACE (file
);
3464 return (* iface
->copy_finish
) (file
, res
, error
);
3469 * @source: #GFile pointing to the source location
3470 * @destination: #GFile pointing to the destination location
3471 * @flags: set of #GFileCopyFlags
3472 * @cancellable: (allow-none): optional #GCancellable object,
3474 * @progress_callback: (allow-none) (scope call): #GFileProgressCallback
3475 * function for updates
3476 * @progress_callback_data: (closure): gpointer to user data for
3477 * the callback function
3478 * @error: #GError for returning error conditions, or %NULL
3480 * Tries to move the file or directory @source to the location specified
3481 * by @destination. If native move operations are supported then this is
3482 * used, otherwise a copy + delete fallback is used. The native
3483 * implementation may support moving directories (for instance on moves
3484 * inside the same filesystem), but the fallback code does not.
3486 * If the flag #G_FILE_COPY_OVERWRITE is specified an already
3487 * existing @destination file is overwritten.
3489 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
3490 * will be copied as symlinks, otherwise the target of the
3491 * @source symlink will be copied.
3493 * If @cancellable is not %NULL, then the operation can be cancelled by
3494 * triggering the cancellable object from another thread. If the operation
3495 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3497 * If @progress_callback is not %NULL, then the operation can be monitored
3498 * by setting this to a #GFileProgressCallback function.
3499 * @progress_callback_data will be passed to this function. It is
3500 * guaranteed that this callback will be called after all data has been
3501 * transferred with the total number of bytes copied during the operation.
3503 * If the @source file does not exist, then the %G_IO_ERROR_NOT_FOUND
3504 * error is returned, independent on the status of the @destination.
3506 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists,
3507 * then the error %G_IO_ERROR_EXISTS is returned.
3509 * If trying to overwrite a file over a directory, the %G_IO_ERROR_IS_DIRECTORY
3510 * error is returned. If trying to overwrite a directory with a directory the
3511 * %G_IO_ERROR_WOULD_MERGE error is returned.
3513 * If the source is a directory and the target does not exist, or
3514 * #G_FILE_COPY_OVERWRITE is specified and the target is a file, then
3515 * the %G_IO_ERROR_WOULD_RECURSE error may be returned (if the native
3516 * move operation isn't available).
3518 * Returns: %TRUE on successful move, %FALSE otherwise.
3521 g_file_move (GFile
*source
,
3523 GFileCopyFlags flags
,
3524 GCancellable
*cancellable
,
3525 GFileProgressCallback progress_callback
,
3526 gpointer progress_callback_data
,
3533 g_return_val_if_fail (G_IS_FILE (source
), FALSE
);
3534 g_return_val_if_fail (G_IS_FILE (destination
), FALSE
);
3536 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
3539 iface
= G_FILE_GET_IFACE (destination
);
3543 res
= (* iface
->move
) (source
, destination
,
3545 progress_callback
, progress_callback_data
,
3551 if (my_error
->domain
!= G_IO_ERROR
|| my_error
->code
!= G_IO_ERROR_NOT_SUPPORTED
)
3553 g_propagate_error (error
, my_error
);
3558 /* If the types are different, and the destination method failed
3559 * also try the source method
3561 if (G_OBJECT_TYPE (source
) != G_OBJECT_TYPE (destination
))
3563 iface
= G_FILE_GET_IFACE (source
);
3568 res
= (* iface
->move
) (source
, destination
,
3570 progress_callback
, progress_callback_data
,
3576 if (my_error
->domain
!= G_IO_ERROR
|| my_error
->code
!= G_IO_ERROR_NOT_SUPPORTED
)
3578 g_propagate_error (error
, my_error
);
3584 if (flags
& G_FILE_COPY_NO_FALLBACK_FOR_MOVE
)
3586 g_set_error_literal (error
, G_IO_ERROR
,
3587 G_IO_ERROR_NOT_SUPPORTED
,
3588 _("Operation not supported"));
3592 flags
|= G_FILE_COPY_ALL_METADATA
;
3593 if (!g_file_copy (source
, destination
, flags
, cancellable
,
3594 progress_callback
, progress_callback_data
,
3598 return g_file_delete (source
, cancellable
, error
);
3602 * g_file_make_directory:
3603 * @file: input #GFile
3604 * @cancellable: (allow-none): optional #GCancellable object,
3606 * @error: a #GError, or %NULL
3608 * Creates a directory. Note that this will only create a child directory
3609 * of the immediate parent directory of the path or URI given by the #GFile.
3610 * To recursively create directories, see g_file_make_directory_with_parents().
3611 * This function will fail if the parent directory does not exist, setting
3612 * @error to %G_IO_ERROR_NOT_FOUND. If the file system doesn't support
3613 * creating directories, this function will fail, setting @error to
3614 * %G_IO_ERROR_NOT_SUPPORTED.
3616 * For a local #GFile the newly created directory will have the default
3617 * (current) ownership and permissions of the current process.
3619 * If @cancellable is not %NULL, then the operation can be cancelled by
3620 * triggering the cancellable object from another thread. If the operation
3621 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3623 * Returns: %TRUE on successful creation, %FALSE otherwise.
3626 g_file_make_directory (GFile
*file
,
3627 GCancellable
*cancellable
,
3632 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
3634 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
3637 iface
= G_FILE_GET_IFACE (file
);
3639 if (iface
->make_directory
== NULL
)
3641 g_set_error_literal (error
, G_IO_ERROR
,
3642 G_IO_ERROR_NOT_SUPPORTED
,
3643 _("Operation not supported"));
3647 return (* iface
->make_directory
) (file
, cancellable
, error
);
3651 * g_file_make_directory_async:
3652 * @file: input #GFile
3653 * @io_priority: the [I/O priority][io-priority] of the request
3654 * @cancellable: (allow-none): optional #GCancellable object,
3656 * @callback: a #GAsyncReadyCallback to call
3657 * when the request is satisfied
3658 * @user_data: the data to pass to callback function
3660 * Asynchronously creates a directory.
3662 * Virtual: make_directory_async
3666 g_file_make_directory_async (GFile
*file
,
3668 GCancellable
*cancellable
,
3669 GAsyncReadyCallback callback
,
3674 g_return_if_fail (G_IS_FILE (file
));
3676 iface
= G_FILE_GET_IFACE (file
);
3677 (* iface
->make_directory_async
) (file
,
3685 * g_file_make_directory_finish:
3686 * @file: input #GFile
3687 * @result: a #GAsyncResult
3688 * @error: a #GError, or %NULL
3690 * Finishes an asynchronous directory creation, started with
3691 * g_file_make_directory_async().
3693 * Virtual: make_directory_finish
3694 * Returns: %TRUE on successful directory creation, %FALSE otherwise.
3698 g_file_make_directory_finish (GFile
*file
,
3699 GAsyncResult
*result
,
3704 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
3705 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
3707 iface
= G_FILE_GET_IFACE (file
);
3708 return (* iface
->make_directory_finish
) (file
, result
, error
);
3712 * g_file_make_directory_with_parents:
3713 * @file: input #GFile
3714 * @cancellable: (allow-none): optional #GCancellable object,
3716 * @error: a #GError, or %NULL
3718 * Creates a directory and any parent directories that may not
3719 * exist similar to 'mkdir -p'. If the file system does not support
3720 * creating directories, this function will fail, setting @error to
3721 * %G_IO_ERROR_NOT_SUPPORTED. If the directory itself already exists,
3722 * this function will fail setting @error to %G_IO_ERROR_EXISTS, unlike
3723 * the similar g_mkdir_with_parents().
3725 * For a local #GFile the newly created directories will have the default
3726 * (current) ownership and permissions of the current process.
3728 * If @cancellable is not %NULL, then the operation can be cancelled by
3729 * triggering the cancellable object from another thread. If the operation
3730 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3732 * Returns: %TRUE if all directories have been successfully created, %FALSE
3738 g_file_make_directory_with_parents (GFile
*file
,
3739 GCancellable
*cancellable
,
3742 GFile
*work_file
= NULL
;
3743 GList
*list
= NULL
, *l
;
3744 GError
*my_error
= NULL
;
3746 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
3748 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
3751 g_file_make_directory (file
, cancellable
, &my_error
);
3752 if (my_error
== NULL
|| my_error
->code
!= G_IO_ERROR_NOT_FOUND
)
3755 g_propagate_error (error
, my_error
);
3756 return my_error
== NULL
;
3759 work_file
= g_object_ref (file
);
3761 while (my_error
!= NULL
&& my_error
->code
== G_IO_ERROR_NOT_FOUND
)
3765 parent_file
= g_file_get_parent (work_file
);
3766 if (parent_file
== NULL
)
3769 g_clear_error (&my_error
);
3770 g_file_make_directory (parent_file
, cancellable
, &my_error
);
3772 g_object_unref (work_file
);
3773 work_file
= g_object_ref (parent_file
);
3775 if (my_error
!= NULL
&& my_error
->code
== G_IO_ERROR_NOT_FOUND
)
3776 list
= g_list_prepend (list
, parent_file
); /* Transfer ownership of ref */
3778 g_object_unref (parent_file
);
3781 for (l
= list
; my_error
== NULL
&& l
; l
= l
->next
)
3783 g_file_make_directory ((GFile
*) l
->data
, cancellable
, &my_error
);
3787 g_object_unref (work_file
);
3790 while (list
!= NULL
)
3792 g_object_unref ((GFile
*) list
->data
);
3793 list
= g_list_remove (list
, list
->data
);
3796 if (my_error
!= NULL
)
3798 g_propagate_error (error
, my_error
);
3802 return g_file_make_directory (file
, cancellable
, error
);
3806 * g_file_make_symbolic_link:
3807 * @file: a #GFile with the name of the symlink to create
3808 * @symlink_value: a string with the path for the target of the new symlink
3809 * @cancellable: (allow-none): optional #GCancellable object,
3813 * Creates a symbolic link named @file which contains the string
3816 * If @cancellable is not %NULL, then the operation can be cancelled by
3817 * triggering the cancellable object from another thread. If the operation
3818 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3820 * Returns: %TRUE on the creation of a new symlink, %FALSE otherwise.
3823 g_file_make_symbolic_link (GFile
*file
,
3824 const char *symlink_value
,
3825 GCancellable
*cancellable
,
3830 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
3831 g_return_val_if_fail (symlink_value
!= NULL
, FALSE
);
3833 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
3836 if (*symlink_value
== '\0')
3838 g_set_error_literal (error
, G_IO_ERROR
,
3839 G_IO_ERROR_INVALID_ARGUMENT
,
3840 _("Invalid symlink value given"));
3844 iface
= G_FILE_GET_IFACE (file
);
3846 if (iface
->make_symbolic_link
== NULL
)
3848 g_set_error_literal (error
, G_IO_ERROR
,
3849 G_IO_ERROR_NOT_SUPPORTED
,
3850 _("Operation not supported"));
3854 return (* iface
->make_symbolic_link
) (file
, symlink_value
, cancellable
, error
);
3859 * @file: input #GFile
3860 * @cancellable: (allow-none): optional #GCancellable object,
3862 * @error: a #GError, or %NULL
3864 * Deletes a file. If the @file is a directory, it will only be
3865 * deleted if it is empty. This has the same semantics as g_unlink().
3867 * If @cancellable is not %NULL, then the operation can be cancelled by
3868 * triggering the cancellable object from another thread. If the operation
3869 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3871 * Virtual: delete_file
3872 * Returns: %TRUE if the file was deleted. %FALSE otherwise.
3875 g_file_delete (GFile
*file
,
3876 GCancellable
*cancellable
,
3881 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
3883 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
3886 iface
= G_FILE_GET_IFACE (file
);
3888 if (iface
->delete_file
== NULL
)
3890 g_set_error_literal (error
, G_IO_ERROR
,
3891 G_IO_ERROR_NOT_SUPPORTED
,
3892 _("Operation not supported"));
3896 return (* iface
->delete_file
) (file
, cancellable
, error
);
3900 * g_file_delete_async:
3901 * @file: input #GFile
3902 * @io_priority: the [I/O priority][io-priority] of the request
3903 * @cancellable: (allow-none): optional #GCancellable object,
3905 * @callback: a #GAsyncReadyCallback to call
3906 * when the request is satisfied
3907 * @user_data: the data to pass to callback function
3909 * Asynchronously delete a file. If the @file is a directory, it will
3910 * only be deleted if it is empty. This has the same semantics as
3913 * Virtual: delete_file_async
3917 g_file_delete_async (GFile
*file
,
3919 GCancellable
*cancellable
,
3920 GAsyncReadyCallback callback
,
3925 g_return_if_fail (G_IS_FILE (file
));
3927 iface
= G_FILE_GET_IFACE (file
);
3928 (* iface
->delete_file_async
) (file
,
3936 * g_file_delete_finish:
3937 * @file: input #GFile
3938 * @result: a #GAsyncResult
3939 * @error: a #GError, or %NULL
3941 * Finishes deleting a file started with g_file_delete_async().
3943 * Virtual: delete_file_finish
3944 * Returns: %TRUE if the file was deleted. %FALSE otherwise.
3948 g_file_delete_finish (GFile
*file
,
3949 GAsyncResult
*result
,
3954 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
3955 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
3957 if (g_async_result_legacy_propagate_error (result
, error
))
3960 iface
= G_FILE_GET_IFACE (file
);
3961 return (* iface
->delete_file_finish
) (file
, result
, error
);
3966 * @file: #GFile to send to trash
3967 * @cancellable: (allow-none): optional #GCancellable object,
3969 * @error: a #GError, or %NULL
3971 * Sends @file to the "Trashcan", if possible. This is similar to
3972 * deleting it, but the user can recover it before emptying the trashcan.
3973 * Not all file systems support trashing, so this call can return the
3974 * %G_IO_ERROR_NOT_SUPPORTED error.
3976 * If @cancellable is not %NULL, then the operation can be cancelled by
3977 * triggering the cancellable object from another thread. If the operation
3978 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
3981 * Returns: %TRUE on successful trash, %FALSE otherwise.
3984 g_file_trash (GFile
*file
,
3985 GCancellable
*cancellable
,
3990 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
3992 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
3995 iface
= G_FILE_GET_IFACE (file
);
3997 if (iface
->trash
== NULL
)
3999 g_set_error_literal (error
,
4000 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
4001 _("Trash not supported"));
4005 return (* iface
->trash
) (file
, cancellable
, error
);
4009 * g_file_trash_async:
4010 * @file: input #GFile
4011 * @io_priority: the [I/O priority][io-priority] of the request
4012 * @cancellable: (allow-none): optional #GCancellable object,
4014 * @callback: a #GAsyncReadyCallback to call
4015 * when the request is satisfied
4016 * @user_data: the data to pass to callback function
4018 * Asynchronously sends @file to the Trash location, if possible.
4020 * Virtual: trash_async
4024 g_file_trash_async (GFile
*file
,
4026 GCancellable
*cancellable
,
4027 GAsyncReadyCallback callback
,
4032 g_return_if_fail (G_IS_FILE (file
));
4034 iface
= G_FILE_GET_IFACE (file
);
4035 (* iface
->trash_async
) (file
,
4043 * g_file_trash_finish:
4044 * @file: input #GFile
4045 * @result: a #GAsyncResult
4046 * @error: a #GError, or %NULL
4048 * Finishes an asynchronous file trashing operation, started with
4049 * g_file_trash_async().
4051 * Virtual: trash_finish
4052 * Returns: %TRUE on successful trash, %FALSE otherwise.
4056 g_file_trash_finish (GFile
*file
,
4057 GAsyncResult
*result
,
4062 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
4063 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
4065 iface
= G_FILE_GET_IFACE (file
);
4066 return (* iface
->trash_finish
) (file
, result
, error
);
4070 * g_file_set_display_name:
4071 * @file: input #GFile
4072 * @display_name: a string
4073 * @cancellable: (allow-none): optional #GCancellable object,
4075 * @error: a #GError, or %NULL
4077 * Renames @file to the specified display name.
4079 * The display name is converted from UTF-8 to the correct encoding
4080 * for the target filesystem if possible and the @file is renamed to this.
4082 * If you want to implement a rename operation in the user interface the
4083 * edit name (#G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the
4084 * initial value in the rename widget, and then the result after editing
4085 * should be passed to g_file_set_display_name().
4087 * On success the resulting converted filename is returned.
4089 * If @cancellable is not %NULL, then the operation can be cancelled by
4090 * triggering the cancellable object from another thread. If the operation
4091 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4093 * Returns: (transfer full): a #GFile specifying what @file was renamed to,
4094 * or %NULL if there was an error.
4095 * Free the returned object with g_object_unref().
4098 g_file_set_display_name (GFile
*file
,
4099 const gchar
*display_name
,
4100 GCancellable
*cancellable
,
4105 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
4106 g_return_val_if_fail (display_name
!= NULL
, NULL
);
4108 if (strchr (display_name
, G_DIR_SEPARATOR
) != NULL
)
4112 G_IO_ERROR_INVALID_ARGUMENT
,
4113 _("File names cannot contain '%c'"), G_DIR_SEPARATOR
);
4117 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
4120 iface
= G_FILE_GET_IFACE (file
);
4122 return (* iface
->set_display_name
) (file
, display_name
, cancellable
, error
);
4126 * g_file_set_display_name_async:
4127 * @file: input #GFile
4128 * @display_name: a string
4129 * @io_priority: the [I/O priority][io-priority] of the request
4130 * @cancellable: (allow-none): optional #GCancellable object,
4132 * @callback: (scope async): a #GAsyncReadyCallback to call
4133 * when the request is satisfied
4134 * @user_data: (closure): the data to pass to callback function
4136 * Asynchronously sets the display name for a given #GFile.
4138 * For more details, see g_file_set_display_name() which is
4139 * the synchronous version of this call.
4141 * When the operation is finished, @callback will be called.
4142 * You can then call g_file_set_display_name_finish() to get
4143 * the result of the operation.
4146 g_file_set_display_name_async (GFile
*file
,
4147 const gchar
*display_name
,
4149 GCancellable
*cancellable
,
4150 GAsyncReadyCallback callback
,
4155 g_return_if_fail (G_IS_FILE (file
));
4156 g_return_if_fail (display_name
!= NULL
);
4158 iface
= G_FILE_GET_IFACE (file
);
4159 (* iface
->set_display_name_async
) (file
,
4168 * g_file_set_display_name_finish:
4169 * @file: input #GFile
4170 * @res: a #GAsyncResult
4171 * @error: a #GError, or %NULL
4173 * Finishes setting a display name started with
4174 * g_file_set_display_name_async().
4176 * Returns: (transfer full): a #GFile or %NULL on error.
4177 * Free the returned object with g_object_unref().
4180 g_file_set_display_name_finish (GFile
*file
,
4186 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
4187 g_return_val_if_fail (G_IS_ASYNC_RESULT (res
), NULL
);
4189 if (g_async_result_legacy_propagate_error (res
, error
))
4192 iface
= G_FILE_GET_IFACE (file
);
4193 return (* iface
->set_display_name_finish
) (file
, res
, error
);
4197 * g_file_query_settable_attributes:
4198 * @file: input #GFile
4199 * @cancellable: (allow-none): optional #GCancellable object,
4201 * @error: a #GError, or %NULL
4203 * Obtain the list of settable attributes for the file.
4205 * Returns the type and full attribute name of all the attributes
4206 * that can be set on this file. This doesn't mean setting it will
4207 * always succeed though, you might get an access failure, or some
4208 * specific file may not support a specific attribute.
4210 * If @cancellable is not %NULL, then the operation can be cancelled by
4211 * triggering the cancellable object from another thread. If the operation
4212 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4214 * Returns: a #GFileAttributeInfoList describing the settable attributes.
4215 * When you are done with it, release it with
4216 * g_file_attribute_info_list_unref()
4218 GFileAttributeInfoList
*
4219 g_file_query_settable_attributes (GFile
*file
,
4220 GCancellable
*cancellable
,
4225 GFileAttributeInfoList
*list
;
4227 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
4229 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
4232 iface
= G_FILE_GET_IFACE (file
);
4234 if (iface
->query_settable_attributes
== NULL
)
4235 return g_file_attribute_info_list_new ();
4238 list
= (* iface
->query_settable_attributes
) (file
, cancellable
, &my_error
);
4242 if (my_error
->domain
== G_IO_ERROR
&& my_error
->code
== G_IO_ERROR_NOT_SUPPORTED
)
4244 list
= g_file_attribute_info_list_new ();
4245 g_error_free (my_error
);
4248 g_propagate_error (error
, my_error
);
4255 * g_file_query_writable_namespaces:
4256 * @file: input #GFile
4257 * @cancellable: (allow-none): optional #GCancellable object,
4259 * @error: a #GError, or %NULL
4261 * Obtain the list of attribute namespaces where new attributes
4262 * can be created by a user. An example of this is extended
4263 * attributes (in the "xattr" namespace).
4265 * If @cancellable is not %NULL, then the operation can be cancelled by
4266 * triggering the cancellable object from another thread. If the operation
4267 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4269 * Returns: a #GFileAttributeInfoList describing the writable namespaces.
4270 * When you are done with it, release it with
4271 * g_file_attribute_info_list_unref()
4273 GFileAttributeInfoList
*
4274 g_file_query_writable_namespaces (GFile
*file
,
4275 GCancellable
*cancellable
,
4280 GFileAttributeInfoList
*list
;
4282 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
4284 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
4287 iface
= G_FILE_GET_IFACE (file
);
4289 if (iface
->query_writable_namespaces
== NULL
)
4290 return g_file_attribute_info_list_new ();
4293 list
= (* iface
->query_writable_namespaces
) (file
, cancellable
, &my_error
);
4297 if (my_error
->domain
== G_IO_ERROR
&& my_error
->code
== G_IO_ERROR_NOT_SUPPORTED
)
4299 list
= g_file_attribute_info_list_new ();
4300 g_error_free (my_error
);
4303 g_propagate_error (error
, my_error
);
4310 * g_file_set_attribute:
4311 * @file: input #GFile
4312 * @attribute: a string containing the attribute's name
4313 * @type: The type of the attribute
4314 * @value_p: (allow-none): a pointer to the value (or the pointer
4315 * itself if the type is a pointer type)
4316 * @flags: a set of #GFileQueryInfoFlags
4317 * @cancellable: (allow-none): optional #GCancellable object,
4319 * @error: a #GError, or %NULL
4321 * Sets an attribute in the file with attribute name @attribute to @value.
4323 * Some attributes can be unset by setting @attribute to
4324 * %G_FILE_ATTRIBUTE_TYPE_INVALID and @value_p to %NULL.
4326 * If @cancellable is not %NULL, then the operation can be cancelled by
4327 * triggering the cancellable object from another thread. If the operation
4328 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4330 * Returns: %TRUE if the attribute was set, %FALSE otherwise.
4333 g_file_set_attribute (GFile
*file
,
4334 const gchar
*attribute
,
4335 GFileAttributeType type
,
4337 GFileQueryInfoFlags flags
,
4338 GCancellable
*cancellable
,
4343 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
4344 g_return_val_if_fail (attribute
!= NULL
&& *attribute
!= '\0', FALSE
);
4346 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
4349 iface
= G_FILE_GET_IFACE (file
);
4351 if (iface
->set_attribute
== NULL
)
4353 g_set_error_literal (error
, G_IO_ERROR
,
4354 G_IO_ERROR_NOT_SUPPORTED
,
4355 _("Operation not supported"));
4359 return (* iface
->set_attribute
) (file
, attribute
, type
, value_p
, flags
, cancellable
, error
);
4363 * g_file_set_attributes_from_info:
4364 * @file: input #GFile
4365 * @info: a #GFileInfo
4366 * @flags: #GFileQueryInfoFlags
4367 * @cancellable: (allow-none): optional #GCancellable object,
4369 * @error: a #GError, or %NULL
4371 * Tries to set all attributes in the #GFileInfo on the target
4372 * values, not stopping on the first error.
4374 * If there is any error during this operation then @error will
4375 * be set to the first error. Error on particular fields are flagged
4376 * by setting the "status" field in the attribute value to
4377 * %G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can
4378 * also detect further errors.
4380 * If @cancellable is not %NULL, then the operation can be cancelled by
4381 * triggering the cancellable object from another thread. If the operation
4382 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4384 * Returns: %FALSE if there was any error, %TRUE otherwise.
4387 g_file_set_attributes_from_info (GFile
*file
,
4389 GFileQueryInfoFlags flags
,
4390 GCancellable
*cancellable
,
4395 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
4396 g_return_val_if_fail (G_IS_FILE_INFO (info
), FALSE
);
4398 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
4401 g_file_info_clear_status (info
);
4403 iface
= G_FILE_GET_IFACE (file
);
4405 return (* iface
->set_attributes_from_info
) (file
,
4413 g_file_real_set_attributes_from_info (GFile
*file
,
4415 GFileQueryInfoFlags flags
,
4416 GCancellable
*cancellable
,
4422 GFileAttributeValue
*value
;
4426 attributes
= g_file_info_list_attributes (info
, NULL
);
4428 for (i
= 0; attributes
[i
] != NULL
; i
++)
4430 value
= _g_file_info_get_attribute_value (info
, attributes
[i
]);
4432 if (value
->status
!= G_FILE_ATTRIBUTE_STATUS_UNSET
)
4435 if (!g_file_set_attribute (file
, attributes
[i
],
4436 value
->type
, _g_file_attribute_value_peek_as_pointer (value
),
4437 flags
, cancellable
, error
))
4439 value
->status
= G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
;
4441 /* Don't set error multiple times */
4445 value
->status
= G_FILE_ATTRIBUTE_STATUS_SET
;
4448 g_strfreev (attributes
);
4454 * g_file_set_attributes_async:
4455 * @file: input #GFile
4456 * @info: a #GFileInfo
4457 * @flags: a #GFileQueryInfoFlags
4458 * @io_priority: the [I/O priority][io-priority] of the request
4459 * @cancellable: (allow-none): optional #GCancellable object,
4461 * @callback: (scope async): a #GAsyncReadyCallback
4462 * @user_data: (closure): a #gpointer
4464 * Asynchronously sets the attributes of @file with @info.
4466 * For more details, see g_file_set_attributes_from_info(),
4467 * which is the synchronous version of this call.
4469 * When the operation is finished, @callback will be called.
4470 * You can then call g_file_set_attributes_finish() to get
4471 * the result of the operation.
4474 g_file_set_attributes_async (GFile
*file
,
4476 GFileQueryInfoFlags flags
,
4478 GCancellable
*cancellable
,
4479 GAsyncReadyCallback callback
,
4484 g_return_if_fail (G_IS_FILE (file
));
4485 g_return_if_fail (G_IS_FILE_INFO (info
));
4487 iface
= G_FILE_GET_IFACE (file
);
4488 (* iface
->set_attributes_async
) (file
,
4498 * g_file_set_attributes_finish:
4499 * @file: input #GFile
4500 * @result: a #GAsyncResult
4501 * @info: (out) (transfer full): a #GFileInfo
4502 * @error: a #GError, or %NULL
4504 * Finishes setting an attribute started in g_file_set_attributes_async().
4506 * Returns: %TRUE if the attributes were set correctly, %FALSE otherwise.
4509 g_file_set_attributes_finish (GFile
*file
,
4510 GAsyncResult
*result
,
4516 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
4517 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
4519 /* No standard handling of errors here, as we must set info even
4522 iface
= G_FILE_GET_IFACE (file
);
4523 return (* iface
->set_attributes_finish
) (file
, result
, info
, error
);
4527 * g_file_set_attribute_string:
4528 * @file: input #GFile
4529 * @attribute: a string containing the attribute's name
4530 * @value: a string containing the attribute's value
4531 * @flags: #GFileQueryInfoFlags
4532 * @cancellable: (allow-none): optional #GCancellable object,
4534 * @error: a #GError, or %NULL
4536 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value.
4537 * If @attribute is of a different type, this operation will fail.
4539 * If @cancellable is not %NULL, then the operation can be cancelled by
4540 * triggering the cancellable object from another thread. If the operation
4541 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4543 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
4546 g_file_set_attribute_string (GFile
*file
,
4547 const char *attribute
,
4549 GFileQueryInfoFlags flags
,
4550 GCancellable
*cancellable
,
4553 return g_file_set_attribute (file
, attribute
,
4554 G_FILE_ATTRIBUTE_TYPE_STRING
, (gpointer
)value
,
4555 flags
, cancellable
, error
);
4559 * g_file_set_attribute_byte_string:
4560 * @file: input #GFile
4561 * @attribute: a string containing the attribute's name
4562 * @value: a string containing the attribute's new value
4563 * @flags: a #GFileQueryInfoFlags
4564 * @cancellable: (allow-none): optional #GCancellable object,
4566 * @error: a #GError, or %NULL
4568 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value.
4569 * If @attribute is of a different type, this operation will fail,
4572 * If @cancellable is not %NULL, then the operation can be cancelled by
4573 * triggering the cancellable object from another thread. If the operation
4574 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4576 * Returns: %TRUE if the @attribute was successfully set to @value
4577 * in the @file, %FALSE otherwise.
4580 g_file_set_attribute_byte_string (GFile
*file
,
4581 const gchar
*attribute
,
4583 GFileQueryInfoFlags flags
,
4584 GCancellable
*cancellable
,
4587 return g_file_set_attribute (file
, attribute
,
4588 G_FILE_ATTRIBUTE_TYPE_BYTE_STRING
, (gpointer
)value
,
4589 flags
, cancellable
, error
);
4593 * g_file_set_attribute_uint32:
4594 * @file: input #GFile
4595 * @attribute: a string containing the attribute's name
4596 * @value: a #guint32 containing the attribute's new value
4597 * @flags: a #GFileQueryInfoFlags
4598 * @cancellable: (allow-none): optional #GCancellable object,
4600 * @error: a #GError, or %NULL
4602 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value.
4603 * If @attribute is of a different type, this operation will fail.
4605 * If @cancellable is not %NULL, then the operation can be cancelled by
4606 * triggering the cancellable object from another thread. If the operation
4607 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4609 * Returns: %TRUE if the @attribute was successfully set to @value
4610 * in the @file, %FALSE otherwise.
4613 g_file_set_attribute_uint32 (GFile
*file
,
4614 const gchar
*attribute
,
4616 GFileQueryInfoFlags flags
,
4617 GCancellable
*cancellable
,
4620 return g_file_set_attribute (file
, attribute
,
4621 G_FILE_ATTRIBUTE_TYPE_UINT32
, &value
,
4622 flags
, cancellable
, error
);
4626 * g_file_set_attribute_int32:
4627 * @file: input #GFile
4628 * @attribute: a string containing the attribute's name
4629 * @value: a #gint32 containing the attribute's new value
4630 * @flags: a #GFileQueryInfoFlags
4631 * @cancellable: (allow-none): optional #GCancellable object,
4633 * @error: a #GError, or %NULL
4635 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value.
4636 * If @attribute is of a different type, this operation will fail.
4638 * If @cancellable is not %NULL, then the operation can be cancelled by
4639 * triggering the cancellable object from another thread. If the operation
4640 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4642 * Returns: %TRUE if the @attribute was successfully set to @value
4643 * in the @file, %FALSE otherwise.
4646 g_file_set_attribute_int32 (GFile
*file
,
4647 const gchar
*attribute
,
4649 GFileQueryInfoFlags flags
,
4650 GCancellable
*cancellable
,
4653 return g_file_set_attribute (file
, attribute
,
4654 G_FILE_ATTRIBUTE_TYPE_INT32
, &value
,
4655 flags
, cancellable
, error
);
4659 * g_file_set_attribute_uint64:
4660 * @file: input #GFile
4661 * @attribute: a string containing the attribute's name
4662 * @value: a #guint64 containing the attribute's new value
4663 * @flags: a #GFileQueryInfoFlags
4664 * @cancellable: (allow-none): optional #GCancellable object,
4666 * @error: a #GError, or %NULL
4668 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value.
4669 * If @attribute is of a different type, this operation will fail.
4671 * If @cancellable is not %NULL, then the operation can be cancelled by
4672 * triggering the cancellable object from another thread. If the operation
4673 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4675 * Returns: %TRUE if the @attribute was successfully set to @value
4676 * in the @file, %FALSE otherwise.
4679 g_file_set_attribute_uint64 (GFile
*file
,
4680 const gchar
*attribute
,
4682 GFileQueryInfoFlags flags
,
4683 GCancellable
*cancellable
,
4686 return g_file_set_attribute (file
, attribute
,
4687 G_FILE_ATTRIBUTE_TYPE_UINT64
, &value
,
4688 flags
, cancellable
, error
);
4692 * g_file_set_attribute_int64:
4693 * @file: input #GFile
4694 * @attribute: a string containing the attribute's name
4695 * @value: a #guint64 containing the attribute's new value
4696 * @flags: a #GFileQueryInfoFlags
4697 * @cancellable: (allow-none): optional #GCancellable object,
4699 * @error: a #GError, or %NULL
4701 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value.
4702 * If @attribute is of a different type, this operation will fail.
4704 * If @cancellable is not %NULL, then the operation can be cancelled by
4705 * triggering the cancellable object from another thread. If the operation
4706 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4708 * Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
4711 g_file_set_attribute_int64 (GFile
*file
,
4712 const gchar
*attribute
,
4714 GFileQueryInfoFlags flags
,
4715 GCancellable
*cancellable
,
4718 return g_file_set_attribute (file
, attribute
,
4719 G_FILE_ATTRIBUTE_TYPE_INT64
, &value
,
4720 flags
, cancellable
, error
);
4724 * g_file_mount_mountable:
4725 * @file: input #GFile
4726 * @flags: flags affecting the operation
4727 * @mount_operation: (allow-none): a #GMountOperation,
4728 * or %NULL to avoid user interaction
4729 * @cancellable: (allow-none): optional #GCancellable object,
4731 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call
4732 * when the request is satisfied, or %NULL
4733 * @user_data: (closure): the data to pass to callback function
4735 * Mounts a file of type G_FILE_TYPE_MOUNTABLE.
4736 * Using @mount_operation, you can request callbacks when, for instance,
4737 * passwords are needed during authentication.
4739 * If @cancellable is not %NULL, then the operation can be cancelled by
4740 * triggering the cancellable object from another thread. If the operation
4741 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4743 * When the operation is finished, @callback will be called.
4744 * You can then call g_file_mount_mountable_finish() to get
4745 * the result of the operation.
4748 g_file_mount_mountable (GFile
*file
,
4749 GMountMountFlags flags
,
4750 GMountOperation
*mount_operation
,
4751 GCancellable
*cancellable
,
4752 GAsyncReadyCallback callback
,
4757 g_return_if_fail (G_IS_FILE (file
));
4759 iface
= G_FILE_GET_IFACE (file
);
4761 if (iface
->mount_mountable
== NULL
)
4763 g_task_report_new_error (file
, callback
, user_data
,
4764 g_file_mount_mountable
,
4765 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
4766 _("Operation not supported"));
4770 (* iface
->mount_mountable
) (file
,
4779 * g_file_mount_mountable_finish:
4780 * @file: input #GFile
4781 * @result: a #GAsyncResult
4782 * @error: a #GError, or %NULL
4784 * Finishes a mount operation. See g_file_mount_mountable() for details.
4786 * Finish an asynchronous mount operation that was started
4787 * with g_file_mount_mountable().
4789 * Returns: (transfer full): a #GFile or %NULL on error.
4790 * Free the returned object with g_object_unref().
4793 g_file_mount_mountable_finish (GFile
*file
,
4794 GAsyncResult
*result
,
4799 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
4800 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), NULL
);
4802 if (g_async_result_legacy_propagate_error (result
, error
))
4804 else if (g_async_result_is_tagged (result
, g_file_mount_mountable
))
4805 return g_task_propagate_pointer (G_TASK (result
), error
);
4807 iface
= G_FILE_GET_IFACE (file
);
4808 return (* iface
->mount_mountable_finish
) (file
, result
, error
);
4812 * g_file_unmount_mountable:
4813 * @file: input #GFile
4814 * @flags: flags affecting the operation
4815 * @cancellable: (allow-none): optional #GCancellable object,
4817 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call
4818 * when the request is satisfied, or %NULL
4819 * @user_data: (closure): the data to pass to callback function
4821 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
4823 * If @cancellable is not %NULL, then the operation can be cancelled by
4824 * triggering the cancellable object from another thread. If the operation
4825 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4827 * When the operation is finished, @callback will be called.
4828 * You can then call g_file_unmount_mountable_finish() to get
4829 * the result of the operation.
4831 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation() instead.
4834 g_file_unmount_mountable (GFile
*file
,
4835 GMountUnmountFlags flags
,
4836 GCancellable
*cancellable
,
4837 GAsyncReadyCallback callback
,
4842 g_return_if_fail (G_IS_FILE (file
));
4844 iface
= G_FILE_GET_IFACE (file
);
4846 if (iface
->unmount_mountable
== NULL
)
4848 g_task_report_new_error (file
, callback
, user_data
,
4849 g_file_unmount_mountable_with_operation
,
4850 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
4851 _("Operation not supported"));
4855 (* iface
->unmount_mountable
) (file
,
4863 * g_file_unmount_mountable_finish:
4864 * @file: input #GFile
4865 * @result: a #GAsyncResult
4866 * @error: a #GError, or %NULL
4868 * Finishes an unmount operation, see g_file_unmount_mountable() for details.
4870 * Finish an asynchronous unmount operation that was started
4871 * with g_file_unmount_mountable().
4873 * Returns: %TRUE if the operation finished successfully.
4876 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation_finish()
4880 g_file_unmount_mountable_finish (GFile
*file
,
4881 GAsyncResult
*result
,
4886 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
4887 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
4889 if (g_async_result_legacy_propagate_error (result
, error
))
4891 else if (g_async_result_is_tagged (result
, g_file_unmount_mountable_with_operation
))
4892 return g_task_propagate_boolean (G_TASK (result
), error
);
4894 iface
= G_FILE_GET_IFACE (file
);
4895 return (* iface
->unmount_mountable_finish
) (file
, result
, error
);
4899 * g_file_unmount_mountable_with_operation:
4900 * @file: input #GFile
4901 * @flags: flags affecting the operation
4902 * @mount_operation: (allow-none): a #GMountOperation,
4903 * or %NULL to avoid user interaction
4904 * @cancellable: (allow-none): optional #GCancellable object,
4906 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call
4907 * when the request is satisfied, or %NULL
4908 * @user_data: (closure): the data to pass to callback function
4910 * Unmounts a file of type #G_FILE_TYPE_MOUNTABLE.
4912 * If @cancellable is not %NULL, then the operation can be cancelled by
4913 * triggering the cancellable object from another thread. If the operation
4914 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
4916 * When the operation is finished, @callback will be called.
4917 * You can then call g_file_unmount_mountable_finish() to get
4918 * the result of the operation.
4923 g_file_unmount_mountable_with_operation (GFile
*file
,
4924 GMountUnmountFlags flags
,
4925 GMountOperation
*mount_operation
,
4926 GCancellable
*cancellable
,
4927 GAsyncReadyCallback callback
,
4932 g_return_if_fail (G_IS_FILE (file
));
4934 iface
= G_FILE_GET_IFACE (file
);
4936 if (iface
->unmount_mountable
== NULL
&& iface
->unmount_mountable_with_operation
== NULL
)
4938 g_task_report_new_error (file
, callback
, user_data
,
4939 g_file_unmount_mountable_with_operation
,
4940 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
4941 _("Operation not supported"));
4945 if (iface
->unmount_mountable_with_operation
!= NULL
)
4946 (* iface
->unmount_mountable_with_operation
) (file
,
4953 (* iface
->unmount_mountable
) (file
,
4961 * g_file_unmount_mountable_with_operation_finish:
4962 * @file: input #GFile
4963 * @result: a #GAsyncResult
4964 * @error: a #GError, or %NULL
4966 * Finishes an unmount operation,
4967 * see g_file_unmount_mountable_with_operation() for details.
4969 * Finish an asynchronous unmount operation that was started
4970 * with g_file_unmount_mountable_with_operation().
4972 * Returns: %TRUE if the operation finished successfully.
4978 g_file_unmount_mountable_with_operation_finish (GFile
*file
,
4979 GAsyncResult
*result
,
4984 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
4985 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
4987 if (g_async_result_legacy_propagate_error (result
, error
))
4989 else if (g_async_result_is_tagged (result
, g_file_unmount_mountable_with_operation
))
4990 return g_task_propagate_boolean (G_TASK (result
), error
);
4992 iface
= G_FILE_GET_IFACE (file
);
4993 if (iface
->unmount_mountable_with_operation_finish
!= NULL
)
4994 return (* iface
->unmount_mountable_with_operation_finish
) (file
, result
, error
);
4996 return (* iface
->unmount_mountable_finish
) (file
, result
, error
);
5000 * g_file_eject_mountable:
5001 * @file: input #GFile
5002 * @flags: flags affecting the operation
5003 * @cancellable: (allow-none): optional #GCancellable object,
5005 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call
5006 * when the request is satisfied, or %NULL
5007 * @user_data: (closure): the data to pass to callback function
5009 * Starts an asynchronous eject on a mountable.
5010 * When this operation has completed, @callback will be called with
5011 * @user_user data, and the operation can be finalized with
5012 * g_file_eject_mountable_finish().
5014 * If @cancellable is not %NULL, then the operation can be cancelled by
5015 * triggering the cancellable object from another thread. If the operation
5016 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5018 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation() instead.
5021 g_file_eject_mountable (GFile
*file
,
5022 GMountUnmountFlags flags
,
5023 GCancellable
*cancellable
,
5024 GAsyncReadyCallback callback
,
5029 g_return_if_fail (G_IS_FILE (file
));
5031 iface
= G_FILE_GET_IFACE (file
);
5033 if (iface
->eject_mountable
== NULL
)
5035 g_task_report_new_error (file
, callback
, user_data
,
5036 g_file_eject_mountable_with_operation
,
5037 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
5038 _("Operation not supported"));
5042 (* iface
->eject_mountable
) (file
,
5050 * g_file_eject_mountable_finish:
5051 * @file: input #GFile
5052 * @result: a #GAsyncResult
5053 * @error: a #GError, or %NULL
5055 * Finishes an asynchronous eject operation started by
5056 * g_file_eject_mountable().
5058 * Returns: %TRUE if the @file was ejected successfully.
5061 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation_finish()
5065 g_file_eject_mountable_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 return (* iface
->eject_mountable_finish
) (file
, result
, error
);
5084 * g_file_eject_mountable_with_operation:
5085 * @file: input #GFile
5086 * @flags: flags affecting the operation
5087 * @mount_operation: (allow-none): a #GMountOperation,
5088 * or %NULL to avoid user interaction
5089 * @cancellable: (allow-none): optional #GCancellable object,
5091 * @callback: (scope async) (allow-none): a #GAsyncReadyCallback to call
5092 * when the request is satisfied, or %NULL
5093 * @user_data: (closure): the data to pass to callback function
5095 * Starts an asynchronous eject on a mountable.
5096 * When this operation has completed, @callback will be called with
5097 * @user_user data, and the operation can be finalized with
5098 * g_file_eject_mountable_with_operation_finish().
5100 * If @cancellable is not %NULL, then the operation can be cancelled by
5101 * triggering the cancellable object from another thread. If the operation
5102 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5107 g_file_eject_mountable_with_operation (GFile
*file
,
5108 GMountUnmountFlags flags
,
5109 GMountOperation
*mount_operation
,
5110 GCancellable
*cancellable
,
5111 GAsyncReadyCallback callback
,
5116 g_return_if_fail (G_IS_FILE (file
));
5118 iface
= G_FILE_GET_IFACE (file
);
5120 if (iface
->eject_mountable
== NULL
&& iface
->eject_mountable_with_operation
== NULL
)
5122 g_task_report_new_error (file
, callback
, user_data
,
5123 g_file_eject_mountable_with_operation
,
5124 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
5125 _("Operation not supported"));
5129 if (iface
->eject_mountable_with_operation
!= NULL
)
5130 (* iface
->eject_mountable_with_operation
) (file
,
5137 (* iface
->eject_mountable
) (file
,
5145 * g_file_eject_mountable_with_operation_finish:
5146 * @file: input #GFile
5147 * @result: a #GAsyncResult
5148 * @error: a #GError, or %NULL
5150 * Finishes an asynchronous eject operation started by
5151 * g_file_eject_mountable_with_operation().
5153 * Returns: %TRUE if the @file was ejected successfully.
5159 g_file_eject_mountable_with_operation_finish (GFile
*file
,
5160 GAsyncResult
*result
,
5165 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
5166 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
5168 if (g_async_result_legacy_propagate_error (result
, error
))
5170 else if (g_async_result_is_tagged (result
, g_file_eject_mountable_with_operation
))
5171 return g_task_propagate_boolean (G_TASK (result
), error
);
5173 iface
= G_FILE_GET_IFACE (file
);
5174 if (iface
->eject_mountable_with_operation_finish
!= NULL
)
5175 return (* iface
->eject_mountable_with_operation_finish
) (file
, result
, error
);
5177 return (* iface
->eject_mountable_finish
) (file
, result
, error
);
5181 * g_file_monitor_directory:
5182 * @file: input #GFile
5183 * @flags: a set of #GFileMonitorFlags
5184 * @cancellable: (allow-none): optional #GCancellable object,
5186 * @error: a #GError, or %NULL
5188 * Obtains a directory monitor for the given file.
5189 * This may fail if directory monitoring is not supported.
5191 * If @cancellable is not %NULL, then the operation can be cancelled by
5192 * triggering the cancellable object from another thread. If the operation
5193 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5195 * It does not make sense for @flags to contain
5196 * %G_FILE_MONITOR_WATCH_HARD_LINKS, since hard links can not be made to
5197 * directories. It is not possible to monitor all the files in a
5198 * directory for changes made via hard links; if you want to do this then
5199 * you must register individual watches with g_file_monitor().
5201 * Virtual: monitor_dir
5202 * Returns: (transfer full): a #GFileMonitor for the given @file,
5203 * or %NULL on error.
5204 * Free the returned object with g_object_unref().
5207 g_file_monitor_directory (GFile
*file
,
5208 GFileMonitorFlags flags
,
5209 GCancellable
*cancellable
,
5214 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
5215 g_return_val_if_fail (~flags
& G_FILE_MONITOR_WATCH_HARD_LINKS
, NULL
);
5217 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
5220 iface
= G_FILE_GET_IFACE (file
);
5222 if (iface
->monitor_dir
== NULL
)
5224 g_set_error_literal (error
, G_IO_ERROR
,
5225 G_IO_ERROR_NOT_SUPPORTED
,
5226 _("Operation not supported"));
5230 return (* iface
->monitor_dir
) (file
, flags
, cancellable
, error
);
5234 * g_file_monitor_file:
5235 * @file: input #GFile
5236 * @flags: a set of #GFileMonitorFlags
5237 * @cancellable: (allow-none): optional #GCancellable object,
5239 * @error: a #GError, or %NULL
5241 * Obtains a file monitor for the given file. If no file notification
5242 * mechanism exists, then regular polling of the file is used.
5244 * If @cancellable is not %NULL, then the operation can be cancelled by
5245 * triggering the cancellable object from another thread. If the operation
5246 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5248 * If @flags contains %G_FILE_MONITOR_WATCH_HARD_LINKS then the monitor
5249 * will also attempt to report changes made to the file via another
5250 * filename (ie, a hard link). Without this flag, you can only rely on
5251 * changes made through the filename contained in @file to be
5252 * reported. Using this flag may result in an increase in resource
5253 * usage, and may not have any effect depending on the #GFileMonitor
5254 * backend and/or filesystem type.
5256 * Returns: (transfer full): a #GFileMonitor for the given @file,
5257 * or %NULL on error.
5258 * Free the returned object with g_object_unref().
5261 g_file_monitor_file (GFile
*file
,
5262 GFileMonitorFlags flags
,
5263 GCancellable
*cancellable
,
5267 GFileMonitor
*monitor
;
5269 g_return_val_if_fail (G_IS_FILE (file
), NULL
);
5271 if (g_cancellable_set_error_if_cancelled (cancellable
, error
))
5274 iface
= G_FILE_GET_IFACE (file
);
5278 if (iface
->monitor_file
)
5279 monitor
= (* iface
->monitor_file
) (file
, flags
, cancellable
, NULL
);
5281 /* Fallback to polling */
5282 if (monitor
== NULL
)
5283 monitor
= _g_poll_file_monitor_new (file
);
5290 * @file: input #GFile
5291 * @flags: a set of #GFileMonitorFlags
5292 * @cancellable: (allow-none): optional #GCancellable object,
5294 * @error: a #GError, or %NULL
5296 * Obtains a file or directory monitor for the given file,
5297 * depending on the type of the file.
5299 * If @cancellable is not %NULL, then the operation can be cancelled by
5300 * triggering the cancellable object from another thread. If the operation
5301 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
5303 * Returns: (transfer full): a #GFileMonitor for the given @file,
5304 * or %NULL on error.
5305 * Free the returned object with g_object_unref().
5310 g_file_monitor (GFile
*file
,
5311 GFileMonitorFlags flags
,
5312 GCancellable
*cancellable
,
5315 if (g_file_query_file_type (file
, 0, cancellable
) == G_FILE_TYPE_DIRECTORY
)
5316 return g_file_monitor_directory (file
,
5317 flags
& ~G_FILE_MONITOR_WATCH_HARD_LINKS
,
5318 cancellable
, error
);
5320 return g_file_monitor_file (file
, flags
, cancellable
, error
);
5323 /********************************************
5324 * Default implementation of async ops *
5325 ********************************************/
5329 GFileQueryInfoFlags flags
;
5330 } QueryInfoAsyncData
;
5333 query_info_data_free (QueryInfoAsyncData
*data
)
5335 g_free (data
->attributes
);
5340 query_info_async_thread (GTask
*task
,
5343 GCancellable
*cancellable
)
5345 QueryInfoAsyncData
*data
= task_data
;
5347 GError
*error
= NULL
;
5349 info
= g_file_query_info (G_FILE (object
), data
->attributes
, data
->flags
, cancellable
, &error
);
5351 g_task_return_pointer (task
, info
, g_object_unref
);
5353 g_task_return_error (task
, error
);
5357 g_file_real_query_info_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
, query_info_async_thread
);
5376 g_object_unref (task
);
5380 g_file_real_query_info_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 query_filesystem_info_async_thread (GTask
*task
,
5393 GCancellable
*cancellable
)
5395 const char *attributes
= task_data
;
5397 GError
*error
= NULL
;
5399 info
= g_file_query_filesystem_info (G_FILE (object
), attributes
, cancellable
, &error
);
5401 g_task_return_pointer (task
, info
, g_object_unref
);
5403 g_task_return_error (task
, error
);
5407 g_file_real_query_filesystem_info_async (GFile
*file
,
5408 const char *attributes
,
5410 GCancellable
*cancellable
,
5411 GAsyncReadyCallback callback
,
5416 task
= g_task_new (file
, cancellable
, callback
, user_data
);
5417 g_task_set_task_data (task
, g_strdup (attributes
), g_free
);
5418 g_task_set_priority (task
, io_priority
);
5419 g_task_run_in_thread (task
, query_filesystem_info_async_thread
);
5420 g_object_unref (task
);
5424 g_file_real_query_filesystem_info_finish (GFile
*file
,
5428 g_return_val_if_fail (g_task_is_valid (res
, file
), NULL
);
5430 return g_task_propagate_pointer (G_TASK (res
), error
);
5434 enumerate_children_async_thread (GTask
*task
,
5437 GCancellable
*cancellable
)
5439 QueryInfoAsyncData
*data
= task_data
;
5440 GFileEnumerator
*enumerator
;
5441 GError
*error
= NULL
;
5443 enumerator
= g_file_enumerate_children (G_FILE (object
), data
->attributes
, data
->flags
, cancellable
, &error
);
5445 g_task_return_error (task
, error
);
5447 g_task_return_pointer (task
, enumerator
, g_object_unref
);
5451 g_file_real_enumerate_children_async (GFile
*file
,
5452 const char *attributes
,
5453 GFileQueryInfoFlags flags
,
5455 GCancellable
*cancellable
,
5456 GAsyncReadyCallback callback
,
5460 QueryInfoAsyncData
*data
;
5462 data
= g_new0 (QueryInfoAsyncData
, 1);
5463 data
->attributes
= g_strdup (attributes
);
5464 data
->flags
= flags
;
5466 task
= g_task_new (file
, cancellable
, callback
, user_data
);
5467 g_task_set_task_data (task
, data
, (GDestroyNotify
)query_info_data_free
);
5468 g_task_set_priority (task
, io_priority
);
5469 g_task_run_in_thread (task
, enumerate_children_async_thread
);
5470 g_object_unref (task
);
5473 static GFileEnumerator
*
5474 g_file_real_enumerate_children_finish (GFile
*file
,
5478 g_return_val_if_fail (g_task_is_valid (res
, file
), NULL
);
5480 return g_task_propagate_pointer (G_TASK (res
), error
);
5484 open_read_async_thread (GTask
*task
,
5487 GCancellable
*cancellable
)
5489 GFileInputStream
*stream
;
5490 GError
*error
= NULL
;
5492 stream
= g_file_read (G_FILE (object
), cancellable
, &error
);
5494 g_task_return_pointer (task
, stream
, g_object_unref
);
5496 g_task_return_error (task
, error
);
5500 g_file_real_read_async (GFile
*file
,
5502 GCancellable
*cancellable
,
5503 GAsyncReadyCallback callback
,
5508 task
= g_task_new (file
, cancellable
, callback
, user_data
);
5509 g_task_set_priority (task
, io_priority
);
5510 g_task_run_in_thread (task
, open_read_async_thread
);
5511 g_object_unref (task
);
5514 static GFileInputStream
*
5515 g_file_real_read_finish (GFile
*file
,
5519 g_return_val_if_fail (g_task_is_valid (res
, file
), NULL
);
5521 return g_task_propagate_pointer (G_TASK (res
), error
);
5525 append_to_async_thread (GTask
*task
,
5526 gpointer source_object
,
5528 GCancellable
*cancellable
)
5530 GFileCreateFlags
*data
= task_data
;
5531 GFileOutputStream
*stream
;
5532 GError
*error
= NULL
;
5534 stream
= g_file_append_to (G_FILE (source_object
), *data
, cancellable
, &error
);
5536 g_task_return_pointer (task
, stream
, g_object_unref
);
5538 g_task_return_error (task
, error
);
5542 g_file_real_append_to_async (GFile
*file
,
5543 GFileCreateFlags flags
,
5545 GCancellable
*cancellable
,
5546 GAsyncReadyCallback callback
,
5549 GFileCreateFlags
*data
;
5552 data
= g_new0 (GFileCreateFlags
, 1);
5555 task
= g_task_new (file
, cancellable
, callback
, user_data
);
5556 g_task_set_task_data (task
, data
, g_free
);
5557 g_task_set_priority (task
, io_priority
);
5559 g_task_run_in_thread (task
, append_to_async_thread
);
5560 g_object_unref (task
);
5563 static GFileOutputStream
*
5564 g_file_real_append_to_finish (GFile
*file
,
5568 g_return_val_if_fail (g_task_is_valid (res
, file
), NULL
);
5570 return g_task_propagate_pointer (G_TASK (res
), error
);
5574 create_async_thread (GTask
*task
,
5575 gpointer source_object
,
5577 GCancellable
*cancellable
)
5579 GFileCreateFlags
*data
= task_data
;
5580 GFileOutputStream
*stream
;
5581 GError
*error
= NULL
;
5583 stream
= g_file_create (G_FILE (source_object
), *data
, cancellable
, &error
);
5585 g_task_return_pointer (task
, stream
, g_object_unref
);
5587 g_task_return_error (task
, error
);
5591 g_file_real_create_async (GFile
*file
,
5592 GFileCreateFlags flags
,
5594 GCancellable
*cancellable
,
5595 GAsyncReadyCallback callback
,
5598 GFileCreateFlags
*data
;
5601 data
= g_new0 (GFileCreateFlags
, 1);
5604 task
= g_task_new (file
, cancellable
, callback
, user_data
);
5605 g_task_set_task_data (task
, data
, g_free
);
5606 g_task_set_priority (task
, io_priority
);
5608 g_task_run_in_thread (task
, create_async_thread
);
5609 g_object_unref (task
);
5612 static GFileOutputStream
*
5613 g_file_real_create_finish (GFile
*file
,
5617 g_return_val_if_fail (g_task_is_valid (res
, file
), NULL
);
5619 return g_task_propagate_pointer (G_TASK (res
), error
);
5623 GFileOutputStream
*stream
;
5625 gboolean make_backup
;
5626 GFileCreateFlags flags
;
5630 replace_async_data_free (ReplaceAsyncData
*data
)
5633 g_object_unref (data
->stream
);
5634 g_free (data
->etag
);
5639 replace_async_thread (GTask
*task
,
5640 gpointer source_object
,
5642 GCancellable
*cancellable
)
5644 GFileOutputStream
*stream
;
5645 ReplaceAsyncData
*data
= task_data
;
5646 GError
*error
= NULL
;
5648 stream
= g_file_replace (G_FILE (source_object
),
5656 g_task_return_pointer (task
, stream
, g_object_unref
);
5658 g_task_return_error (task
, error
);
5662 g_file_real_replace_async (GFile
*file
,
5664 gboolean make_backup
,
5665 GFileCreateFlags flags
,
5667 GCancellable
*cancellable
,
5668 GAsyncReadyCallback callback
,
5672 ReplaceAsyncData
*data
;
5674 data
= g_new0 (ReplaceAsyncData
, 1);
5675 data
->etag
= g_strdup (etag
);
5676 data
->make_backup
= make_backup
;
5677 data
->flags
= flags
;
5679 task
= g_task_new (file
, cancellable
, callback
, user_data
);
5680 g_task_set_task_data (task
, data
, (GDestroyNotify
)replace_async_data_free
);
5681 g_task_set_priority (task
, io_priority
);
5683 g_task_run_in_thread (task
, replace_async_thread
);
5684 g_object_unref (task
);
5687 static GFileOutputStream
*
5688 g_file_real_replace_finish (GFile
*file
,
5692 g_return_val_if_fail (g_task_is_valid (res
, file
), NULL
);
5694 return g_task_propagate_pointer (G_TASK (res
), error
);
5698 delete_async_thread (GTask
*task
,
5701 GCancellable
*cancellable
)
5703 GError
*error
= NULL
;
5705 if (g_file_delete (G_FILE (object
), cancellable
, &error
))
5706 g_task_return_boolean (task
, TRUE
);
5708 g_task_return_error (task
, error
);
5712 g_file_real_delete_async (GFile
*file
,
5714 GCancellable
*cancellable
,
5715 GAsyncReadyCallback callback
,
5720 task
= g_task_new (file
, cancellable
, callback
, user_data
);
5721 g_task_set_priority (task
, io_priority
);
5722 g_task_run_in_thread (task
, delete_async_thread
);
5723 g_object_unref (task
);
5727 g_file_real_delete_finish (GFile
*file
,
5731 g_return_val_if_fail (g_task_is_valid (res
, file
), FALSE
);
5733 return g_task_propagate_boolean (G_TASK (res
), error
);
5737 trash_async_thread (GTask
*task
,
5740 GCancellable
*cancellable
)
5742 GError
*error
= NULL
;
5744 if (g_file_trash (G_FILE (object
), cancellable
, &error
))
5745 g_task_return_boolean (task
, TRUE
);
5747 g_task_return_error (task
, error
);
5751 g_file_real_trash_async (GFile
*file
,
5753 GCancellable
*cancellable
,
5754 GAsyncReadyCallback callback
,
5759 task
= g_task_new (file
, cancellable
, callback
, user_data
);
5760 g_task_set_priority (task
, io_priority
);
5761 g_task_run_in_thread (task
, trash_async_thread
);
5762 g_object_unref (task
);
5766 g_file_real_trash_finish (GFile
*file
,
5770 g_return_val_if_fail (g_task_is_valid (res
, file
), FALSE
);
5772 return g_task_propagate_boolean (G_TASK (res
), error
);
5776 make_directory_async_thread (GTask
*task
,
5779 GCancellable
*cancellable
)
5781 GError
*error
= NULL
;
5783 if (g_file_make_directory (G_FILE (object
), cancellable
, &error
))
5784 g_task_return_boolean (task
, TRUE
);
5786 g_task_return_error (task
, error
);
5790 g_file_real_make_directory_async (GFile
*file
,
5792 GCancellable
*cancellable
,
5793 GAsyncReadyCallback callback
,
5798 task
= g_task_new (file
, cancellable
, callback
, user_data
);
5799 g_task_set_priority (task
, io_priority
);
5800 g_task_run_in_thread (task
, make_directory_async_thread
);
5801 g_object_unref (task
);
5805 g_file_real_make_directory_finish (GFile
*file
,
5809 g_return_val_if_fail (g_task_is_valid (res
, file
), FALSE
);
5811 return g_task_propagate_boolean (G_TASK (res
), error
);
5815 open_readwrite_async_thread (GTask
*task
,
5818 GCancellable
*cancellable
)
5820 GFileIOStream
*stream
;
5821 GError
*error
= NULL
;
5823 stream
= g_file_open_readwrite (G_FILE (object
), cancellable
, &error
);
5826 g_task_return_error (task
, error
);
5828 g_task_return_pointer (task
, stream
, g_object_unref
);
5832 g_file_real_open_readwrite_async (GFile
*file
,
5834 GCancellable
*cancellable
,
5835 GAsyncReadyCallback callback
,
5840 task
= g_task_new (file
, cancellable
, callback
, user_data
);
5841 g_task_set_priority (task
, io_priority
);
5843 g_task_run_in_thread (task
, open_readwrite_async_thread
);
5844 g_object_unref (task
);
5847 static GFileIOStream
*
5848 g_file_real_open_readwrite_finish (GFile
*file
,
5852 g_return_val_if_fail (g_task_is_valid (res
, file
), NULL
);
5854 return g_task_propagate_pointer (G_TASK (res
), error
);
5858 create_readwrite_async_thread (GTask
*task
,
5861 GCancellable
*cancellable
)
5863 GFileCreateFlags
*data
= task_data
;
5864 GFileIOStream
*stream
;
5865 GError
*error
= NULL
;
5867 stream
= g_file_create_readwrite (G_FILE (object
), *data
, cancellable
, &error
);
5870 g_task_return_error (task
, error
);
5872 g_task_return_pointer (task
, stream
, g_object_unref
);
5876 g_file_real_create_readwrite_async (GFile
*file
,
5877 GFileCreateFlags flags
,
5879 GCancellable
*cancellable
,
5880 GAsyncReadyCallback callback
,
5883 GFileCreateFlags
*data
;
5886 data
= g_new0 (GFileCreateFlags
, 1);
5889 task
= g_task_new (file
, cancellable
, callback
, user_data
);
5890 g_task_set_task_data (task
, data
, g_free
);
5891 g_task_set_priority (task
, io_priority
);
5893 g_task_run_in_thread (task
, create_readwrite_async_thread
);
5894 g_object_unref (task
);
5897 static GFileIOStream
*
5898 g_file_real_create_readwrite_finish (GFile
*file
,
5902 g_return_val_if_fail (g_task_is_valid (res
, file
), NULL
);
5904 return g_task_propagate_pointer (G_TASK (res
), error
);
5909 gboolean make_backup
;
5910 GFileCreateFlags flags
;
5911 } ReplaceRWAsyncData
;
5914 replace_rw_async_data_free (ReplaceRWAsyncData
*data
)
5916 g_free (data
->etag
);
5921 replace_readwrite_async_thread (GTask
*task
,
5924 GCancellable
*cancellable
)
5926 GFileIOStream
*stream
;
5927 GError
*error
= NULL
;
5928 ReplaceRWAsyncData
*data
= task_data
;
5930 stream
= g_file_replace_readwrite (G_FILE (object
),
5938 g_task_return_error (task
, error
);
5940 g_task_return_pointer (task
, stream
, g_object_unref
);
5944 g_file_real_replace_readwrite_async (GFile
*file
,
5946 gboolean make_backup
,
5947 GFileCreateFlags flags
,
5949 GCancellable
*cancellable
,
5950 GAsyncReadyCallback callback
,
5954 ReplaceRWAsyncData
*data
;
5956 data
= g_new0 (ReplaceRWAsyncData
, 1);
5957 data
->etag
= g_strdup (etag
);
5958 data
->make_backup
= make_backup
;
5959 data
->flags
= flags
;
5961 task
= g_task_new (file
, cancellable
, callback
, user_data
);
5962 g_task_set_task_data (task
, data
, (GDestroyNotify
)replace_rw_async_data_free
);
5963 g_task_set_priority (task
, io_priority
);
5965 g_task_run_in_thread (task
, replace_readwrite_async_thread
);
5966 g_object_unref (task
);
5969 static GFileIOStream
*
5970 g_file_real_replace_readwrite_finish (GFile
*file
,
5974 g_return_val_if_fail (g_task_is_valid (res
, file
), NULL
);
5976 return g_task_propagate_pointer (G_TASK (res
), error
);
5980 set_display_name_async_thread (GTask
*task
,
5983 GCancellable
*cancellable
)
5985 GError
*error
= NULL
;
5986 char *name
= task_data
;
5989 file
= g_file_set_display_name (G_FILE (object
), name
, cancellable
, &error
);
5992 g_task_return_error (task
, error
);
5994 g_task_return_pointer (task
, file
, g_object_unref
);
5998 g_file_real_set_display_name_async (GFile
*file
,
5999 const char *display_name
,
6001 GCancellable
*cancellable
,
6002 GAsyncReadyCallback callback
,
6007 task
= g_task_new (file
, cancellable
, callback
, user_data
);
6008 g_task_set_task_data (task
, g_strdup (display_name
), g_free
);
6009 g_task_set_priority (task
, io_priority
);
6011 g_task_run_in_thread (task
, set_display_name_async_thread
);
6012 g_object_unref (task
);
6016 g_file_real_set_display_name_finish (GFile
*file
,
6020 g_return_val_if_fail (g_task_is_valid (res
, file
), NULL
);
6022 return g_task_propagate_pointer (G_TASK (res
), error
);
6026 GFileQueryInfoFlags flags
;
6033 set_info_data_free (SetInfoAsyncData
*data
)
6036 g_object_unref (data
->info
);
6038 g_error_free (data
->error
);
6043 set_info_async_thread (GTask
*task
,
6046 GCancellable
*cancellable
)
6048 SetInfoAsyncData
*data
= task_data
;
6051 data
->res
= g_file_set_attributes_from_info (G_FILE (object
),
6059 g_file_real_set_attributes_async (GFile
*file
,
6061 GFileQueryInfoFlags flags
,
6063 GCancellable
*cancellable
,
6064 GAsyncReadyCallback callback
,
6068 SetInfoAsyncData
*data
;
6070 data
= g_new0 (SetInfoAsyncData
, 1);
6071 data
->info
= g_file_info_dup (info
);
6072 data
->flags
= flags
;
6074 task
= g_task_new (file
, cancellable
, callback
, user_data
);
6075 g_task_set_task_data (task
, data
, (GDestroyNotify
)set_info_data_free
);
6076 g_task_set_priority (task
, io_priority
);
6078 g_task_run_in_thread (task
, set_info_async_thread
);
6079 g_object_unref (task
);
6083 g_file_real_set_attributes_finish (GFile
*file
,
6088 SetInfoAsyncData
*data
;
6090 g_return_val_if_fail (g_task_is_valid (res
, file
), FALSE
);
6092 data
= g_task_get_task_data (G_TASK (res
));
6095 *info
= g_object_ref (data
->info
);
6097 if (error
!= NULL
&& data
->error
)
6098 *error
= g_error_copy (data
->error
);
6104 find_enclosing_mount_async_thread (GTask
*task
,
6107 GCancellable
*cancellable
)
6109 GError
*error
= NULL
;
6112 mount
= g_file_find_enclosing_mount (G_FILE (object
), cancellable
, &error
);
6115 g_task_return_error (task
, error
);
6117 g_task_return_pointer (task
, mount
, g_object_unref
);
6121 g_file_real_find_enclosing_mount_async (GFile
*file
,
6123 GCancellable
*cancellable
,
6124 GAsyncReadyCallback callback
,
6129 task
= g_task_new (file
, cancellable
, callback
, user_data
);
6130 g_task_set_priority (task
, io_priority
);
6132 g_task_run_in_thread (task
, find_enclosing_mount_async_thread
);
6133 g_object_unref (task
);
6137 g_file_real_find_enclosing_mount_finish (GFile
*file
,
6141 g_return_val_if_fail (g_task_is_valid (res
, file
), NULL
);
6143 return g_task_propagate_pointer (G_TASK (res
), error
);
6150 GFileCopyFlags flags
;
6151 GFileProgressCallback progress_cb
;
6152 gpointer progress_cb_data
;
6156 copy_async_data_free (CopyAsyncData
*data
)
6158 g_object_unref (data
->source
);
6159 g_object_unref (data
->destination
);
6160 g_slice_free (CopyAsyncData
, data
);
6164 CopyAsyncData
*data
;
6165 goffset current_num_bytes
;
6166 goffset total_num_bytes
;
6170 copy_async_progress_in_main (gpointer user_data
)
6172 ProgressData
*progress
= user_data
;
6173 CopyAsyncData
*data
= progress
->data
;
6175 data
->progress_cb (progress
->current_num_bytes
,
6176 progress
->total_num_bytes
,
6177 data
->progress_cb_data
);
6183 copy_async_progress_callback (goffset current_num_bytes
,
6184 goffset total_num_bytes
,
6187 GTask
*task
= user_data
;
6188 CopyAsyncData
*data
= g_task_get_task_data (task
);
6189 ProgressData
*progress
;
6191 progress
= g_new (ProgressData
, 1);
6192 progress
->data
= data
;
6193 progress
->current_num_bytes
= current_num_bytes
;
6194 progress
->total_num_bytes
= total_num_bytes
;
6196 g_main_context_invoke_full (g_task_get_context (task
),
6197 g_task_get_priority (task
),
6198 copy_async_progress_in_main
,
6204 copy_async_thread (GTask
*task
,
6207 GCancellable
*cancellable
)
6209 CopyAsyncData
*data
= task_data
;
6211 GError
*error
= NULL
;
6213 result
= g_file_copy (data
->source
,
6217 (data
->progress_cb
!= NULL
) ? copy_async_progress_callback
: NULL
,
6221 g_task_return_boolean (task
, TRUE
);
6223 g_task_return_error (task
, error
);
6227 g_file_real_copy_async (GFile
*source
,
6229 GFileCopyFlags flags
,
6231 GCancellable
*cancellable
,
6232 GFileProgressCallback progress_callback
,
6233 gpointer progress_callback_data
,
6234 GAsyncReadyCallback callback
,
6238 CopyAsyncData
*data
;
6240 data
= g_slice_new (CopyAsyncData
);
6241 data
->source
= g_object_ref (source
);
6242 data
->destination
= g_object_ref (destination
);
6243 data
->flags
= flags
;
6244 data
->progress_cb
= progress_callback
;
6245 data
->progress_cb_data
= progress_callback_data
;
6247 task
= g_task_new (source
, cancellable
, callback
, user_data
);
6248 g_task_set_task_data (task
, data
, (GDestroyNotify
)copy_async_data_free
);
6249 g_task_set_priority (task
, io_priority
);
6250 g_task_run_in_thread (task
, copy_async_thread
);
6251 g_object_unref (task
);
6255 g_file_real_copy_finish (GFile
*file
,
6259 g_return_val_if_fail (g_task_is_valid (res
, file
), FALSE
);
6261 return g_task_propagate_boolean (G_TASK (res
), error
);
6265 /********************************************
6266 * Default VFS operations *
6267 ********************************************/
6270 * g_file_new_for_path:
6271 * @path: a string containing a relative or absolute path.
6272 * The string must be encoded in the glib filename encoding.
6274 * Constructs a #GFile for a given path. This operation never
6275 * fails, but the returned object might not support any I/O
6276 * operation if @path is malformed.
6278 * Returns: (transfer full): a new #GFile for the given @path.
6279 * Free the returned object with g_object_unref().
6282 g_file_new_for_path (const char *path
)
6284 g_return_val_if_fail (path
!= NULL
, NULL
);
6286 return g_vfs_get_file_for_path (g_vfs_get_default (), path
);
6290 * g_file_new_for_uri:
6291 * @uri: a UTF-8 string containing a URI
6293 * Constructs a #GFile for a given URI. This operation never
6294 * fails, but the returned object might not support any I/O
6295 * operation if @uri is malformed or if the uri type is
6298 * Returns: (transfer full): a new #GFile for the given @uri.
6299 * Free the returned object with g_object_unref().
6302 g_file_new_for_uri (const char *uri
)
6304 g_return_val_if_fail (uri
!= NULL
, NULL
);
6306 return g_vfs_get_file_for_uri (g_vfs_get_default (), uri
);
6311 * @tmpl: (type filename) (allow-none): Template for the file
6312 * name, as in g_file_open_tmp(), or %NULL for a default template
6313 * @iostream: (out): on return, a #GFileIOStream for the created file
6314 * @error: a #GError, or %NULL
6316 * Opens a file in the preferred directory for temporary files (as
6317 * returned by g_get_tmp_dir()) and returns a #GFile and
6318 * #GFileIOStream pointing to it.
6320 * @tmpl should be a string in the GLib file name encoding
6321 * containing a sequence of six 'X' characters, and containing no
6322 * directory components. If it is %NULL, a default template is used.
6324 * Unlike the other #GFile constructors, this will return %NULL if
6325 * a temporary file could not be created.
6327 * Returns: (transfer full): a new #GFile.
6328 * Free the returned object with g_object_unref().
6333 g_file_new_tmp (const char *tmpl
,
6334 GFileIOStream
**iostream
,
6340 GFileOutputStream
*output
;
6342 g_return_val_if_fail (iostream
!= NULL
, NULL
);
6344 fd
= g_file_open_tmp (tmpl
, &path
, error
);
6348 file
= g_file_new_for_path (path
);
6350 output
= _g_local_file_output_stream_new (fd
);
6351 *iostream
= _g_local_file_io_stream_new (G_LOCAL_FILE_OUTPUT_STREAM (output
));
6353 g_object_unref (output
);
6360 * g_file_parse_name:
6361 * @parse_name: a file name or path to be parsed
6363 * Constructs a #GFile with the given @parse_name (i.e. something
6364 * given by g_file_get_parse_name()). This operation never fails,
6365 * but the returned object might not support any I/O operation if
6366 * the @parse_name cannot be parsed.
6368 * Returns: (transfer full): a new #GFile.
6371 g_file_parse_name (const char *parse_name
)
6373 g_return_val_if_fail (parse_name
!= NULL
, NULL
);
6375 return g_vfs_parse_name (g_vfs_get_default (), parse_name
);
6379 is_valid_scheme_character (char c
)
6381 return g_ascii_isalnum (c
) || c
== '+' || c
== '-' || c
== '.';
6384 /* Following RFC 2396, valid schemes are built like:
6385 * scheme = alpha *( alpha | digit | "+" | "-" | "." )
6388 has_valid_scheme (const char *uri
)
6394 if (!g_ascii_isalpha (*p
))
6399 } while (is_valid_scheme_character (*p
));
6405 new_for_cmdline_arg (const gchar
*arg
,
6411 if (g_path_is_absolute (arg
))
6412 return g_file_new_for_path (arg
);
6414 if (has_valid_scheme (arg
))
6415 return g_file_new_for_uri (arg
);
6421 current_dir
= g_get_current_dir ();
6422 filename
= g_build_filename (current_dir
, arg
, NULL
);
6423 g_free (current_dir
);
6426 filename
= g_build_filename (cwd
, arg
, NULL
);
6428 file
= g_file_new_for_path (filename
);
6435 * g_file_new_for_commandline_arg:
6436 * @arg: a command line string
6438 * Creates a #GFile with the given argument from the command line.
6439 * The value of @arg can be either a URI, an absolute path or a
6440 * relative path resolved relative to the current working directory.
6441 * This operation never fails, but the returned object might not
6442 * support any I/O operation if @arg points to a malformed path.
6444 * Note that on Windows, this function expects its argument to be in
6445 * UTF-8 -- not the system code page. This means that you
6446 * should not use this function with string from argv as it is passed
6447 * to main(). g_win32_get_command_line() will return a UTF-8 version of
6448 * the commandline. #GApplication also uses UTF-8 but
6449 * g_application_command_line_create_file_for_arg() may be more useful
6450 * for you there. It is also always possible to use this function with
6451 * #GOptionContext arguments of type %G_OPTION_ARG_FILENAME.
6453 * Returns: (transfer full): a new #GFile.
6454 * Free the returned object with g_object_unref().
6457 g_file_new_for_commandline_arg (const char *arg
)
6459 g_return_val_if_fail (arg
!= NULL
, NULL
);
6461 return new_for_cmdline_arg (arg
, NULL
);
6465 * g_file_new_for_commandline_arg_and_cwd:
6466 * @arg: a command line string
6467 * @cwd: the current working directory of the commandline
6469 * Creates a #GFile with the given argument from the command line.
6471 * This function is similar to g_file_new_for_commandline_arg() except
6472 * that it allows for passing the current working directory as an
6473 * argument instead of using the current working directory of the
6476 * This is useful if the commandline argument was given in a context
6477 * other than the invocation of the current process.
6479 * See also g_application_command_line_create_file_for_arg().
6481 * Returns: (transfer full): a new #GFile
6486 g_file_new_for_commandline_arg_and_cwd (const gchar
*arg
,
6489 g_return_val_if_fail (arg
!= NULL
, NULL
);
6490 g_return_val_if_fail (cwd
!= NULL
, NULL
);
6492 return new_for_cmdline_arg (arg
, cwd
);
6496 * g_file_mount_enclosing_volume:
6497 * @location: input #GFile
6498 * @flags: flags affecting the operation
6499 * @mount_operation: (allow-none): a #GMountOperation
6500 * or %NULL to avoid user interaction
6501 * @cancellable: (allow-none): optional #GCancellable object,
6503 * @callback: (allow-none): a #GAsyncReadyCallback to call
6504 * when the request is satisfied, or %NULL
6505 * @user_data: the data to pass to callback function
6507 * Starts a @mount_operation, mounting the volume that contains
6508 * the file @location.
6510 * When this operation has completed, @callback will be called with
6511 * @user_user data, and the operation can be finalized with
6512 * g_file_mount_enclosing_volume_finish().
6514 * If @cancellable is not %NULL, then the operation can be cancelled by
6515 * triggering the cancellable object from another thread. If the operation
6516 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6519 g_file_mount_enclosing_volume (GFile
*location
,
6520 GMountMountFlags flags
,
6521 GMountOperation
*mount_operation
,
6522 GCancellable
*cancellable
,
6523 GAsyncReadyCallback callback
,
6528 g_return_if_fail (G_IS_FILE (location
));
6530 iface
= G_FILE_GET_IFACE (location
);
6532 if (iface
->mount_enclosing_volume
== NULL
)
6534 g_task_report_new_error (location
, callback
, user_data
,
6535 g_file_mount_enclosing_volume
,
6536 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
6537 _("volume doesn't implement mount"));
6541 (* iface
->mount_enclosing_volume
) (location
, flags
, mount_operation
, cancellable
, callback
, user_data
);
6546 * g_file_mount_enclosing_volume_finish:
6547 * @location: input #GFile
6548 * @result: a #GAsyncResult
6549 * @error: a #GError, or %NULL
6551 * Finishes a mount operation started by g_file_mount_enclosing_volume().
6553 * Returns: %TRUE if successful. If an error has occurred,
6554 * this function will return %FALSE and set @error
6555 * appropriately if present.
6558 g_file_mount_enclosing_volume_finish (GFile
*location
,
6559 GAsyncResult
*result
,
6564 g_return_val_if_fail (G_IS_FILE (location
), FALSE
);
6565 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
6567 if (g_async_result_legacy_propagate_error (result
, error
))
6569 else if (g_async_result_is_tagged (result
, g_file_mount_enclosing_volume
))
6570 return g_task_propagate_boolean (G_TASK (result
), error
);
6572 iface
= G_FILE_GET_IFACE (location
);
6574 return (* iface
->mount_enclosing_volume_finish
) (location
, result
, error
);
6577 /********************************************
6578 * Utility functions *
6579 ********************************************/
6582 * g_file_query_default_handler:
6583 * @file: a #GFile to open
6584 * @cancellable: optional #GCancellable object, %NULL to ignore
6585 * @error: a #GError, or %NULL
6587 * Returns the #GAppInfo that is registered as the default
6588 * application to handle the file specified by @file.
6590 * If @cancellable is not %NULL, then the operation can be cancelled by
6591 * triggering the cancellable object from another thread. If the operation
6592 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6594 * Returns: (transfer full): a #GAppInfo if the handle was found,
6595 * %NULL if there were errors.
6596 * When you are done with it, release it with g_object_unref()
6599 g_file_query_default_handler (GFile
*file
,
6600 GCancellable
*cancellable
,
6604 const char *content_type
;
6609 uri_scheme
= g_file_get_uri_scheme (file
);
6610 if (uri_scheme
&& uri_scheme
[0] != '\0')
6612 appinfo
= g_app_info_get_default_for_uri_scheme (uri_scheme
);
6613 g_free (uri_scheme
);
6615 if (appinfo
!= NULL
)
6619 info
= g_file_query_info (file
,
6620 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
,
6629 content_type
= g_file_info_get_content_type (info
);
6632 /* Don't use is_native(), as we want to support fuse paths if available */
6633 path
= g_file_get_path (file
);
6634 appinfo
= g_app_info_get_default_for_type (content_type
,
6639 g_object_unref (info
);
6641 if (appinfo
!= NULL
)
6644 g_set_error_literal (error
, G_IO_ERROR
,
6645 G_IO_ERROR_NOT_SUPPORTED
,
6646 _("No application is registered as handling this file"));
6650 #define GET_CONTENT_BLOCK_SIZE 8192
6653 * g_file_load_contents:
6654 * @file: input #GFile
6655 * @cancellable: optional #GCancellable object, %NULL to ignore
6656 * @contents: (out) (transfer full) (element-type guint8) (array length=length): a location to place the contents of the file
6657 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6658 * or %NULL if the length is not needed
6659 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6660 * or %NULL if the entity tag is not needed
6661 * @error: a #GError, or %NULL
6663 * Loads the content of the file into memory. The data is always
6664 * zero-terminated, but this is not included in the resultant @length.
6665 * The returned @content should be freed with g_free() when no longer
6668 * If @cancellable is not %NULL, then the operation can be cancelled by
6669 * triggering the cancellable object from another thread. If the operation
6670 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6672 * Returns: %TRUE if the @file's contents were successfully loaded.
6673 * %FALSE if there were errors.
6676 g_file_load_contents (GFile
*file
,
6677 GCancellable
*cancellable
,
6683 GFileInputStream
*in
;
6684 GByteArray
*content
;
6689 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
6690 g_return_val_if_fail (contents
!= NULL
, FALSE
);
6692 in
= g_file_read (file
, cancellable
, error
);
6696 content
= g_byte_array_new ();
6699 g_byte_array_set_size (content
, pos
+ GET_CONTENT_BLOCK_SIZE
+ 1);
6700 while ((res
= g_input_stream_read (G_INPUT_STREAM (in
),
6701 content
->data
+ pos
,
6702 GET_CONTENT_BLOCK_SIZE
,
6703 cancellable
, error
)) > 0)
6706 g_byte_array_set_size (content
, pos
+ GET_CONTENT_BLOCK_SIZE
+ 1);
6713 info
= g_file_input_stream_query_info (in
,
6714 G_FILE_ATTRIBUTE_ETAG_VALUE
,
6719 *etag_out
= g_strdup (g_file_info_get_etag (info
));
6720 g_object_unref (info
);
6724 /* Ignore errors on close */
6725 g_input_stream_close (G_INPUT_STREAM (in
), cancellable
, NULL
);
6726 g_object_unref (in
);
6730 /* error is set already */
6731 g_byte_array_free (content
, TRUE
);
6738 /* Zero terminate (we got an extra byte allocated for this */
6739 content
->data
[pos
] = 0;
6741 *contents
= (char *)g_byte_array_free (content
, FALSE
);
6748 GFileReadMoreCallback read_more_callback
;
6749 GByteArray
*content
;
6756 load_contents_data_free (LoadContentsData
*data
)
6759 g_byte_array_free (data
->content
, TRUE
);
6760 g_free (data
->etag
);
6765 load_contents_close_callback (GObject
*obj
,
6766 GAsyncResult
*close_res
,
6769 GInputStream
*stream
= G_INPUT_STREAM (obj
);
6770 LoadContentsData
*data
= user_data
;
6772 /* Ignore errors here, we're only reading anyway */
6773 g_input_stream_close_finish (stream
, close_res
, NULL
);
6774 g_object_unref (stream
);
6776 g_task_return_boolean (data
->task
, TRUE
);
6777 g_object_unref (data
->task
);
6781 load_contents_fstat_callback (GObject
*obj
,
6782 GAsyncResult
*stat_res
,
6785 GInputStream
*stream
= G_INPUT_STREAM (obj
);
6786 LoadContentsData
*data
= user_data
;
6789 info
= g_file_input_stream_query_info_finish (G_FILE_INPUT_STREAM (stream
),
6793 data
->etag
= g_strdup (g_file_info_get_etag (info
));
6794 g_object_unref (info
);
6797 g_input_stream_close_async (stream
, 0,
6798 g_task_get_cancellable (data
->task
),
6799 load_contents_close_callback
, data
);
6803 load_contents_read_callback (GObject
*obj
,
6804 GAsyncResult
*read_res
,
6807 GInputStream
*stream
= G_INPUT_STREAM (obj
);
6808 LoadContentsData
*data
= user_data
;
6809 GError
*error
= NULL
;
6812 read_size
= g_input_stream_read_finish (stream
, read_res
, &error
);
6816 g_task_return_error (data
->task
, error
);
6817 g_object_unref (data
->task
);
6819 /* Close the file ignoring any error */
6820 g_input_stream_close_async (stream
, 0, NULL
, NULL
, NULL
);
6821 g_object_unref (stream
);
6823 else if (read_size
== 0)
6825 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream
),
6826 G_FILE_ATTRIBUTE_ETAG_VALUE
,
6828 g_task_get_cancellable (data
->task
),
6829 load_contents_fstat_callback
,
6832 else if (read_size
> 0)
6834 data
->pos
+= read_size
;
6836 g_byte_array_set_size (data
->content
,
6837 data
->pos
+ GET_CONTENT_BLOCK_SIZE
);
6840 if (data
->read_more_callback
&&
6841 !data
->read_more_callback ((char *)data
->content
->data
, data
->pos
,
6842 g_async_result_get_user_data (G_ASYNC_RESULT (data
->task
))))
6843 g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream
),
6844 G_FILE_ATTRIBUTE_ETAG_VALUE
,
6846 g_task_get_cancellable (data
->task
),
6847 load_contents_fstat_callback
,
6850 g_input_stream_read_async (stream
,
6851 data
->content
->data
+ data
->pos
,
6852 GET_CONTENT_BLOCK_SIZE
,
6854 g_task_get_cancellable (data
->task
),
6855 load_contents_read_callback
,
6861 load_contents_open_callback (GObject
*obj
,
6862 GAsyncResult
*open_res
,
6865 GFile
*file
= G_FILE (obj
);
6866 GFileInputStream
*stream
;
6867 LoadContentsData
*data
= user_data
;
6868 GError
*error
= NULL
;
6870 stream
= g_file_read_finish (file
, open_res
, &error
);
6874 g_byte_array_set_size (data
->content
,
6875 data
->pos
+ GET_CONTENT_BLOCK_SIZE
);
6876 g_input_stream_read_async (G_INPUT_STREAM (stream
),
6877 data
->content
->data
+ data
->pos
,
6878 GET_CONTENT_BLOCK_SIZE
,
6880 g_task_get_cancellable (data
->task
),
6881 load_contents_read_callback
,
6886 g_task_return_error (data
->task
, error
);
6887 g_object_unref (data
->task
);
6892 * g_file_load_partial_contents_async: (skip)
6893 * @file: input #GFile
6894 * @cancellable: optional #GCancellable object, %NULL to ignore
6895 * @read_more_callback: a #GFileReadMoreCallback to receive partial data
6896 * and to specify whether further data should be read
6897 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
6898 * @user_data: the data to pass to the callback functions
6900 * Reads the partial contents of a file. A #GFileReadMoreCallback should
6901 * be used to stop reading from the file when appropriate, else this
6902 * function will behave exactly as g_file_load_contents_async(). This
6903 * operation can be finished by g_file_load_partial_contents_finish().
6905 * Users of this function should be aware that @user_data is passed to
6906 * both the @read_more_callback and the @callback.
6908 * If @cancellable is not %NULL, then the operation can be cancelled by
6909 * triggering the cancellable object from another thread. If the operation
6910 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
6913 g_file_load_partial_contents_async (GFile
*file
,
6914 GCancellable
*cancellable
,
6915 GFileReadMoreCallback read_more_callback
,
6916 GAsyncReadyCallback callback
,
6919 LoadContentsData
*data
;
6921 g_return_if_fail (G_IS_FILE (file
));
6923 data
= g_new0 (LoadContentsData
, 1);
6924 data
->read_more_callback
= read_more_callback
;
6925 data
->content
= g_byte_array_new ();
6927 data
->task
= g_task_new (file
, cancellable
, callback
, user_data
);
6928 g_task_set_task_data (data
->task
, data
, (GDestroyNotify
)load_contents_data_free
);
6930 g_file_read_async (file
,
6932 g_task_get_cancellable (data
->task
),
6933 load_contents_open_callback
,
6938 * g_file_load_partial_contents_finish:
6939 * @file: input #GFile
6940 * @res: a #GAsyncResult
6941 * @contents: (out) (transfer full) (element-type guint8) (array length=length): a location to place the contents of the file
6942 * @length: (out) (allow-none): a location to place the length of the contents of the file,
6943 * or %NULL if the length is not needed
6944 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
6945 * or %NULL if the entity tag is not needed
6946 * @error: a #GError, or %NULL
6948 * Finishes an asynchronous partial load operation that was started
6949 * with g_file_load_partial_contents_async(). The data is always
6950 * zero-terminated, but this is not included in the resultant @length.
6951 * The returned @content should be freed with g_free() when no longer
6954 * Returns: %TRUE if the load was successful. If %FALSE and @error is
6955 * present, it will be set appropriately.
6958 g_file_load_partial_contents_finish (GFile
*file
,
6966 LoadContentsData
*data
;
6968 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
6969 g_return_val_if_fail (g_task_is_valid (res
, file
), FALSE
);
6970 g_return_val_if_fail (contents
!= NULL
, FALSE
);
6972 task
= G_TASK (res
);
6974 if (!g_task_propagate_boolean (task
, error
))
6981 data
= g_task_get_task_data (task
);
6984 *length
= data
->pos
;
6988 *etag_out
= data
->etag
;
6992 /* Zero terminate */
6993 g_byte_array_set_size (data
->content
, data
->pos
+ 1);
6994 data
->content
->data
[data
->pos
] = 0;
6996 *contents
= (char *)g_byte_array_free (data
->content
, FALSE
);
6997 data
->content
= NULL
;
7003 * g_file_load_contents_async:
7004 * @file: input #GFile
7005 * @cancellable: optional #GCancellable object, %NULL to ignore
7006 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
7007 * @user_data: the data to pass to callback function
7009 * Starts an asynchronous load of the @file's contents.
7011 * For more details, see g_file_load_contents() which is
7012 * the synchronous version of this call.
7014 * When the load operation has completed, @callback will be called
7015 * with @user data. To finish the operation, call
7016 * g_file_load_contents_finish() with the #GAsyncResult returned by
7019 * If @cancellable is not %NULL, then the operation can be cancelled by
7020 * triggering the cancellable object from another thread. If the operation
7021 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7024 g_file_load_contents_async (GFile
*file
,
7025 GCancellable
*cancellable
,
7026 GAsyncReadyCallback callback
,
7029 g_file_load_partial_contents_async (file
,
7032 callback
, user_data
);
7036 * g_file_load_contents_finish:
7037 * @file: input #GFile
7038 * @res: a #GAsyncResult
7039 * @contents: (out) (transfer full) (element-type guint8) (array length=length): a location to place the contents of the file
7040 * @length: (out) (allow-none): a location to place the length of the contents of the file,
7041 * or %NULL if the length is not needed
7042 * @etag_out: (out) (allow-none): a location to place the current entity tag for the file,
7043 * or %NULL if the entity tag is not needed
7044 * @error: a #GError, or %NULL
7046 * Finishes an asynchronous load of the @file's contents.
7047 * The contents are placed in @contents, and @length is set to the
7048 * size of the @contents string. The @content should be freed with
7049 * g_free() when no longer needed. If @etag_out is present, it will be
7050 * set to the new entity tag for the @file.
7052 * Returns: %TRUE if the load was successful. If %FALSE and @error is
7053 * present, it will be set appropriately.
7056 g_file_load_contents_finish (GFile
*file
,
7063 return g_file_load_partial_contents_finish (file
,
7072 * g_file_replace_contents:
7073 * @file: input #GFile
7074 * @contents: (element-type guint8) (array length=length): a string containing the new contents for @file
7075 * @length: the length of @contents in bytes
7076 * @etag: (allow-none): the old [entity-tag][gfile-etag] for the document,
7078 * @make_backup: %TRUE if a backup should be created
7079 * @flags: a set of #GFileCreateFlags
7080 * @new_etag: (allow-none) (out): a location to a new [entity tag][gfile-etag]
7081 * for the document. This should be freed with g_free() when no longer
7083 * @cancellable: optional #GCancellable object, %NULL to ignore
7084 * @error: a #GError, or %NULL
7086 * Replaces the contents of @file with @contents of @length bytes.
7088 * If @etag is specified (not %NULL), any existing file must have that etag,
7089 * or the error %G_IO_ERROR_WRONG_ETAG will be returned.
7091 * If @make_backup is %TRUE, this function will attempt to make a backup
7094 * If @cancellable is not %NULL, then the operation can be cancelled by
7095 * triggering the cancellable object from another thread. If the operation
7096 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7098 * The returned @new_etag can be used to verify that the file hasn't
7099 * changed the next time it is saved over.
7101 * Returns: %TRUE if successful. If an error has occurred, this function
7102 * will return %FALSE and set @error appropriately if present.
7105 g_file_replace_contents (GFile
*file
,
7106 const char *contents
,
7109 gboolean make_backup
,
7110 GFileCreateFlags flags
,
7112 GCancellable
*cancellable
,
7115 GFileOutputStream
*out
;
7116 gsize pos
, remainder
;
7120 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
7121 g_return_val_if_fail (contents
!= NULL
, FALSE
);
7123 out
= g_file_replace (file
, etag
, make_backup
, flags
, cancellable
, error
);
7129 while (remainder
> 0 &&
7130 (res
= g_output_stream_write (G_OUTPUT_STREAM (out
),
7132 MIN (remainder
, GET_CONTENT_BLOCK_SIZE
),
7140 if (remainder
> 0 && res
< 0)
7142 /* Ignore errors on close */
7143 g_output_stream_close (G_OUTPUT_STREAM (out
), cancellable
, NULL
);
7144 g_object_unref (out
);
7146 /* error is set already */
7150 ret
= g_output_stream_close (G_OUTPUT_STREAM (out
), cancellable
, error
);
7153 *new_etag
= g_file_output_stream_get_etag (out
);
7155 g_object_unref (out
);
7166 } ReplaceContentsData
;
7169 replace_contents_data_free (ReplaceContentsData
*data
)
7171 g_bytes_unref (data
->content
);
7172 g_free (data
->etag
);
7177 replace_contents_close_callback (GObject
*obj
,
7178 GAsyncResult
*close_res
,
7181 GOutputStream
*stream
= G_OUTPUT_STREAM (obj
);
7182 ReplaceContentsData
*data
= user_data
;
7184 /* Ignore errors here, we're only reading anyway */
7185 g_output_stream_close_finish (stream
, close_res
, NULL
);
7186 g_object_unref (stream
);
7190 data
->etag
= g_file_output_stream_get_etag (G_FILE_OUTPUT_STREAM (stream
));
7191 g_task_return_boolean (data
->task
, TRUE
);
7193 g_object_unref (data
->task
);
7197 replace_contents_write_callback (GObject
*obj
,
7198 GAsyncResult
*read_res
,
7201 GOutputStream
*stream
= G_OUTPUT_STREAM (obj
);
7202 ReplaceContentsData
*data
= user_data
;
7203 GError
*error
= NULL
;
7206 write_size
= g_output_stream_write_finish (stream
, read_res
, &error
);
7208 if (write_size
<= 0)
7210 /* Error or EOF, close the file */
7213 data
->failed
= TRUE
;
7214 g_task_return_error (data
->task
, error
);
7216 g_output_stream_close_async (stream
, 0,
7217 g_task_get_cancellable (data
->task
),
7218 replace_contents_close_callback
, data
);
7220 else if (write_size
> 0)
7222 const gchar
*content
;
7225 content
= g_bytes_get_data (data
->content
, &length
);
7226 data
->pos
+= write_size
;
7228 if (data
->pos
>= length
)
7229 g_output_stream_close_async (stream
, 0,
7230 g_task_get_cancellable (data
->task
),
7231 replace_contents_close_callback
, data
);
7233 g_output_stream_write_async (stream
,
7234 content
+ data
->pos
,
7237 g_task_get_cancellable (data
->task
),
7238 replace_contents_write_callback
,
7244 replace_contents_open_callback (GObject
*obj
,
7245 GAsyncResult
*open_res
,
7248 GFile
*file
= G_FILE (obj
);
7249 GFileOutputStream
*stream
;
7250 ReplaceContentsData
*data
= user_data
;
7251 GError
*error
= NULL
;
7253 stream
= g_file_replace_finish (file
, open_res
, &error
);
7257 const gchar
*content
;
7260 content
= g_bytes_get_data (data
->content
, &length
);
7261 g_output_stream_write_async (G_OUTPUT_STREAM (stream
),
7262 content
+ data
->pos
,
7265 g_task_get_cancellable (data
->task
),
7266 replace_contents_write_callback
,
7271 g_task_return_error (data
->task
, error
);
7272 g_object_unref (data
->task
);
7277 * g_file_replace_contents_async:
7278 * @file: input #GFile
7279 * @contents: (element-type guint8) (array length=length): string of contents to replace the file with
7280 * @length: the length of @contents in bytes
7281 * @etag: (allow-none): a new [entity tag][gfile-etag] for the @file, or %NULL
7282 * @make_backup: %TRUE if a backup should be created
7283 * @flags: a set of #GFileCreateFlags
7284 * @cancellable: optional #GCancellable object, %NULL to ignore
7285 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
7286 * @user_data: the data to pass to callback function
7288 * Starts an asynchronous replacement of @file with the given
7289 * @contents of @length bytes. @etag will replace the document's
7290 * current entity tag.
7292 * When this operation has completed, @callback will be called with
7293 * @user_user data, and the operation can be finalized with
7294 * g_file_replace_contents_finish().
7296 * If @cancellable is not %NULL, then the operation can be cancelled by
7297 * triggering the cancellable object from another thread. If the operation
7298 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7300 * If @make_backup is %TRUE, this function will attempt to
7301 * make a backup of @file.
7303 * Note that no copy of @content will be made, so it must stay valid
7304 * until @callback is called. See g_file_replace_contents_bytes_async()
7305 * for a #GBytes version that will automatically hold a reference to the
7306 * contents (without copying) for the duration of the call.
7309 g_file_replace_contents_async (GFile
*file
,
7310 const char *contents
,
7313 gboolean make_backup
,
7314 GFileCreateFlags flags
,
7315 GCancellable
*cancellable
,
7316 GAsyncReadyCallback callback
,
7321 bytes
= g_bytes_new_static (contents
, length
);
7322 g_file_replace_contents_bytes_async (file
, bytes
, etag
, make_backup
, flags
,
7323 cancellable
, callback
, user_data
);
7324 g_bytes_unref (bytes
);
7328 * g_file_replace_contents_bytes_async:
7329 * @file: input #GFile
7330 * @contents: a #GBytes
7331 * @etag: (allow-none): a new [entity tag][gfile-etag] for the @file, or %NULL
7332 * @make_backup: %TRUE if a backup should be created
7333 * @flags: a set of #GFileCreateFlags
7334 * @cancellable: optional #GCancellable object, %NULL to ignore
7335 * @callback: a #GAsyncReadyCallback to call when the request is satisfied
7336 * @user_data: the data to pass to callback function
7338 * Same as g_file_replace_contents_async() but takes a #GBytes input instead.
7339 * This function will keep a ref on @contents until the operation is done.
7340 * Unlike g_file_replace_contents_async() this allows forgetting about the
7341 * content without waiting for the callback.
7343 * When this operation has completed, @callback will be called with
7344 * @user_user data, and the operation can be finalized with
7345 * g_file_replace_contents_finish().
7350 g_file_replace_contents_bytes_async (GFile
*file
,
7353 gboolean make_backup
,
7354 GFileCreateFlags flags
,
7355 GCancellable
*cancellable
,
7356 GAsyncReadyCallback callback
,
7359 ReplaceContentsData
*data
;
7361 g_return_if_fail (G_IS_FILE (file
));
7362 g_return_if_fail (contents
!= NULL
);
7364 data
= g_new0 (ReplaceContentsData
, 1);
7366 data
->content
= g_bytes_ref (contents
);
7368 data
->task
= g_task_new (file
, cancellable
, callback
, user_data
);
7369 g_task_set_task_data (data
->task
, data
, (GDestroyNotify
)replace_contents_data_free
);
7371 g_file_replace_async (file
,
7376 g_task_get_cancellable (data
->task
),
7377 replace_contents_open_callback
,
7382 * g_file_replace_contents_finish:
7383 * @file: input #GFile
7384 * @res: a #GAsyncResult
7385 * @new_etag: (out) (allow-none): a location of a new [entity tag][gfile-etag]
7386 * for the document. This should be freed with g_free() when it is no
7387 * longer needed, or %NULL
7388 * @error: a #GError, or %NULL
7390 * Finishes an asynchronous replace of the given @file. See
7391 * g_file_replace_contents_async(). Sets @new_etag to the new entity
7392 * tag for the document, if present.
7394 * Returns: %TRUE on success, %FALSE on failure.
7397 g_file_replace_contents_finish (GFile
*file
,
7403 ReplaceContentsData
*data
;
7405 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
7406 g_return_val_if_fail (g_task_is_valid (res
, file
), FALSE
);
7408 task
= G_TASK (res
);
7410 if (!g_task_propagate_boolean (task
, error
))
7413 data
= g_task_get_task_data (task
);
7417 *new_etag
= data
->etag
;
7418 data
->etag
= NULL
; /* Take ownership */
7425 g_file_real_measure_disk_usage (GFile
*file
,
7426 GFileMeasureFlags flags
,
7427 GCancellable
*cancellable
,
7428 GFileMeasureProgressCallback progress_callback
,
7429 gpointer progress_data
,
7430 guint64
*disk_usage
,
7435 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
7436 "Operation not supported for the current backend.");
7442 GFileMeasureFlags flags
;
7443 GFileMeasureProgressCallback progress_callback
;
7444 gpointer progress_data
;
7456 GFileMeasureProgressCallback callback
;
7459 guint64 current_size
;
7465 measure_disk_usage_invoke_progress (gpointer user_data
)
7467 MeasureProgress
*progress
= user_data
;
7469 (* progress
->callback
) (progress
->reporting
,
7470 progress
->current_size
, progress
->num_dirs
, progress
->num_files
,
7471 progress
->user_data
);
7477 measure_disk_usage_progress (gboolean reporting
,
7478 guint64 current_size
,
7483 MeasureProgress progress
;
7484 GTask
*task
= user_data
;
7485 MeasureTaskData
*data
;
7487 data
= g_task_get_task_data (task
);
7489 progress
.callback
= data
->progress_callback
;
7490 progress
.user_data
= data
->progress_data
;
7491 progress
.reporting
= reporting
;
7492 progress
.current_size
= current_size
;
7493 progress
.num_dirs
= num_dirs
;
7494 progress
.num_files
= num_files
;
7496 g_main_context_invoke_full (g_task_get_context (task
),
7497 g_task_get_priority (task
),
7498 measure_disk_usage_invoke_progress
,
7499 g_memdup (&progress
, sizeof progress
),
7504 measure_disk_usage_thread (GTask
*task
,
7505 gpointer source_object
,
7507 GCancellable
*cancellable
)
7509 MeasureTaskData
*data
= task_data
;
7510 GError
*error
= NULL
;
7511 MeasureResult result
;
7513 if (g_file_measure_disk_usage (source_object
, data
->flags
, cancellable
,
7514 data
->progress_callback
? measure_disk_usage_progress
: NULL
, task
,
7515 &result
.disk_usage
, &result
.num_dirs
, &result
.num_files
,
7517 g_task_return_pointer (task
, g_memdup (&result
, sizeof result
), g_free
);
7519 g_task_return_error (task
, error
);
7523 g_file_real_measure_disk_usage_async (GFile
*file
,
7524 GFileMeasureFlags flags
,
7526 GCancellable
*cancellable
,
7527 GFileMeasureProgressCallback progress_callback
,
7528 gpointer progress_data
,
7529 GAsyncReadyCallback callback
,
7532 MeasureTaskData data
;
7536 data
.progress_callback
= progress_callback
;
7537 data
.progress_data
= progress_data
;
7539 task
= g_task_new (file
, cancellable
, callback
, user_data
);
7540 g_task_set_task_data (task
, g_memdup (&data
, sizeof data
), g_free
);
7541 g_task_set_priority (task
, io_priority
);
7543 g_task_run_in_thread (task
, measure_disk_usage_thread
);
7544 g_object_unref (task
);
7548 g_file_real_measure_disk_usage_finish (GFile
*file
,
7549 GAsyncResult
*result
,
7550 guint64
*disk_usage
,
7555 MeasureResult
*measure_result
;
7557 g_return_val_if_fail (g_task_is_valid (result
, file
), FALSE
);
7559 measure_result
= g_task_propagate_pointer (G_TASK (result
), error
);
7561 if (measure_result
== NULL
)
7565 *disk_usage
= measure_result
->disk_usage
;
7568 *num_dirs
= measure_result
->num_dirs
;
7571 *num_files
= measure_result
->num_files
;
7573 g_free (measure_result
);
7579 * g_file_measure_disk_usage:
7581 * @flags: #GFileMeasureFlags
7582 * @cancellable: (allow-none): optional #GCancellable
7583 * @progress_callback: (allow-none): a #GFileMeasureProgressCallback
7584 * @progress_data: user_data for @progress_callback
7585 * @disk_usage: (allow-none) (out): the number of bytes of disk space used
7586 * @num_dirs: (allow-none) (out): the number of directories encountered
7587 * @num_files: (allow-none) (out): the number of non-directories encountered
7588 * @error: (allow-none): %NULL, or a pointer to a %NULL #GError pointer
7590 * Recursively measures the disk usage of @file.
7592 * This is essentially an analog of the 'du' command, but it also
7593 * reports the number of directories and non-directory files encountered
7594 * (including things like symbolic links).
7596 * By default, errors are only reported against the toplevel file
7597 * itself. Errors found while recursing are silently ignored, unless
7598 * %G_FILE_DISK_USAGE_REPORT_ALL_ERRORS is given in @flags.
7600 * The returned size, @disk_usage, is in bytes and should be formatted
7601 * with g_format_size() in order to get something reasonable for showing
7602 * in a user interface.
7604 * @progress_callback and @progress_data can be given to request
7605 * periodic progress updates while scanning. See the documentation for
7606 * #GFileMeasureProgressCallback for information about when and how the
7607 * callback will be invoked.
7609 * Returns: %TRUE if successful, with the out parameters set.
7610 * %FALSE otherwise, with @error set.
7615 g_file_measure_disk_usage (GFile
*file
,
7616 GFileMeasureFlags flags
,
7617 GCancellable
*cancellable
,
7618 GFileMeasureProgressCallback progress_callback
,
7619 gpointer progress_data
,
7620 guint64
*disk_usage
,
7625 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
7626 g_return_val_if_fail (cancellable
== NULL
|| G_IS_CANCELLABLE (cancellable
), FALSE
);
7627 g_return_val_if_fail (error
== NULL
|| *error
== NULL
, FALSE
);
7629 return G_FILE_GET_IFACE (file
)->measure_disk_usage (file
, flags
, cancellable
,
7630 progress_callback
, progress_data
,
7631 disk_usage
, num_dirs
, num_files
,
7636 * g_file_measure_disk_usage_async:
7638 * @flags: #GFileMeasureFlags
7639 * @io_priority: the [I/O priority][io-priority] of the request
7640 * @cancellable: (allow-none): optional #GCancellable
7641 * @progress_callback: (allow-none): a #GFileMeasureProgressCallback
7642 * @progress_data: user_data for @progress_callback
7643 * @callback: (allow-none): a #GAsyncReadyCallback to call when complete
7644 * @user_data: the data to pass to callback function
7646 * Recursively measures the disk usage of @file.
7648 * This is the asynchronous version of g_file_measure_disk_usage(). See
7649 * there for more information.
7654 g_file_measure_disk_usage_async (GFile
*file
,
7655 GFileMeasureFlags flags
,
7657 GCancellable
*cancellable
,
7658 GFileMeasureProgressCallback progress_callback
,
7659 gpointer progress_data
,
7660 GAsyncReadyCallback callback
,
7663 g_return_if_fail (G_IS_FILE (file
));
7664 g_return_if_fail (cancellable
== NULL
|| G_IS_CANCELLABLE (cancellable
));
7666 G_FILE_GET_IFACE (file
)->measure_disk_usage_async (file
, flags
, io_priority
, cancellable
,
7667 progress_callback
, progress_data
,
7668 callback
, user_data
);
7672 * g_file_measure_disk_usage_finish:
7674 * @result: the #GAsyncResult passed to your #GAsyncReadyCallback
7675 * @disk_usage: (allow-none) (out): the number of bytes of disk space used
7676 * @num_dirs: (allow-none) (out): the number of directories encountered
7677 * @num_files: (allow-none) (out): the number of non-directories encountered
7678 * @error: (allow-none): %NULL, or a pointer to a %NULL #GError pointer
7680 * Collects the results from an earlier call to
7681 * g_file_measure_disk_usage_async(). See g_file_measure_disk_usage() for
7684 * Returns: %TRUE if successful, with the out parameters set.
7685 * %FALSE otherwise, with @error set.
7690 g_file_measure_disk_usage_finish (GFile
*file
,
7691 GAsyncResult
*result
,
7692 guint64
*disk_usage
,
7697 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
7698 g_return_val_if_fail (error
== NULL
|| *error
== NULL
, FALSE
);
7700 return G_FILE_GET_IFACE (file
)->measure_disk_usage_finish (file
, result
, disk_usage
, num_dirs
, num_files
, error
);
7704 * g_file_start_mountable:
7705 * @file: input #GFile
7706 * @flags: flags affecting the operation
7707 * @start_operation: (allow-none): a #GMountOperation, or %NULL to avoid user interaction
7708 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
7709 * @callback: (allow-none): a #GAsyncReadyCallback to call when the request is satisfied, or %NULL
7710 * @user_data: the data to pass to callback function
7712 * Starts a file of type #G_FILE_TYPE_MOUNTABLE.
7713 * Using @start_operation, you can request callbacks when, for instance,
7714 * passwords are needed during authentication.
7716 * If @cancellable is not %NULL, then the operation can be cancelled by
7717 * triggering the cancellable object from another thread. If the operation
7718 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7720 * When the operation is finished, @callback will be called.
7721 * You can then call g_file_mount_mountable_finish() to get
7722 * the result of the operation.
7727 g_file_start_mountable (GFile
*file
,
7728 GDriveStartFlags flags
,
7729 GMountOperation
*start_operation
,
7730 GCancellable
*cancellable
,
7731 GAsyncReadyCallback callback
,
7736 g_return_if_fail (G_IS_FILE (file
));
7738 iface
= G_FILE_GET_IFACE (file
);
7740 if (iface
->start_mountable
== NULL
)
7742 g_task_report_new_error (file
, callback
, user_data
,
7743 g_file_start_mountable
,
7744 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
7745 _("Operation not supported"));
7749 (* iface
->start_mountable
) (file
,
7758 * g_file_start_mountable_finish:
7759 * @file: input #GFile
7760 * @result: a #GAsyncResult
7761 * @error: a #GError, or %NULL
7763 * Finishes a start operation. See g_file_start_mountable() for details.
7765 * Finish an asynchronous start operation that was started
7766 * with g_file_start_mountable().
7768 * Returns: %TRUE if the operation finished successfully. %FALSE
7774 g_file_start_mountable_finish (GFile
*file
,
7775 GAsyncResult
*result
,
7780 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
7781 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
7783 if (g_async_result_legacy_propagate_error (result
, error
))
7785 else if (g_async_result_is_tagged (result
, g_file_start_mountable
))
7786 return g_task_propagate_boolean (G_TASK (result
), error
);
7788 iface
= G_FILE_GET_IFACE (file
);
7789 return (* iface
->start_mountable_finish
) (file
, result
, error
);
7793 * g_file_stop_mountable:
7794 * @file: input #GFile
7795 * @flags: flags affecting the operation
7796 * @mount_operation: (allow-none): a #GMountOperation,
7797 * or %NULL to avoid user interaction.
7798 * @cancellable: (allow-none): optional #GCancellable object,
7800 * @callback: (allow-none): a #GAsyncReadyCallback to call
7801 * when the request is satisfied, or %NULL
7802 * @user_data: the data to pass to callback function
7804 * Stops a file of type #G_FILE_TYPE_MOUNTABLE.
7806 * If @cancellable is not %NULL, then the operation can be cancelled by
7807 * triggering the cancellable object from another thread. If the operation
7808 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7810 * When the operation is finished, @callback will be called.
7811 * You can then call g_file_stop_mountable_finish() to get
7812 * the result of the operation.
7817 g_file_stop_mountable (GFile
*file
,
7818 GMountUnmountFlags flags
,
7819 GMountOperation
*mount_operation
,
7820 GCancellable
*cancellable
,
7821 GAsyncReadyCallback callback
,
7826 g_return_if_fail (G_IS_FILE (file
));
7828 iface
= G_FILE_GET_IFACE (file
);
7830 if (iface
->stop_mountable
== NULL
)
7832 g_task_report_new_error (file
, callback
, user_data
,
7833 g_file_stop_mountable
,
7834 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
7835 _("Operation not supported"));
7839 (* iface
->stop_mountable
) (file
,
7848 * g_file_stop_mountable_finish:
7849 * @file: input #GFile
7850 * @result: a #GAsyncResult
7851 * @error: a #GError, or %NULL
7853 * Finishes an stop operation, see g_file_stop_mountable() for details.
7855 * Finish an asynchronous stop operation that was started
7856 * with g_file_stop_mountable().
7858 * Returns: %TRUE if the operation finished successfully.
7864 g_file_stop_mountable_finish (GFile
*file
,
7865 GAsyncResult
*result
,
7870 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
7871 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
7873 if (g_async_result_legacy_propagate_error (result
, error
))
7875 else if (g_async_result_is_tagged (result
, g_file_stop_mountable
))
7876 return g_task_propagate_boolean (G_TASK (result
), error
);
7878 iface
= G_FILE_GET_IFACE (file
);
7879 return (* iface
->stop_mountable_finish
) (file
, result
, error
);
7883 * g_file_poll_mountable:
7884 * @file: input #GFile
7885 * @cancellable: optional #GCancellable object, %NULL to ignore
7886 * @callback: (allow-none): a #GAsyncReadyCallback to call
7887 * when the request is satisfied, or %NULL
7888 * @user_data: the data to pass to callback function
7890 * Polls a file of type #G_FILE_TYPE_MOUNTABLE.
7892 * If @cancellable is not %NULL, then the operation can be cancelled by
7893 * triggering the cancellable object from another thread. If the operation
7894 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
7896 * When the operation is finished, @callback will be called.
7897 * You can then call g_file_mount_mountable_finish() to get
7898 * the result of the operation.
7903 g_file_poll_mountable (GFile
*file
,
7904 GCancellable
*cancellable
,
7905 GAsyncReadyCallback callback
,
7910 g_return_if_fail (G_IS_FILE (file
));
7912 iface
= G_FILE_GET_IFACE (file
);
7914 if (iface
->poll_mountable
== NULL
)
7916 g_task_report_new_error (file
, callback
, user_data
,
7917 g_file_poll_mountable
,
7918 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
7919 _("Operation not supported"));
7923 (* iface
->poll_mountable
) (file
,
7930 * g_file_poll_mountable_finish:
7931 * @file: input #GFile
7932 * @result: a #GAsyncResult
7933 * @error: a #GError, or %NULL
7935 * Finishes a poll operation. See g_file_poll_mountable() for details.
7937 * Finish an asynchronous poll operation that was polled
7938 * with g_file_poll_mountable().
7940 * Returns: %TRUE if the operation finished successfully. %FALSE
7946 g_file_poll_mountable_finish (GFile
*file
,
7947 GAsyncResult
*result
,
7952 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
7953 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
7955 if (g_async_result_legacy_propagate_error (result
, error
))
7957 else if (g_async_result_is_tagged (result
, g_file_poll_mountable
))
7958 return g_task_propagate_boolean (G_TASK (result
), error
);
7960 iface
= G_FILE_GET_IFACE (file
);
7961 return (* iface
->poll_mountable_finish
) (file
, result
, error
);
7965 * g_file_supports_thread_contexts:
7968 * Checks if @file supports
7969 * [thread-default contexts][g-main-context-push-thread-default-context].
7970 * If this returns %FALSE, you cannot perform asynchronous operations on
7971 * @file in a thread that has a thread-default context.
7973 * Returns: Whether or not @file supports thread-default contexts.
7978 g_file_supports_thread_contexts (GFile
*file
)
7982 g_return_val_if_fail (G_IS_FILE (file
), FALSE
);
7984 iface
= G_FILE_GET_IFACE (file
);
7985 return iface
->supports_thread_contexts
;