Implement this function by moving bits from glocalfileinfo.c
2008-02-21 David Zeuthen <davidz@redhat.com>
* glocalfileinfo.c: (_g_local_file_info_get):
* gcontenttype.c:
(g_content_type_get_icon): Implement this function by
moving bits from glocalfileinfo.c
(g_content_type_get_description): Unalias before getting
description (#517687)
* gfile.c: (g_file_class_init),
(g_file_query_filesystem_info_async),
(g_file_query_filesystem_info_finish),
(query_filesystem_info_data_free),
(query_filesystem_info_async_thread),
(g_file_real_query_filesystem_info_async),
(g_file_real_query_filesystem_info_finish):
* gfile.h: Implement async version of
g_file_query_filesystem_info()
* gfileinfo.h: Add new attributes for filesystem::use-preview
* gio.symbols: Update
* gthemedicon.c: (g_themed_icon_append_name):
* gthemedicon.h: Add new new convenience function.
* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
(get_mounts), (get_volumes), (get_connected_drives),
(get_volume_for_uuid), (get_mount_for_uuid),
(g_union_volume_monitor_init), (populate_union_monitor),
(g_volume_monitor_get), (_g_mount_get_for_mount_path),
(g_volume_monitor_adopt_orphan_mount):
* gvolumemonitor.c:
* gvolumemonitor.h: Use recursive locks so it's safe for volume
monitor implementations to call into the main volume monitor. Also
separate object initialization and volume monitor initialization
such that non-native volume monitors can properly adopt their
mounts away.
svn path=/trunk/; revision=6550
2008-02-21 13:35:05 +01:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/* GIO - GLib Input, Output and Streaming Library
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2007 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General
|
|
|
|
* Public License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Author: Alexander Larsson <alexl@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-06-22 17:10:51 +02:00
|
|
|
#include "config.h"
|
2007-11-26 17:13:05 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
|
|
|
#include "gfile.h"
|
|
|
|
#include "gvfs.h"
|
|
|
|
#include "gioscheduler.h"
|
|
|
|
#include "gsimpleasyncresult.h"
|
2007-12-14 16:56:56 +01:00
|
|
|
#include "gfileattribute-priv.h"
|
2007-11-26 17:13:05 +01:00
|
|
|
#include "gpollfilemonitor.h"
|
2008-07-01 08:32:35 +02:00
|
|
|
#include "gappinfo.h"
|
|
|
|
#include "gfileinputstream.h"
|
|
|
|
#include "gfileoutputstream.h"
|
|
|
|
#include "gcancellable.h"
|
|
|
|
#include "gasyncresult.h"
|
|
|
|
#include "gioerror.h"
|
2007-11-26 17:13:05 +01:00
|
|
|
#include "glibintl.h"
|
|
|
|
|
2007-11-28 13:39:07 +01:00
|
|
|
#include "gioalias.h"
|
|
|
|
|
2007-11-27 15:00:13 +01:00
|
|
|
/**
|
|
|
|
* SECTION:gfile
|
|
|
|
* @short_description: File and Directory Handling
|
2008-02-21 19:20:17 +01:00
|
|
|
* @include: gio/gio.h
|
2007-11-27 15:00:13 +01:00
|
|
|
* @see_also: #GFileInfo, #GFileEnumerator
|
|
|
|
*
|
|
|
|
* #GFile is a high level abstraction for manipulating files on a
|
|
|
|
* virtual file system. #GFile<!-- -->s are lightweight, immutable
|
|
|
|
* objects that do no I/O upon creation. It is necessary to understand that
|
2008-02-21 11:21:11 +01:00
|
|
|
* #GFile objects do not represent files, merely an identifier for a file. All
|
|
|
|
* file content I/O is implemented as streaming operations (see #GInputStream and
|
2007-11-30 19:11:03 +01:00
|
|
|
* #GOutputStream).
|
2008-02-21 11:21:11 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* To construct a #GFile, you can use:
|
|
|
|
* g_file_new_for_path() if you have a path.
|
|
|
|
* g_file_new_for_uri() if you have a URI.
|
2007-12-09 16:51:12 +01:00
|
|
|
* g_file_new_for_commandline_arg() for a command line argument.
|
2008-02-21 11:21:11 +01:00
|
|
|
* g_file_parse_name() from a utf8 string gotten from g_file_get_parse_name().
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2008-02-21 11:21:11 +01:00
|
|
|
* One way to think of a #GFile is as an abstraction of a pathname. For normal
|
2008-02-21 19:20:17 +01:00
|
|
|
* files the system pathname is what is stored internally, but as #GFile<!-- -->s
|
2008-02-21 11:21:11 +01:00
|
|
|
* are extensible it could also be something else that corresponds to a pathname
|
|
|
|
* in a userspace implementation of a filesystem.
|
|
|
|
*
|
|
|
|
* #GFile<!-- -->s make up hierarchies of directories and files that correspond to the
|
|
|
|
* files on a filesystem. You can move through the file system with #GFile using
|
|
|
|
* g_file_get_parent() to get an identifier for the parent directory, g_file_get_child()
|
|
|
|
* to get a child within a directory, g_file_resolve_relative_path() to resolve a relative
|
|
|
|
* path between two #GFile<!-- -->s. There can be multiple hierarchies, so you may not
|
|
|
|
* end up at the same root if you repeatedly call g_file_get_parent() on two different
|
|
|
|
* files.
|
|
|
|
*
|
|
|
|
* All #GFile<!-- -->s have a basename (get with g_file_get_basename()). These names
|
|
|
|
* are byte strings that are used to identify the file on the filesystem (relative to
|
|
|
|
* its parent directory) and there is no guarantees that they have any particular charset
|
|
|
|
* encoding or even make any sense at all. If you want to use filenames in a user
|
|
|
|
* interface you should use the display name that you can get by requesting the
|
|
|
|
* %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info().
|
|
|
|
* This is guaranteed to be in utf8 and can be used in a user interface. But always
|
|
|
|
* store the real basename or the #GFile to use to actually access the file, because
|
|
|
|
* there is no way to go from a display name to the actual name.
|
|
|
|
*
|
2008-02-21 12:44:48 +01:00
|
|
|
* Using #GFile as an identifier has the same weaknesses as using a path in that
|
2008-02-21 11:21:11 +01:00
|
|
|
* there may be multiple aliases for the same file. For instance, hard or
|
|
|
|
* soft links may cause two different #GFile<!-- -->s to refer to the same file.
|
|
|
|
* Other possible causes for aliases are: case insensitive filesystems, short
|
2008-03-31 05:30:48 +02:00
|
|
|
* and long names on Fat/NTFS, or bind mounts in Linux. If you want to check if
|
2008-02-21 11:21:11 +01:00
|
|
|
* two #GFile<!-- -->s point to the same file you can query for the
|
|
|
|
* %G_FILE_ATTRIBUTE_ID_FILE attribute. Note that #GFile does some trivial
|
|
|
|
* canonicalization of pathnames passed in, so that trivial differences in the
|
2008-03-31 05:30:48 +02:00
|
|
|
* path string used at creation (duplicated slashes, slash at end of path, "."
|
2008-02-21 11:21:11 +01:00
|
|
|
* or ".." path segments, etc) does not create different #GFile<!-- -->s.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-11-29 11:18:55 +01:00
|
|
|
* Many #GFile operations have both synchronous and asynchronous versions
|
|
|
|
* to suit your application. Asynchronous versions of synchronous functions
|
|
|
|
* simply have _async() appended to their function names. The asynchronous
|
|
|
|
* I/O functions call a #GAsyncReadyCallback which is then used to finalize
|
2008-01-11 17:23:30 +01:00
|
|
|
* the operation, producing a GAsyncResult which is then passed to the
|
2008-03-31 05:30:48 +02:00
|
|
|
* function's matching _finish() operation.
|
2007-11-29 11:18:55 +01:00
|
|
|
*
|
|
|
|
* Some #GFile operations do not have synchronous analogs, as they may
|
|
|
|
* take a very long time to finish, and blocking may leave an application
|
|
|
|
* unusable. Notable cases include:
|
|
|
|
* g_file_mount_mountable() to mount a mountable file.
|
2009-07-06 03:59:38 +02:00
|
|
|
* g_file_unmount_mountable_with_operation() to unmount a mountable file.
|
|
|
|
* g_file_eject_mountable_with_operation() to eject a mountable file.
|
2007-11-29 11:18:55 +01:00
|
|
|
*
|
2007-11-30 19:11:03 +01:00
|
|
|
* <para id="gfile-etag"><indexterm><primary>entity tag</primary></indexterm>
|
|
|
|
* One notable feature of #GFile<!-- -->s are entity tags, or "etags" for
|
|
|
|
* short. Entity tags are somewhat like a more abstract version of the
|
|
|
|
* traditional mtime, and can be used to quickly determine if the file has
|
|
|
|
* been modified from the version on the file system. See the HTTP 1.1
|
2007-12-01 05:38:29 +01:00
|
|
|
* <ulink url="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">specification</ulink>
|
2007-11-30 19:11:03 +01:00
|
|
|
* for HTTP Etag headers, which are a very similar concept.
|
|
|
|
* </para>
|
2007-11-27 15:00:13 +01:00
|
|
|
**/
|
|
|
|
|
2008-01-24 12:04:05 +01:00
|
|
|
static void g_file_real_query_info_async (GFile *file,
|
|
|
|
const char *attributes,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static GFileInfo * g_file_real_query_info_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
Implement this function by moving bits from glocalfileinfo.c
2008-02-21 David Zeuthen <davidz@redhat.com>
* glocalfileinfo.c: (_g_local_file_info_get):
* gcontenttype.c:
(g_content_type_get_icon): Implement this function by
moving bits from glocalfileinfo.c
(g_content_type_get_description): Unalias before getting
description (#517687)
* gfile.c: (g_file_class_init),
(g_file_query_filesystem_info_async),
(g_file_query_filesystem_info_finish),
(query_filesystem_info_data_free),
(query_filesystem_info_async_thread),
(g_file_real_query_filesystem_info_async),
(g_file_real_query_filesystem_info_finish):
* gfile.h: Implement async version of
g_file_query_filesystem_info()
* gfileinfo.h: Add new attributes for filesystem::use-preview
* gio.symbols: Update
* gthemedicon.c: (g_themed_icon_append_name):
* gthemedicon.h: Add new new convenience function.
* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
(get_mounts), (get_volumes), (get_connected_drives),
(get_volume_for_uuid), (get_mount_for_uuid),
(g_union_volume_monitor_init), (populate_union_monitor),
(g_volume_monitor_get), (_g_mount_get_for_mount_path),
(g_volume_monitor_adopt_orphan_mount):
* gvolumemonitor.c:
* gvolumemonitor.h: Use recursive locks so it's safe for volume
monitor implementations to call into the main volume monitor. Also
separate object initialization and volume monitor initialization
such that non-native volume monitors can properly adopt their
mounts away.
svn path=/trunk/; revision=6550
2008-02-21 13:35:05 +01:00
|
|
|
static void g_file_real_query_filesystem_info_async (GFile *file,
|
|
|
|
const char *attributes,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static GFileInfo * g_file_real_query_filesystem_info_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
2008-01-24 12:04:05 +01:00
|
|
|
static void g_file_real_enumerate_children_async (GFile *file,
|
|
|
|
const char *attributes,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static GFileEnumerator * g_file_real_enumerate_children_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
|
|
|
static void g_file_real_read_async (GFile *file,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static GFileInputStream * g_file_real_read_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
|
|
|
static void g_file_real_append_to_async (GFile *file,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static GFileOutputStream *g_file_real_append_to_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
|
|
|
static void g_file_real_create_async (GFile *file,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static GFileOutputStream *g_file_real_create_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
|
|
|
static void g_file_real_replace_async (GFile *file,
|
|
|
|
const char *etag,
|
|
|
|
gboolean make_backup,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static GFileOutputStream *g_file_real_replace_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
2009-05-13 13:00:26 +02:00
|
|
|
static void g_file_real_open_readwrite_async (GFile *file,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static GFileIOStream * g_file_real_open_readwrite_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
|
|
|
static void g_file_real_create_readwrite_async (GFile *file,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static GFileIOStream * g_file_real_create_readwrite_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
|
|
|
static void g_file_real_replace_readwrite_async (GFile *file,
|
|
|
|
const char *etag,
|
|
|
|
gboolean make_backup,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static GFileIOStream * g_file_real_replace_readwrite_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
2008-01-24 12:04:05 +01:00
|
|
|
static gboolean g_file_real_set_attributes_from_info (GFile *file,
|
|
|
|
GFileInfo *info,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error);
|
|
|
|
static void g_file_real_set_display_name_async (GFile *file,
|
|
|
|
const char *display_name,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static GFile * g_file_real_set_display_name_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
|
|
|
static void g_file_real_set_attributes_async (GFile *file,
|
|
|
|
GFileInfo *info,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static gboolean g_file_real_set_attributes_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GFileInfo **info,
|
|
|
|
GError **error);
|
|
|
|
static void g_file_real_find_enclosing_mount_async (GFile *file,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static GMount * g_file_real_find_enclosing_mount_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
|
|
|
static void g_file_real_copy_async (GFile *source,
|
|
|
|
GFile *destination,
|
|
|
|
GFileCopyFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GFileProgressCallback progress_callback,
|
|
|
|
gpointer progress_callback_data,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static gboolean g_file_real_copy_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2009-12-01 10:42:58 +01:00
|
|
|
typedef GFileIface GFileInterface;
|
|
|
|
G_DEFINE_INTERFACE (GFile, g_file, G_TYPE_OBJECT)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
static void
|
2009-12-01 10:42:58 +01:00
|
|
|
g_file_default_init (GFileIface *iface)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
iface->enumerate_children_async = g_file_real_enumerate_children_async;
|
|
|
|
iface->enumerate_children_finish = g_file_real_enumerate_children_finish;
|
|
|
|
iface->set_display_name_async = g_file_real_set_display_name_async;
|
|
|
|
iface->set_display_name_finish = g_file_real_set_display_name_finish;
|
|
|
|
iface->query_info_async = g_file_real_query_info_async;
|
|
|
|
iface->query_info_finish = g_file_real_query_info_finish;
|
Implement this function by moving bits from glocalfileinfo.c
2008-02-21 David Zeuthen <davidz@redhat.com>
* glocalfileinfo.c: (_g_local_file_info_get):
* gcontenttype.c:
(g_content_type_get_icon): Implement this function by
moving bits from glocalfileinfo.c
(g_content_type_get_description): Unalias before getting
description (#517687)
* gfile.c: (g_file_class_init),
(g_file_query_filesystem_info_async),
(g_file_query_filesystem_info_finish),
(query_filesystem_info_data_free),
(query_filesystem_info_async_thread),
(g_file_real_query_filesystem_info_async),
(g_file_real_query_filesystem_info_finish):
* gfile.h: Implement async version of
g_file_query_filesystem_info()
* gfileinfo.h: Add new attributes for filesystem::use-preview
* gio.symbols: Update
* gthemedicon.c: (g_themed_icon_append_name):
* gthemedicon.h: Add new new convenience function.
* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
(get_mounts), (get_volumes), (get_connected_drives),
(get_volume_for_uuid), (get_mount_for_uuid),
(g_union_volume_monitor_init), (populate_union_monitor),
(g_volume_monitor_get), (_g_mount_get_for_mount_path),
(g_volume_monitor_adopt_orphan_mount):
* gvolumemonitor.c:
* gvolumemonitor.h: Use recursive locks so it's safe for volume
monitor implementations to call into the main volume monitor. Also
separate object initialization and volume monitor initialization
such that non-native volume monitors can properly adopt their
mounts away.
svn path=/trunk/; revision=6550
2008-02-21 13:35:05 +01:00
|
|
|
iface->query_filesystem_info_async = g_file_real_query_filesystem_info_async;
|
|
|
|
iface->query_filesystem_info_finish = g_file_real_query_filesystem_info_finish;
|
2007-11-26 17:13:05 +01:00
|
|
|
iface->set_attributes_async = g_file_real_set_attributes_async;
|
|
|
|
iface->set_attributes_finish = g_file_real_set_attributes_finish;
|
|
|
|
iface->read_async = g_file_real_read_async;
|
|
|
|
iface->read_finish = g_file_real_read_finish;
|
|
|
|
iface->append_to_async = g_file_real_append_to_async;
|
|
|
|
iface->append_to_finish = g_file_real_append_to_finish;
|
|
|
|
iface->create_async = g_file_real_create_async;
|
|
|
|
iface->create_finish = g_file_real_create_finish;
|
|
|
|
iface->replace_async = g_file_real_replace_async;
|
|
|
|
iface->replace_finish = g_file_real_replace_finish;
|
2009-05-13 13:00:26 +02:00
|
|
|
iface->open_readwrite_async = g_file_real_open_readwrite_async;
|
|
|
|
iface->open_readwrite_finish = g_file_real_open_readwrite_finish;
|
|
|
|
iface->create_readwrite_async = g_file_real_create_readwrite_async;
|
|
|
|
iface->create_readwrite_finish = g_file_real_create_readwrite_finish;
|
|
|
|
iface->replace_readwrite_async = g_file_real_replace_readwrite_async;
|
|
|
|
iface->replace_readwrite_finish = g_file_real_replace_readwrite_finish;
|
2008-01-17 15:22:13 +01:00
|
|
|
iface->find_enclosing_mount_async = g_file_real_find_enclosing_mount_async;
|
|
|
|
iface->find_enclosing_mount_finish = g_file_real_find_enclosing_mount_finish;
|
2007-11-26 17:13:05 +01:00
|
|
|
iface->set_attributes_from_info = g_file_real_set_attributes_from_info;
|
2008-01-24 12:04:05 +01:00
|
|
|
iface->copy_async = g_file_real_copy_async;
|
|
|
|
iface->copy_finish = g_file_real_copy_finish;
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_is_native:
|
|
|
|
* @file: input #GFile.
|
|
|
|
*
|
2007-12-02 13:32:27 +01:00
|
|
|
* Checks to see if a file is native to the platform.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* A native file s one expressed in the platform-native filename format,
|
|
|
|
* e.g. "C:\Windows" or "/usr/bin/". This does not mean the file is local,
|
|
|
|
* as it might be on a locally mounted remote filesystem.
|
|
|
|
*
|
2008-01-11 17:23:30 +01:00
|
|
|
* On some systems non-native files may be available using
|
2007-12-12 13:19:02 +01:00
|
|
|
* the native filesystem via a userspace filesystem (FUSE), in
|
|
|
|
* these cases this call will return %FALSE, but g_file_get_path()
|
|
|
|
* will still return a native path.
|
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Returns: %TRUE if file is native.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_file_is_native (GFile *file)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->is_native) (file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_has_uri_scheme:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @uri_scheme: a string containing a URI scheme.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Checks to see if a #GFile has a given URI scheme.
|
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE if #GFile's backend supports the
|
2007-11-29 08:17:59 +01:00
|
|
|
* given URI scheme, %FALSE if URI scheme is %NULL,
|
|
|
|
* not supported, or #GFile is invalid.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_has_uri_scheme (GFile *file,
|
2007-11-26 17:13:05 +01:00
|
|
|
const char *uri_scheme)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (uri_scheme != NULL, FALSE);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->has_uri_scheme) (file, uri_scheme);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_get_uri_scheme:
|
|
|
|
* @file: input #GFile.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Gets the URI scheme for a #GFile.
|
2007-11-26 17:13:05 +01:00
|
|
|
* RFC 3986 decodes the scheme as:
|
2007-11-28 07:43:33 +01:00
|
|
|
* <programlisting>
|
2007-11-26 17:13:05 +01:00
|
|
|
* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
|
2007-11-28 07:43:33 +01:00
|
|
|
* </programlisting>
|
2007-12-12 13:19:02 +01:00
|
|
|
* Common schemes include "file", "http", "ftp", etc.
|
2007-11-28 07:43:33 +01:00
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-11-28 07:43:33 +01:00
|
|
|
* Returns: a string containing the URI scheme for the given
|
|
|
|
* #GFile. The returned string should be freed with g_free()
|
|
|
|
* when no longer needed.
|
2007-11-29 11:18:55 +01:00
|
|
|
**/
|
2007-11-26 17:13:05 +01:00
|
|
|
char *
|
|
|
|
g_file_get_uri_scheme (GFile *file)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->get_uri_scheme) (file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_get_basename:
|
|
|
|
* @file: input #GFile.
|
|
|
|
*
|
2008-01-11 17:23:30 +01:00
|
|
|
* Gets the base name (the last component of the path) for a given #GFile.
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
2008-01-11 17:23:30 +01:00
|
|
|
* If called for the top level of a system (such as the filesystem root
|
2008-02-21 11:21:11 +01:00
|
|
|
* or a uri like sftp://host/) it will return a single directory separator
|
2007-12-12 13:19:02 +01:00
|
|
|
* (and on Windows, possibly a drive letter).
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2008-02-21 11:21:11 +01:00
|
|
|
* The base name is a byte string (*not* UTF-8). It has no defined encoding
|
|
|
|
* or rules other than it may not contain zero bytes. If you want to use
|
|
|
|
* filenames in a user interface you should use the display name that you
|
|
|
|
* can get by requesting the %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
|
|
|
|
* attribute with g_file_query_info().
|
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-11-28 07:43:33 +01:00
|
|
|
* Returns: string containing the #GFile's base name, or %NULL
|
|
|
|
* if given #GFile is invalid. The returned string should be
|
|
|
|
* freed with g_free() when no longer needed.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
char *
|
|
|
|
g_file_get_basename (GFile *file)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->get_basename) (file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_get_path:
|
|
|
|
* @file: input #GFile.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Gets the local pathname for #GFile, if one exists.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-11-28 07:43:33 +01:00
|
|
|
* Returns: string containing the #GFile's path, or %NULL if
|
2007-12-12 13:19:02 +01:00
|
|
|
* no such path exists. The returned string should be
|
2007-11-28 07:43:33 +01:00
|
|
|
* freed with g_free() when no longer needed.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
char *
|
|
|
|
g_file_get_path (GFile *file)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->get_path) (file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_get_uri:
|
|
|
|
* @file: input #GFile.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Gets the URI for the @file.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Returns: a string containing the #GFile's URI.
|
|
|
|
* The returned string should be freed with g_free() when no longer needed.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
char *
|
|
|
|
g_file_get_uri (GFile *file)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->get_uri) (file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-28 07:01:13 +01:00
|
|
|
* g_file_get_parse_name:
|
2007-11-26 17:13:05 +01:00
|
|
|
* @file: input #GFile.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Gets the parse name of the @file.
|
|
|
|
* A parse name is a UTF-8 string that describes the
|
|
|
|
* file such that one can get the #GFile back using
|
|
|
|
* g_file_parse_name().
|
|
|
|
*
|
|
|
|
* This is generally used to show the #GFile as a nice
|
2008-02-21 11:21:11 +01:00
|
|
|
* full-pathname kind of string in a user interface,
|
|
|
|
* like in a location entry.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* For local files with names that can safely be converted
|
|
|
|
* to UTF8 the pathname is used, otherwise the IRI is used
|
|
|
|
* (a form of URI that allows UTF8 characters unescaped).
|
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Returns: a string containing the #GFile's parse name. The returned
|
2007-11-28 07:43:33 +01:00
|
|
|
* string should be freed with g_free() when no longer needed.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
char *
|
|
|
|
g_file_get_parse_name (GFile *file)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->get_parse_name) (file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_dup:
|
|
|
|
* @file: input #GFile.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Duplicates a #GFile handle. This operation does not duplicate
|
2007-11-28 07:43:33 +01:00
|
|
|
* the actual file or directory represented by the #GFile; see
|
|
|
|
* g_file_copy() if attempting to copy a file.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2008-07-16 07:49:16 +02:00
|
|
|
* Returns: a new #GFile that is a duplicate of the given #GFile.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFile *
|
|
|
|
g_file_dup (GFile *file)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->dup) (file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_hash:
|
|
|
|
* @file: #gconstpointer to a #GFile.
|
|
|
|
*
|
2007-11-28 07:43:33 +01:00
|
|
|
* Creates a hash value for a #GFile.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-11-28 07:43:33 +01:00
|
|
|
* Returns: 0 if @file is not a valid #GFile, otherwise an
|
2007-12-09 16:51:12 +01:00
|
|
|
* integer that can be used as hash value for the #GFile.
|
|
|
|
* This function is intended for easily hashing a #GFile to
|
|
|
|
* add to a #GHashTable or similar data structure.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
guint
|
|
|
|
g_file_hash (gconstpointer file)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), 0);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->hash) ((GFile *)file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_equal:
|
|
|
|
* @file1: the first #GFile.
|
|
|
|
* @file2: the second #GFile.
|
|
|
|
*
|
2008-02-21 11:21:11 +01:00
|
|
|
* Checks equality of two given #GFile<!-- -->s. Note that two
|
|
|
|
* #GFile<!-- -->s that differ can still refer to the same
|
|
|
|
* file on the filesystem due to various forms of filename
|
|
|
|
* aliasing.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE if @file1 and @file2 are equal.
|
2007-12-09 16:51:12 +01:00
|
|
|
* %FALSE if either is not a #GFile.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_file_equal (GFile *file1,
|
|
|
|
GFile *file2)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file1), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file2), FALSE);
|
|
|
|
|
|
|
|
if (G_TYPE_FROM_INSTANCE (file1) != G_TYPE_FROM_INSTANCE (file2))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file1);
|
|
|
|
|
|
|
|
return (* iface->equal) (file1, file2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_get_parent:
|
|
|
|
* @file: input #GFile.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Gets the parent directory for the @file.
|
|
|
|
* If the @file represents the root directory of the
|
2007-11-26 17:13:05 +01:00
|
|
|
* file system, then %NULL will be returned.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Returns: a #GFile structure to the parent of the given
|
2007-12-12 13:19:02 +01:00
|
|
|
* #GFile or %NULL if there is no parent.
|
2008-07-09 06:26:47 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFile *
|
|
|
|
g_file_get_parent (GFile *file)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->get_parent) (file);
|
|
|
|
}
|
|
|
|
|
2009-11-12 07:37:27 +01:00
|
|
|
/**
|
|
|
|
* g_file_has_parent:
|
|
|
|
* @file: input #GFile
|
|
|
|
* @parent: the parent to check for, or %NULL
|
|
|
|
*
|
|
|
|
* Checks if @file has a parent, and optionally, if it is @parent.
|
|
|
|
*
|
|
|
|
* If @parent is %NULL then this function returns %TRUE if @file has any
|
|
|
|
* parent at all. If @parent is non-%NULL then %TRUE is only returned
|
|
|
|
* if @file is a child of @parent.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @file is a child of @parent (or any parent in the
|
|
|
|
* case that @parent is %NULL).
|
|
|
|
*
|
|
|
|
* Since: 2.24
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_file_has_parent (GFile *file,
|
|
|
|
GFile *parent)
|
|
|
|
{
|
|
|
|
GFile *actual_parent;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (parent == NULL || G_IS_FILE (parent), FALSE);
|
|
|
|
|
|
|
|
actual_parent = g_file_get_parent (file);
|
|
|
|
|
|
|
|
if (actual_parent != NULL)
|
|
|
|
{
|
|
|
|
if (parent != NULL)
|
|
|
|
result = g_file_equal (parent, actual_parent);
|
|
|
|
else
|
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
g_object_unref (actual_parent);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result = FALSE;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/**
|
|
|
|
* g_file_get_child:
|
|
|
|
* @file: input #GFile.
|
2008-02-21 11:21:11 +01:00
|
|
|
* @name: string containing the child's basename.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2008-02-21 11:21:11 +01:00
|
|
|
* Gets a child of @file with basename equal to @name.
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
|
|
|
* Note that the file with that specific name might not exist, but
|
|
|
|
* you can still have a #GFile that points to it. You can use this
|
|
|
|
* for instance to create that file.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Returns: a #GFile to a child specified by @name.
|
2008-07-09 06:26:47 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFile *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_get_child (GFile *file,
|
2007-11-26 17:13:05 +01:00
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
|
|
|
return g_file_resolve_relative_path (file, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_get_child_for_display_name:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @display_name: string to a possible child.
|
|
|
|
* @error: #GError.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Gets the child of @file for a given @display_name (i.e. a UTF8
|
|
|
|
* version of the name). If this function fails, it returns %NULL and @error will be
|
2007-12-17 12:26:34 +01:00
|
|
|
* set. This is very useful when constructing a GFile for a new file
|
|
|
|
* and the user entered the filename in the user interface, for instance
|
|
|
|
* when you select a directory and type a filename in the file selector.
|
|
|
|
*
|
|
|
|
* This call does no blocking i/o.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Returns: a #GFile to the specified child, or
|
2007-12-12 13:19:02 +01:00
|
|
|
* %NULL if the display name couldn't be converted.
|
2008-07-09 06:26:47 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFile *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_get_child_for_display_name (GFile *file,
|
2007-11-26 17:13:05 +01:00
|
|
|
const char *display_name,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (display_name != NULL, NULL);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->get_child_for_display_name) (file, display_name, error);
|
|
|
|
}
|
|
|
|
|
2008-02-21 10:09:59 +01:00
|
|
|
/**
|
|
|
|
* g_file_has_prefix:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @prefix: input #GFile.
|
|
|
|
*
|
2008-07-09 06:26:47 +02:00
|
|
|
* Checks whether @file has the prefix specified by @prefix. In other word,
|
|
|
|
* if the names of inital elements of @file<!-- -->s pathname match @prefix.
|
2009-02-26 16:03:11 +01:00
|
|
|
* Only full pathname elements are matched, so a path like /foo is not
|
|
|
|
* considered a prefix of /foobar, only of /foo/bar.
|
2008-02-21 10:09:59 +01:00
|
|
|
*
|
2008-07-09 06:26:47 +02:00
|
|
|
* This call does no i/o, as it works purely on names. As such it can
|
|
|
|
* sometimes return %FALSE even if @file is inside a @prefix (from a
|
|
|
|
* filesystem point of view), because the prefix of @file is an alias
|
|
|
|
* of @prefix.
|
2008-02-21 10:09:59 +01:00
|
|
|
*
|
2008-07-09 06:26:47 +02:00
|
|
|
* Returns: %TRUE if the @files's parent, grandparent, etc is @prefix.
|
|
|
|
* %FALSE otherwise.
|
2008-02-21 10:09:59 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_file_has_prefix (GFile *file,
|
|
|
|
GFile *prefix)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
2008-02-21 10:09:59 +01:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_FILE (prefix), FALSE);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2008-02-21 10:09:59 +01:00
|
|
|
if (G_TYPE_FROM_INSTANCE (file) != G_TYPE_FROM_INSTANCE (prefix))
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2008-02-21 10:09:59 +01:00
|
|
|
iface = G_FILE_GET_IFACE (file);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2008-02-21 10:09:59 +01:00
|
|
|
/* The vtable function differs in arg order since we're
|
|
|
|
using the old contains_file call */
|
|
|
|
return (* iface->prefix_matches) (prefix, file);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_get_relative_path:
|
|
|
|
* @parent: input #GFile.
|
|
|
|
* @descendant: input #GFile.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Gets the path for @descendant relative to @parent.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-11-28 07:43:33 +01:00
|
|
|
* Returns: string with the relative path from @descendant
|
2008-07-09 06:26:47 +02:00
|
|
|
* to @parent, or %NULL if @descendant doesn't have @parent as prefix.
|
|
|
|
* The returned string should be freed with g_free() when no longer needed.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
char *
|
|
|
|
g_file_get_relative_path (GFile *parent,
|
|
|
|
GFile *descendant)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (parent), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_FILE (descendant), NULL);
|
|
|
|
|
|
|
|
if (G_TYPE_FROM_INSTANCE (parent) != G_TYPE_FROM_INSTANCE (descendant))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (parent);
|
|
|
|
|
|
|
|
return (* iface->get_relative_path) (parent, descendant);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_resolve_relative_path:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @relative_path: a given relative path string.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Resolves a relative path for @file to an absolute path.
|
|
|
|
*
|
2007-12-17 12:26:34 +01:00
|
|
|
* This call does no blocking i/o.
|
|
|
|
*
|
2007-11-28 07:43:33 +01:00
|
|
|
* Returns: #GFile to the resolved path. %NULL if @relative_path
|
|
|
|
* is %NULL or if @file is invalid.
|
2008-07-09 06:26:47 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFile *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_resolve_relative_path (GFile *file,
|
2007-11-26 17:13:05 +01:00
|
|
|
const char *relative_path)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (relative_path != NULL, NULL);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->resolve_relative_path) (file, relative_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_enumerate_children:
|
|
|
|
* @file: input #GFile.
|
2007-12-12 13:19:02 +01:00
|
|
|
* @attributes: an attribute query string.
|
2007-11-27 15:00:13 +01:00
|
|
|
* @flags: a set of #GFileQueryInfoFlags.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @error: #GError for error reporting.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Gets the requested information about the files in a directory. The result
|
|
|
|
* is a #GFileEnumerator object that will give out #GFileInfo objects for
|
|
|
|
* all the files in the directory.
|
|
|
|
*
|
|
|
|
* The @attribute value is a string that specifies the file attributes that
|
2008-01-16 21:00:23 +01:00
|
|
|
* should be gathered. It is not an error if it's not possible to read a particular
|
|
|
|
* requested attribute from a file - it just won't be set. @attribute should
|
2007-12-12 13:19:02 +01:00
|
|
|
* be a comma-separated list of attribute or attribute wildcards. The wildcard "*"
|
2007-12-20 14:30:47 +01:00
|
|
|
* means all attributes, and a wildcard like "standard::*" means all attributes in the standard
|
|
|
|
* namespace. An example attribute query be "standard::*,owner::user".
|
2008-01-11 17:23:30 +01:00
|
|
|
* The standard attributes are available as defines, like #G_FILE_ATTRIBUTE_STANDARD_NAME.
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-11-27 15:00:13 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
|
|
|
|
* If the file is not a directory, the G_FILE_ERROR_NOTDIR error will be returned.
|
|
|
|
* Other errors are possible too.
|
|
|
|
*
|
|
|
|
* Returns: A #GFileEnumerator if successful, %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileEnumerator *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_enumerate_children (GFile *file,
|
|
|
|
const char *attributes,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->enumerate_children == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (* iface->enumerate_children) (file, attributes, flags,
|
|
|
|
cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_enumerate_children_async:
|
|
|
|
* @file: input #GFile.
|
2007-12-12 13:19:02 +01:00
|
|
|
* @attributes: an attribute query string.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @flags: a set of #GFileQueryInfoFlags.
|
2007-11-30 19:11:03 +01:00
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
2007-11-30 06:51:10 +01:00
|
|
|
* of the request.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-29 11:18:55 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Asynchronously gets the requested information about the files in a directory. The result
|
|
|
|
* is a #GFileEnumerator object that will give out #GFileInfo objects for
|
|
|
|
* all the files in the directory.
|
|
|
|
*
|
|
|
|
* For more details, see g_file_enumerate_children() which is
|
|
|
|
* the synchronous version of this call.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_enumerate_children_finish() to get the result of the operation.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_enumerate_children_async (GFile *file,
|
|
|
|
const char *attributes,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
(* iface->enumerate_children_async) (file,
|
|
|
|
attributes,
|
|
|
|
flags,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_enumerate_children_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @res: a #GAsyncResult.
|
|
|
|
* @error: a #GError.
|
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Finishes an async enumerate children operation.
|
2007-12-12 13:19:02 +01:00
|
|
|
* See g_file_enumerate_children_async().
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: a #GFileEnumerator or %NULL if an error occurred.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileEnumerator *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_enumerate_children_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->enumerate_children_finish) (file, res, error);
|
|
|
|
}
|
|
|
|
|
2008-01-16 11:11:26 +01:00
|
|
|
/**
|
|
|
|
* g_file_query_exists:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
*
|
|
|
|
* Utility function to check if a particular file exists. This is
|
|
|
|
* implemented using g_file_query_info() and as such does blocking I/O.
|
|
|
|
*
|
2008-03-10 20:38:42 +01:00
|
|
|
* Note that in many cases it is racy to first check for file existence
|
2008-01-16 11:11:26 +01:00
|
|
|
* and then execute something based on the outcome of that, because the
|
2008-03-10 20:38:42 +01:00
|
|
|
* file might have been created or removed in between the operations. The
|
2008-01-16 11:11:26 +01:00
|
|
|
* general approach to handling that is to not check, but just do the
|
|
|
|
* operation and handle the errors as they come.
|
|
|
|
*
|
2008-01-20 18:42:35 +01:00
|
|
|
* As an example of race-free checking, take the case of reading a file, and
|
|
|
|
* if it doesn't exist, creating it. There are two racy versions: read it, and
|
2008-01-16 11:11:26 +01:00
|
|
|
* on error create it; and: check if it exists, if not create it. These
|
|
|
|
* can both result in two processes creating the file (with perhaps a partially
|
|
|
|
* written file as the result). The correct approach is to always try to create
|
|
|
|
* the file with g_file_create() which will either atomically create the file
|
2008-01-20 18:42:35 +01:00
|
|
|
* or fail with a G_IO_ERROR_EXISTS error.
|
2008-01-16 11:11:26 +01:00
|
|
|
*
|
2008-03-10 20:38:42 +01:00
|
|
|
* However, in many cases an existence check is useful in a user
|
2008-01-16 11:11:26 +01:00
|
|
|
* interface, for instance to make a menu item sensitive/insensitive, so that
|
|
|
|
* you don't have to fool users that something is possible and then just show
|
|
|
|
* and error dialog. If you do this, you should make sure to also handle the
|
|
|
|
* errors that can happen due to races when you execute the operation.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the file exists (and can be detected without error), %FALSE otherwise (or if cancelled).
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
g_file_query_exists (GFile *file,
|
|
|
|
GCancellable *cancellable)
|
|
|
|
{
|
|
|
|
GFileInfo *info;
|
2008-03-06 11:04:24 +01:00
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE(file), FALSE);
|
|
|
|
|
2008-01-16 11:11:26 +01:00
|
|
|
info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
2008-03-31 06:46:22 +02:00
|
|
|
G_FILE_QUERY_INFO_NONE, cancellable, NULL);
|
2008-01-16 11:11:26 +01:00
|
|
|
if (info != NULL)
|
|
|
|
{
|
|
|
|
g_object_unref (info);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2008-03-31 06:46:22 +02:00
|
|
|
/**
|
|
|
|
* g_file_query_file_type:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @flags: a set of #GFileQueryInfoFlags passed to g_file_query_info().
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
*
|
|
|
|
* Utility function to inspect the #GFileType of a file. This is
|
|
|
|
* implemented using g_file_query_info() and as such does blocking I/O.
|
|
|
|
*
|
|
|
|
* The primary use case of this method is to check if a file is a regular file,
|
|
|
|
* directory, or symlink.
|
|
|
|
*
|
|
|
|
* Returns: The #GFileType of the file and #G_FILE_TYPE_UNKNOWN if the file
|
|
|
|
* does not exist
|
|
|
|
*
|
|
|
|
* Since: 2.18
|
|
|
|
*/
|
|
|
|
GFileType
|
|
|
|
g_file_query_file_type (GFile *file,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable)
|
|
|
|
{
|
|
|
|
GFileInfo *info;
|
|
|
|
GFileType file_type;
|
|
|
|
|
2008-03-31 21:32:58 +02:00
|
|
|
g_return_val_if_fail (G_IS_FILE(file), G_FILE_TYPE_UNKNOWN);
|
2008-03-31 06:46:22 +02:00
|
|
|
info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, flags,
|
|
|
|
cancellable, NULL);
|
|
|
|
if (info != NULL)
|
|
|
|
{
|
|
|
|
file_type = g_file_info_get_file_type (info);
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
file_type = G_FILE_TYPE_UNKNOWN;
|
|
|
|
|
|
|
|
return file_type;
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/**
|
|
|
|
* g_file_query_info:
|
|
|
|
* @file: input #GFile.
|
2007-12-12 13:19:02 +01:00
|
|
|
* @attributes: an attribute query string.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @flags: a set of #GFileQueryInfoFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @error: a #GError.
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
|
|
|
* Gets the requested information about specified @file. The result
|
2008-01-20 18:42:35 +01:00
|
|
|
* is a #GFileInfo object that contains key-value attributes (such as
|
|
|
|
* the type or size of the file).
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
|
|
|
* The @attribute value is a string that specifies the file attributes that
|
2008-01-16 21:00:23 +01:00
|
|
|
* should be gathered. It is not an error if it's not possible to read a particular
|
|
|
|
* requested attribute from a file - it just won't be set. @attribute should
|
2007-12-12 13:19:02 +01:00
|
|
|
* be a comma-separated list of attribute or attribute wildcards. The wildcard "*"
|
2007-12-20 14:30:47 +01:00
|
|
|
* means all attributes, and a wildcard like "standard::*" means all attributes in the standard
|
|
|
|
* namespace. An example attribute query be "standard::*,owner::user".
|
2008-01-11 17:23:30 +01:00
|
|
|
* The standard attributes are available as defines, like #G_FILE_ATTRIBUTE_STANDARD_NAME.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-11-27 15:00:13 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
|
|
|
* For symlinks, normally the information about the target of the
|
|
|
|
* symlink is returned, rather than information about the symlink itself.
|
|
|
|
* However if you pass #G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS in @flags the
|
|
|
|
* information about the symlink itself will be returned. Also, for symlinks
|
2008-01-20 18:42:35 +01:00
|
|
|
* that point to non-existing files the information about the symlink itself
|
2007-12-12 13:19:02 +01:00
|
|
|
* will be returned.
|
|
|
|
*
|
|
|
|
* If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
|
|
|
|
* Other errors are possible too, and depend on what kind of filesystem the file is on.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: a #GFileInfo for the given @file, or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileInfo *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_query_info (GFile *file,
|
|
|
|
const char *attributes,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->query_info == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (* iface->query_info) (file, attributes, flags, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_query_info_async:
|
|
|
|
* @file: input #GFile.
|
2007-12-12 13:19:02 +01:00
|
|
|
* @attributes: an attribute query string.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @flags: a set of #GFileQueryInfoFlags.
|
2007-11-30 19:11:03 +01:00
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
2007-11-30 06:51:10 +01:00
|
|
|
* of the request.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-29 11:18:55 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Asynchronously gets the requested information about specified @file. The result
|
2008-01-20 18:42:35 +01:00
|
|
|
* is a #GFileInfo object that contains key-value attributes (such as type or size
|
2008-01-09 18:04:06 +01:00
|
|
|
* for the file).
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* For more details, see g_file_query_info() which is
|
|
|
|
* the synchronous version of this call.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
2008-01-09 18:04:06 +01:00
|
|
|
* g_file_query_info_finish() to get the result of the operation.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_query_info_async (GFile *file,
|
|
|
|
const char *attributes,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
(* iface->query_info_async) (file,
|
|
|
|
attributes,
|
|
|
|
flags,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_query_info_finish:
|
|
|
|
* @file: input #GFile.
|
2007-11-27 15:00:13 +01:00
|
|
|
* @res: a #GAsyncResult.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @error: a #GError.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Finishes an asynchronous file info query.
|
2007-12-12 13:19:02 +01:00
|
|
|
* See g_file_query_info_async().
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Returns: #GFileInfo for given @file or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileInfo *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_query_info_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->query_info_finish) (file, res, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_query_filesystem_info:
|
|
|
|
* @file: input #GFile.
|
2007-12-12 13:19:02 +01:00
|
|
|
* @attributes: an attribute query string.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @error: a #GError.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Similar to g_file_query_info(), but obtains information
|
|
|
|
* about the filesystem the @file is on, rather than the file itself.
|
2008-01-11 17:23:30 +01:00
|
|
|
* For instance the amount of space available and the type of
|
2007-12-12 13:19:02 +01:00
|
|
|
* the filesystem.
|
|
|
|
*
|
|
|
|
* The @attribute value is a string that specifies the file attributes that
|
2008-01-16 21:00:23 +01:00
|
|
|
* should be gathered. It is not an error if it's not possible to read a particular
|
|
|
|
* requested attribute from a file - it just won't be set. @attribute should
|
2007-12-12 13:19:02 +01:00
|
|
|
* be a comma-separated list of attribute or attribute wildcards. The wildcard "*"
|
|
|
|
* means all attributes, and a wildcard like "fs:*" means all attributes in the fs
|
|
|
|
* namespace. The standard namespace for filesystem attributes is "fs".
|
2007-12-20 14:30:47 +01:00
|
|
|
* Common attributes of interest are #G_FILE_ATTRIBUTE_FILESYSTEM_SIZE
|
|
|
|
* (the total size of the filesystem in bytes), #G_FILE_ATTRIBUTE_FILESYSTEM_FREE (number of
|
2008-01-11 17:23:30 +01:00
|
|
|
* bytes available), and #G_FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-11-27 15:00:13 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
|
|
|
* If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
|
|
|
|
* Other errors are possible too, and depend on what kind of filesystem the file is on.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Returns: a #GFileInfo or %NULL if there was an error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileInfo *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_query_filesystem_info (GFile *file,
|
|
|
|
const char *attributes,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->query_filesystem_info == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (* iface->query_filesystem_info) (file, attributes, cancellable, error);
|
|
|
|
}
|
|
|
|
|
Implement this function by moving bits from glocalfileinfo.c
2008-02-21 David Zeuthen <davidz@redhat.com>
* glocalfileinfo.c: (_g_local_file_info_get):
* gcontenttype.c:
(g_content_type_get_icon): Implement this function by
moving bits from glocalfileinfo.c
(g_content_type_get_description): Unalias before getting
description (#517687)
* gfile.c: (g_file_class_init),
(g_file_query_filesystem_info_async),
(g_file_query_filesystem_info_finish),
(query_filesystem_info_data_free),
(query_filesystem_info_async_thread),
(g_file_real_query_filesystem_info_async),
(g_file_real_query_filesystem_info_finish):
* gfile.h: Implement async version of
g_file_query_filesystem_info()
* gfileinfo.h: Add new attributes for filesystem::use-preview
* gio.symbols: Update
* gthemedicon.c: (g_themed_icon_append_name):
* gthemedicon.h: Add new new convenience function.
* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
(get_mounts), (get_volumes), (get_connected_drives),
(get_volume_for_uuid), (get_mount_for_uuid),
(g_union_volume_monitor_init), (populate_union_monitor),
(g_volume_monitor_get), (_g_mount_get_for_mount_path),
(g_volume_monitor_adopt_orphan_mount):
* gvolumemonitor.c:
* gvolumemonitor.h: Use recursive locks so it's safe for volume
monitor implementations to call into the main volume monitor. Also
separate object initialization and volume monitor initialization
such that non-native volume monitors can properly adopt their
mounts away.
svn path=/trunk/; revision=6550
2008-02-21 13:35:05 +01:00
|
|
|
/**
|
|
|
|
* g_file_query_filesystem_info_async:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @attributes: an attribute query string.
|
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
|
|
|
* of the request.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Asynchronously gets the requested information about the filesystem
|
|
|
|
* that the specified @file is on. The result is a #GFileInfo object
|
|
|
|
* that contains key-value attributes (such as type or size for the
|
|
|
|
* file).
|
|
|
|
*
|
|
|
|
* For more details, see g_file_query_filesystem_info() which is the
|
|
|
|
* synchronous version of this call.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can
|
|
|
|
* then call g_file_query_info_finish() to get the result of the
|
|
|
|
* operation.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_file_query_filesystem_info_async (GFile *file,
|
|
|
|
const char *attributes,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
(* iface->query_filesystem_info_async) (file,
|
|
|
|
attributes,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_query_filesystem_info_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @res: a #GAsyncResult.
|
|
|
|
* @error: a #GError.
|
|
|
|
*
|
|
|
|
* Finishes an asynchronous filesystem info query. See
|
|
|
|
* g_file_query_filesystem_info_async().
|
|
|
|
*
|
|
|
|
* Returns: #GFileInfo for given @file or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
Implement this function by moving bits from glocalfileinfo.c
2008-02-21 David Zeuthen <davidz@redhat.com>
* glocalfileinfo.c: (_g_local_file_info_get):
* gcontenttype.c:
(g_content_type_get_icon): Implement this function by
moving bits from glocalfileinfo.c
(g_content_type_get_description): Unalias before getting
description (#517687)
* gfile.c: (g_file_class_init),
(g_file_query_filesystem_info_async),
(g_file_query_filesystem_info_finish),
(query_filesystem_info_data_free),
(query_filesystem_info_async_thread),
(g_file_real_query_filesystem_info_async),
(g_file_real_query_filesystem_info_finish):
* gfile.h: Implement async version of
g_file_query_filesystem_info()
* gfileinfo.h: Add new attributes for filesystem::use-preview
* gio.symbols: Update
* gthemedicon.c: (g_themed_icon_append_name):
* gthemedicon.h: Add new new convenience function.
* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
(get_mounts), (get_volumes), (get_connected_drives),
(get_volume_for_uuid), (get_mount_for_uuid),
(g_union_volume_monitor_init), (populate_union_monitor),
(g_volume_monitor_get), (_g_mount_get_for_mount_path),
(g_volume_monitor_adopt_orphan_mount):
* gvolumemonitor.c:
* gvolumemonitor.h: Use recursive locks so it's safe for volume
monitor implementations to call into the main volume monitor. Also
separate object initialization and volume monitor initialization
such that non-native volume monitors can properly adopt their
mounts away.
svn path=/trunk/; revision=6550
2008-02-21 13:35:05 +01:00
|
|
|
**/
|
|
|
|
GFileInfo *
|
|
|
|
g_file_query_filesystem_info_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->query_filesystem_info_finish) (file, res, error);
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/**
|
Rework how volumes, drives and volume monitoring is done. Previosly the
2007-12-11 David Zeuthen <davidz@redhat.com>
Rework how volumes, drives and volume monitoring is
done. Previosly the model was
GDrive <1-1> GVolume
where a GDrive instance represented a mount point and a GVolume
instance represented a mounted file system. This patch changes it
the model to
GDrive <1-N> GVolume <1-1> GMount
where GMount now serves the purpose of the old GVolume and the new
GVolume serves the purpose of the old GDrive. In addition the new
GDrive interface is used to represent a collection of GVolume
instances (typically partitions) and also contains utility to query
the state of the physical drive the GDrive object represents (such
as checking for media, polling the drive, ejecting the media etc.).
Also implement mounting and unmounting in the Unix volume monitor
backend. A subquent patch will introduce GDrive support for ejection
of media.
* Makefile.am:
* gdrive.c: (g_drive_is_media_check_automatic),
(g_drive_is_media_removable), (g_drive_has_media),
(g_drive_can_poll_for_media), (g_drive_eject),
(g_drive_eject_finish), (g_drive_poll_for_media),
(g_drive_poll_for_media_finish):
* gdrive.h:
* gfile.c: (g_file_find_enclosing_mount):
* gfile.h:
* gio.symbols:
* glocaldirectorymonitor.c:
(g_local_directory_monitor_constructor), (mounts_changed):
* glocalfile.c: (get_mount_info),
(g_local_file_find_enclosing_mount),
(g_local_file_file_iface_init):
* gnativevolumemonitor.h:
* gunionvolumemonitor.c: (get_mounts), (get_volumes),
(get_connected_drives), (g_union_volume_monitor_class_init),
(child_volume_added), (child_volume_removed),
(child_volume_changed), (child_mount_added), (child_mount_removed),
(child_mount_pre_unmount), (child_mount_changed),
(child_drive_changed), (g_union_volume_monitor_add_monitor),
(g_union_volume_monitor_remove_monitor),
(_g_mount_get_for_mount_path):
* gunixmounts.c: (g_unix_is_mount_path_system_internal),
(guess_system_internal), (_g_get_unix_mounts),
(_g_get_unix_mount_points), (g_get_unix_mount_at),
(g_unix_mount_free), (g_unix_mount_compare),
(g_unix_mount_get_mount_path), (g_unix_mount_get_device_path),
(g_unix_mount_get_fs_type), (g_unix_mount_is_readonly),
(g_unix_mount_is_system_internal), (g_unix_mount_guess_type),
(type_to_icon), (g_unix_mount_guess_name),
(g_unix_mount_guess_icon), (g_unix_mount_point_guess_name),
(g_unix_mount_point_guess_icon), (_canonicalize_filename),
(_resolve_symlink), (_resolve_dev_root):
* gunixmounts.h:
* gunixvolume.c: (g_unix_volume_finalize), (_g_unix_volume_new),
(_g_unix_volume_disconnected), (_g_unix_volume_set_mount),
(_g_unix_volume_unset_mount), (g_unix_volume_get_icon),
(g_unix_volume_get_name), (g_unix_volume_can_mount),
(g_unix_volume_get_drive), (g_unix_volume_get_mount),
(_g_unix_volume_has_mount_path), (mount_cb), (mount_read_error),
(g_unix_volume_mount), (g_unix_volume_mount_finish),
(g_unix_volume_volume_iface_init):
* gunixvolume.h:
* gunixvolumemonitor.c: (g_unix_volume_monitor_finalize),
(get_mounts), (get_volumes), (get_connected_drives),
(get_mount_for_mount_path), (g_unix_volume_monitor_class_init),
(mountpoints_changed), (mounts_changed),
(g_unix_volume_monitor_init),
(_g_unix_volume_monitor_lookup_volume_for_mount_path),
(find_mount_by_mountpath), (update_volumes), (update_mounts):
* gunixvolumemonitor.h:
* gvolume.c: (g_volume_get_mount), (g_volume_can_mount),
(g_volume_mount), (g_volume_mount_finish):
* gvolume.h:
* gvolumemonitor.c: (g_volume_monitor_class_init),
(g_volume_monitor_get_connected_drives),
(g_volume_monitor_get_volumes), (g_volume_monitor_get_mounts):
* gvolumemonitor.h:
svn path=/trunk/; revision=6095
2007-12-11 22:23:55 +01:00
|
|
|
* g_file_find_enclosing_mount:
|
2007-11-26 17:13:05 +01:00
|
|
|
* @file: input #GFile.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @error: a #GError.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
Rework how volumes, drives and volume monitoring is done. Previosly the
2007-12-11 David Zeuthen <davidz@redhat.com>
Rework how volumes, drives and volume monitoring is
done. Previosly the model was
GDrive <1-1> GVolume
where a GDrive instance represented a mount point and a GVolume
instance represented a mounted file system. This patch changes it
the model to
GDrive <1-N> GVolume <1-1> GMount
where GMount now serves the purpose of the old GVolume and the new
GVolume serves the purpose of the old GDrive. In addition the new
GDrive interface is used to represent a collection of GVolume
instances (typically partitions) and also contains utility to query
the state of the physical drive the GDrive object represents (such
as checking for media, polling the drive, ejecting the media etc.).
Also implement mounting and unmounting in the Unix volume monitor
backend. A subquent patch will introduce GDrive support for ejection
of media.
* Makefile.am:
* gdrive.c: (g_drive_is_media_check_automatic),
(g_drive_is_media_removable), (g_drive_has_media),
(g_drive_can_poll_for_media), (g_drive_eject),
(g_drive_eject_finish), (g_drive_poll_for_media),
(g_drive_poll_for_media_finish):
* gdrive.h:
* gfile.c: (g_file_find_enclosing_mount):
* gfile.h:
* gio.symbols:
* glocaldirectorymonitor.c:
(g_local_directory_monitor_constructor), (mounts_changed):
* glocalfile.c: (get_mount_info),
(g_local_file_find_enclosing_mount),
(g_local_file_file_iface_init):
* gnativevolumemonitor.h:
* gunionvolumemonitor.c: (get_mounts), (get_volumes),
(get_connected_drives), (g_union_volume_monitor_class_init),
(child_volume_added), (child_volume_removed),
(child_volume_changed), (child_mount_added), (child_mount_removed),
(child_mount_pre_unmount), (child_mount_changed),
(child_drive_changed), (g_union_volume_monitor_add_monitor),
(g_union_volume_monitor_remove_monitor),
(_g_mount_get_for_mount_path):
* gunixmounts.c: (g_unix_is_mount_path_system_internal),
(guess_system_internal), (_g_get_unix_mounts),
(_g_get_unix_mount_points), (g_get_unix_mount_at),
(g_unix_mount_free), (g_unix_mount_compare),
(g_unix_mount_get_mount_path), (g_unix_mount_get_device_path),
(g_unix_mount_get_fs_type), (g_unix_mount_is_readonly),
(g_unix_mount_is_system_internal), (g_unix_mount_guess_type),
(type_to_icon), (g_unix_mount_guess_name),
(g_unix_mount_guess_icon), (g_unix_mount_point_guess_name),
(g_unix_mount_point_guess_icon), (_canonicalize_filename),
(_resolve_symlink), (_resolve_dev_root):
* gunixmounts.h:
* gunixvolume.c: (g_unix_volume_finalize), (_g_unix_volume_new),
(_g_unix_volume_disconnected), (_g_unix_volume_set_mount),
(_g_unix_volume_unset_mount), (g_unix_volume_get_icon),
(g_unix_volume_get_name), (g_unix_volume_can_mount),
(g_unix_volume_get_drive), (g_unix_volume_get_mount),
(_g_unix_volume_has_mount_path), (mount_cb), (mount_read_error),
(g_unix_volume_mount), (g_unix_volume_mount_finish),
(g_unix_volume_volume_iface_init):
* gunixvolume.h:
* gunixvolumemonitor.c: (g_unix_volume_monitor_finalize),
(get_mounts), (get_volumes), (get_connected_drives),
(get_mount_for_mount_path), (g_unix_volume_monitor_class_init),
(mountpoints_changed), (mounts_changed),
(g_unix_volume_monitor_init),
(_g_unix_volume_monitor_lookup_volume_for_mount_path),
(find_mount_by_mountpath), (update_volumes), (update_mounts):
* gunixvolumemonitor.h:
* gvolume.c: (g_volume_get_mount), (g_volume_can_mount),
(g_volume_mount), (g_volume_mount_finish):
* gvolume.h:
* gvolumemonitor.c: (g_volume_monitor_class_init),
(g_volume_monitor_get_connected_drives),
(g_volume_monitor_get_volumes), (g_volume_monitor_get_mounts):
* gvolumemonitor.h:
svn path=/trunk/; revision=6095
2007-12-11 22:23:55 +01:00
|
|
|
* Gets a #GMount for the #GFile.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
Rework how volumes, drives and volume monitoring is done. Previosly the
2007-12-11 David Zeuthen <davidz@redhat.com>
Rework how volumes, drives and volume monitoring is
done. Previosly the model was
GDrive <1-1> GVolume
where a GDrive instance represented a mount point and a GVolume
instance represented a mounted file system. This patch changes it
the model to
GDrive <1-N> GVolume <1-1> GMount
where GMount now serves the purpose of the old GVolume and the new
GVolume serves the purpose of the old GDrive. In addition the new
GDrive interface is used to represent a collection of GVolume
instances (typically partitions) and also contains utility to query
the state of the physical drive the GDrive object represents (such
as checking for media, polling the drive, ejecting the media etc.).
Also implement mounting and unmounting in the Unix volume monitor
backend. A subquent patch will introduce GDrive support for ejection
of media.
* Makefile.am:
* gdrive.c: (g_drive_is_media_check_automatic),
(g_drive_is_media_removable), (g_drive_has_media),
(g_drive_can_poll_for_media), (g_drive_eject),
(g_drive_eject_finish), (g_drive_poll_for_media),
(g_drive_poll_for_media_finish):
* gdrive.h:
* gfile.c: (g_file_find_enclosing_mount):
* gfile.h:
* gio.symbols:
* glocaldirectorymonitor.c:
(g_local_directory_monitor_constructor), (mounts_changed):
* glocalfile.c: (get_mount_info),
(g_local_file_find_enclosing_mount),
(g_local_file_file_iface_init):
* gnativevolumemonitor.h:
* gunionvolumemonitor.c: (get_mounts), (get_volumes),
(get_connected_drives), (g_union_volume_monitor_class_init),
(child_volume_added), (child_volume_removed),
(child_volume_changed), (child_mount_added), (child_mount_removed),
(child_mount_pre_unmount), (child_mount_changed),
(child_drive_changed), (g_union_volume_monitor_add_monitor),
(g_union_volume_monitor_remove_monitor),
(_g_mount_get_for_mount_path):
* gunixmounts.c: (g_unix_is_mount_path_system_internal),
(guess_system_internal), (_g_get_unix_mounts),
(_g_get_unix_mount_points), (g_get_unix_mount_at),
(g_unix_mount_free), (g_unix_mount_compare),
(g_unix_mount_get_mount_path), (g_unix_mount_get_device_path),
(g_unix_mount_get_fs_type), (g_unix_mount_is_readonly),
(g_unix_mount_is_system_internal), (g_unix_mount_guess_type),
(type_to_icon), (g_unix_mount_guess_name),
(g_unix_mount_guess_icon), (g_unix_mount_point_guess_name),
(g_unix_mount_point_guess_icon), (_canonicalize_filename),
(_resolve_symlink), (_resolve_dev_root):
* gunixmounts.h:
* gunixvolume.c: (g_unix_volume_finalize), (_g_unix_volume_new),
(_g_unix_volume_disconnected), (_g_unix_volume_set_mount),
(_g_unix_volume_unset_mount), (g_unix_volume_get_icon),
(g_unix_volume_get_name), (g_unix_volume_can_mount),
(g_unix_volume_get_drive), (g_unix_volume_get_mount),
(_g_unix_volume_has_mount_path), (mount_cb), (mount_read_error),
(g_unix_volume_mount), (g_unix_volume_mount_finish),
(g_unix_volume_volume_iface_init):
* gunixvolume.h:
* gunixvolumemonitor.c: (g_unix_volume_monitor_finalize),
(get_mounts), (get_volumes), (get_connected_drives),
(get_mount_for_mount_path), (g_unix_volume_monitor_class_init),
(mountpoints_changed), (mounts_changed),
(g_unix_volume_monitor_init),
(_g_unix_volume_monitor_lookup_volume_for_mount_path),
(find_mount_by_mountpath), (update_volumes), (update_mounts):
* gunixvolumemonitor.h:
* gvolume.c: (g_volume_get_mount), (g_volume_can_mount),
(g_volume_mount), (g_volume_mount_finish):
* gvolume.h:
* gvolumemonitor.c: (g_volume_monitor_class_init),
(g_volume_monitor_get_connected_drives),
(g_volume_monitor_get_volumes), (g_volume_monitor_get_mounts):
* gvolumemonitor.h:
svn path=/trunk/; revision=6095
2007-12-11 22:23:55 +01:00
|
|
|
* If the #GFileIface for @file does not have a mount (e.g. possibly a
|
2007-11-27 15:00:13 +01:00
|
|
|
* remote share), @error will be set to %G_IO_ERROR_NOT_FOUND and %NULL
|
|
|
|
* will be returned.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-11-27 15:00:13 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
Rework how volumes, drives and volume monitoring is done. Previosly the
2007-12-11 David Zeuthen <davidz@redhat.com>
Rework how volumes, drives and volume monitoring is
done. Previosly the model was
GDrive <1-1> GVolume
where a GDrive instance represented a mount point and a GVolume
instance represented a mounted file system. This patch changes it
the model to
GDrive <1-N> GVolume <1-1> GMount
where GMount now serves the purpose of the old GVolume and the new
GVolume serves the purpose of the old GDrive. In addition the new
GDrive interface is used to represent a collection of GVolume
instances (typically partitions) and also contains utility to query
the state of the physical drive the GDrive object represents (such
as checking for media, polling the drive, ejecting the media etc.).
Also implement mounting and unmounting in the Unix volume monitor
backend. A subquent patch will introduce GDrive support for ejection
of media.
* Makefile.am:
* gdrive.c: (g_drive_is_media_check_automatic),
(g_drive_is_media_removable), (g_drive_has_media),
(g_drive_can_poll_for_media), (g_drive_eject),
(g_drive_eject_finish), (g_drive_poll_for_media),
(g_drive_poll_for_media_finish):
* gdrive.h:
* gfile.c: (g_file_find_enclosing_mount):
* gfile.h:
* gio.symbols:
* glocaldirectorymonitor.c:
(g_local_directory_monitor_constructor), (mounts_changed):
* glocalfile.c: (get_mount_info),
(g_local_file_find_enclosing_mount),
(g_local_file_file_iface_init):
* gnativevolumemonitor.h:
* gunionvolumemonitor.c: (get_mounts), (get_volumes),
(get_connected_drives), (g_union_volume_monitor_class_init),
(child_volume_added), (child_volume_removed),
(child_volume_changed), (child_mount_added), (child_mount_removed),
(child_mount_pre_unmount), (child_mount_changed),
(child_drive_changed), (g_union_volume_monitor_add_monitor),
(g_union_volume_monitor_remove_monitor),
(_g_mount_get_for_mount_path):
* gunixmounts.c: (g_unix_is_mount_path_system_internal),
(guess_system_internal), (_g_get_unix_mounts),
(_g_get_unix_mount_points), (g_get_unix_mount_at),
(g_unix_mount_free), (g_unix_mount_compare),
(g_unix_mount_get_mount_path), (g_unix_mount_get_device_path),
(g_unix_mount_get_fs_type), (g_unix_mount_is_readonly),
(g_unix_mount_is_system_internal), (g_unix_mount_guess_type),
(type_to_icon), (g_unix_mount_guess_name),
(g_unix_mount_guess_icon), (g_unix_mount_point_guess_name),
(g_unix_mount_point_guess_icon), (_canonicalize_filename),
(_resolve_symlink), (_resolve_dev_root):
* gunixmounts.h:
* gunixvolume.c: (g_unix_volume_finalize), (_g_unix_volume_new),
(_g_unix_volume_disconnected), (_g_unix_volume_set_mount),
(_g_unix_volume_unset_mount), (g_unix_volume_get_icon),
(g_unix_volume_get_name), (g_unix_volume_can_mount),
(g_unix_volume_get_drive), (g_unix_volume_get_mount),
(_g_unix_volume_has_mount_path), (mount_cb), (mount_read_error),
(g_unix_volume_mount), (g_unix_volume_mount_finish),
(g_unix_volume_volume_iface_init):
* gunixvolume.h:
* gunixvolumemonitor.c: (g_unix_volume_monitor_finalize),
(get_mounts), (get_volumes), (get_connected_drives),
(get_mount_for_mount_path), (g_unix_volume_monitor_class_init),
(mountpoints_changed), (mounts_changed),
(g_unix_volume_monitor_init),
(_g_unix_volume_monitor_lookup_volume_for_mount_path),
(find_mount_by_mountpath), (update_volumes), (update_mounts):
* gunixvolumemonitor.h:
* gvolume.c: (g_volume_get_mount), (g_volume_can_mount),
(g_volume_mount), (g_volume_mount_finish):
* gvolume.h:
* gvolumemonitor.c: (g_volume_monitor_class_init),
(g_volume_monitor_get_connected_drives),
(g_volume_monitor_get_volumes), (g_volume_monitor_get_mounts):
* gvolumemonitor.h:
svn path=/trunk/; revision=6095
2007-12-11 22:23:55 +01:00
|
|
|
* Returns: a #GMount where the @file is located or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
Rework how volumes, drives and volume monitoring is done. Previosly the
2007-12-11 David Zeuthen <davidz@redhat.com>
Rework how volumes, drives and volume monitoring is
done. Previosly the model was
GDrive <1-1> GVolume
where a GDrive instance represented a mount point and a GVolume
instance represented a mounted file system. This patch changes it
the model to
GDrive <1-N> GVolume <1-1> GMount
where GMount now serves the purpose of the old GVolume and the new
GVolume serves the purpose of the old GDrive. In addition the new
GDrive interface is used to represent a collection of GVolume
instances (typically partitions) and also contains utility to query
the state of the physical drive the GDrive object represents (such
as checking for media, polling the drive, ejecting the media etc.).
Also implement mounting and unmounting in the Unix volume monitor
backend. A subquent patch will introduce GDrive support for ejection
of media.
* Makefile.am:
* gdrive.c: (g_drive_is_media_check_automatic),
(g_drive_is_media_removable), (g_drive_has_media),
(g_drive_can_poll_for_media), (g_drive_eject),
(g_drive_eject_finish), (g_drive_poll_for_media),
(g_drive_poll_for_media_finish):
* gdrive.h:
* gfile.c: (g_file_find_enclosing_mount):
* gfile.h:
* gio.symbols:
* glocaldirectorymonitor.c:
(g_local_directory_monitor_constructor), (mounts_changed):
* glocalfile.c: (get_mount_info),
(g_local_file_find_enclosing_mount),
(g_local_file_file_iface_init):
* gnativevolumemonitor.h:
* gunionvolumemonitor.c: (get_mounts), (get_volumes),
(get_connected_drives), (g_union_volume_monitor_class_init),
(child_volume_added), (child_volume_removed),
(child_volume_changed), (child_mount_added), (child_mount_removed),
(child_mount_pre_unmount), (child_mount_changed),
(child_drive_changed), (g_union_volume_monitor_add_monitor),
(g_union_volume_monitor_remove_monitor),
(_g_mount_get_for_mount_path):
* gunixmounts.c: (g_unix_is_mount_path_system_internal),
(guess_system_internal), (_g_get_unix_mounts),
(_g_get_unix_mount_points), (g_get_unix_mount_at),
(g_unix_mount_free), (g_unix_mount_compare),
(g_unix_mount_get_mount_path), (g_unix_mount_get_device_path),
(g_unix_mount_get_fs_type), (g_unix_mount_is_readonly),
(g_unix_mount_is_system_internal), (g_unix_mount_guess_type),
(type_to_icon), (g_unix_mount_guess_name),
(g_unix_mount_guess_icon), (g_unix_mount_point_guess_name),
(g_unix_mount_point_guess_icon), (_canonicalize_filename),
(_resolve_symlink), (_resolve_dev_root):
* gunixmounts.h:
* gunixvolume.c: (g_unix_volume_finalize), (_g_unix_volume_new),
(_g_unix_volume_disconnected), (_g_unix_volume_set_mount),
(_g_unix_volume_unset_mount), (g_unix_volume_get_icon),
(g_unix_volume_get_name), (g_unix_volume_can_mount),
(g_unix_volume_get_drive), (g_unix_volume_get_mount),
(_g_unix_volume_has_mount_path), (mount_cb), (mount_read_error),
(g_unix_volume_mount), (g_unix_volume_mount_finish),
(g_unix_volume_volume_iface_init):
* gunixvolume.h:
* gunixvolumemonitor.c: (g_unix_volume_monitor_finalize),
(get_mounts), (get_volumes), (get_connected_drives),
(get_mount_for_mount_path), (g_unix_volume_monitor_class_init),
(mountpoints_changed), (mounts_changed),
(g_unix_volume_monitor_init),
(_g_unix_volume_monitor_lookup_volume_for_mount_path),
(find_mount_by_mountpath), (update_volumes), (update_mounts):
* gunixvolumemonitor.h:
* gvolume.c: (g_volume_get_mount), (g_volume_can_mount),
(g_volume_mount), (g_volume_mount_finish):
* gvolume.h:
* gvolumemonitor.c: (g_volume_monitor_class_init),
(g_volume_monitor_get_connected_drives),
(g_volume_monitor_get_volumes), (g_volume_monitor_get_mounts):
* gvolumemonitor.h:
svn path=/trunk/; revision=6095
2007-12-11 22:23:55 +01:00
|
|
|
GMount *
|
|
|
|
g_file_find_enclosing_mount (GFile *file,
|
2007-12-12 13:19:02 +01:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
2008-02-25 15:04:38 +01:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
Rework how volumes, drives and volume monitoring is done. Previosly the
2007-12-11 David Zeuthen <davidz@redhat.com>
Rework how volumes, drives and volume monitoring is
done. Previosly the model was
GDrive <1-1> GVolume
where a GDrive instance represented a mount point and a GVolume
instance represented a mounted file system. This patch changes it
the model to
GDrive <1-N> GVolume <1-1> GMount
where GMount now serves the purpose of the old GVolume and the new
GVolume serves the purpose of the old GDrive. In addition the new
GDrive interface is used to represent a collection of GVolume
instances (typically partitions) and also contains utility to query
the state of the physical drive the GDrive object represents (such
as checking for media, polling the drive, ejecting the media etc.).
Also implement mounting and unmounting in the Unix volume monitor
backend. A subquent patch will introduce GDrive support for ejection
of media.
* Makefile.am:
* gdrive.c: (g_drive_is_media_check_automatic),
(g_drive_is_media_removable), (g_drive_has_media),
(g_drive_can_poll_for_media), (g_drive_eject),
(g_drive_eject_finish), (g_drive_poll_for_media),
(g_drive_poll_for_media_finish):
* gdrive.h:
* gfile.c: (g_file_find_enclosing_mount):
* gfile.h:
* gio.symbols:
* glocaldirectorymonitor.c:
(g_local_directory_monitor_constructor), (mounts_changed):
* glocalfile.c: (get_mount_info),
(g_local_file_find_enclosing_mount),
(g_local_file_file_iface_init):
* gnativevolumemonitor.h:
* gunionvolumemonitor.c: (get_mounts), (get_volumes),
(get_connected_drives), (g_union_volume_monitor_class_init),
(child_volume_added), (child_volume_removed),
(child_volume_changed), (child_mount_added), (child_mount_removed),
(child_mount_pre_unmount), (child_mount_changed),
(child_drive_changed), (g_union_volume_monitor_add_monitor),
(g_union_volume_monitor_remove_monitor),
(_g_mount_get_for_mount_path):
* gunixmounts.c: (g_unix_is_mount_path_system_internal),
(guess_system_internal), (_g_get_unix_mounts),
(_g_get_unix_mount_points), (g_get_unix_mount_at),
(g_unix_mount_free), (g_unix_mount_compare),
(g_unix_mount_get_mount_path), (g_unix_mount_get_device_path),
(g_unix_mount_get_fs_type), (g_unix_mount_is_readonly),
(g_unix_mount_is_system_internal), (g_unix_mount_guess_type),
(type_to_icon), (g_unix_mount_guess_name),
(g_unix_mount_guess_icon), (g_unix_mount_point_guess_name),
(g_unix_mount_point_guess_icon), (_canonicalize_filename),
(_resolve_symlink), (_resolve_dev_root):
* gunixmounts.h:
* gunixvolume.c: (g_unix_volume_finalize), (_g_unix_volume_new),
(_g_unix_volume_disconnected), (_g_unix_volume_set_mount),
(_g_unix_volume_unset_mount), (g_unix_volume_get_icon),
(g_unix_volume_get_name), (g_unix_volume_can_mount),
(g_unix_volume_get_drive), (g_unix_volume_get_mount),
(_g_unix_volume_has_mount_path), (mount_cb), (mount_read_error),
(g_unix_volume_mount), (g_unix_volume_mount_finish),
(g_unix_volume_volume_iface_init):
* gunixvolume.h:
* gunixvolumemonitor.c: (g_unix_volume_monitor_finalize),
(get_mounts), (get_volumes), (get_connected_drives),
(get_mount_for_mount_path), (g_unix_volume_monitor_class_init),
(mountpoints_changed), (mounts_changed),
(g_unix_volume_monitor_init),
(_g_unix_volume_monitor_lookup_volume_for_mount_path),
(find_mount_by_mountpath), (update_volumes), (update_mounts):
* gunixvolumemonitor.h:
* gvolume.c: (g_volume_get_mount), (g_volume_can_mount),
(g_volume_mount), (g_volume_mount_finish):
* gvolume.h:
* gvolumemonitor.c: (g_volume_monitor_class_init),
(g_volume_monitor_get_connected_drives),
(g_volume_monitor_get_volumes), (g_volume_monitor_get_mounts):
* gvolumemonitor.h:
svn path=/trunk/; revision=6095
2007-12-11 22:23:55 +01:00
|
|
|
if (iface->find_enclosing_mount == NULL)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2008-02-25 14:47:00 +01:00
|
|
|
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
2008-02-25 15:31:19 +01:00
|
|
|
/* Translators: This is an error message when trying to find the
|
|
|
|
* enclosing (user visible) mount of a file, but none exists. */
|
Rework how volumes, drives and volume monitoring is done. Previosly the
2007-12-11 David Zeuthen <davidz@redhat.com>
Rework how volumes, drives and volume monitoring is
done. Previosly the model was
GDrive <1-1> GVolume
where a GDrive instance represented a mount point and a GVolume
instance represented a mounted file system. This patch changes it
the model to
GDrive <1-N> GVolume <1-1> GMount
where GMount now serves the purpose of the old GVolume and the new
GVolume serves the purpose of the old GDrive. In addition the new
GDrive interface is used to represent a collection of GVolume
instances (typically partitions) and also contains utility to query
the state of the physical drive the GDrive object represents (such
as checking for media, polling the drive, ejecting the media etc.).
Also implement mounting and unmounting in the Unix volume monitor
backend. A subquent patch will introduce GDrive support for ejection
of media.
* Makefile.am:
* gdrive.c: (g_drive_is_media_check_automatic),
(g_drive_is_media_removable), (g_drive_has_media),
(g_drive_can_poll_for_media), (g_drive_eject),
(g_drive_eject_finish), (g_drive_poll_for_media),
(g_drive_poll_for_media_finish):
* gdrive.h:
* gfile.c: (g_file_find_enclosing_mount):
* gfile.h:
* gio.symbols:
* glocaldirectorymonitor.c:
(g_local_directory_monitor_constructor), (mounts_changed):
* glocalfile.c: (get_mount_info),
(g_local_file_find_enclosing_mount),
(g_local_file_file_iface_init):
* gnativevolumemonitor.h:
* gunionvolumemonitor.c: (get_mounts), (get_volumes),
(get_connected_drives), (g_union_volume_monitor_class_init),
(child_volume_added), (child_volume_removed),
(child_volume_changed), (child_mount_added), (child_mount_removed),
(child_mount_pre_unmount), (child_mount_changed),
(child_drive_changed), (g_union_volume_monitor_add_monitor),
(g_union_volume_monitor_remove_monitor),
(_g_mount_get_for_mount_path):
* gunixmounts.c: (g_unix_is_mount_path_system_internal),
(guess_system_internal), (_g_get_unix_mounts),
(_g_get_unix_mount_points), (g_get_unix_mount_at),
(g_unix_mount_free), (g_unix_mount_compare),
(g_unix_mount_get_mount_path), (g_unix_mount_get_device_path),
(g_unix_mount_get_fs_type), (g_unix_mount_is_readonly),
(g_unix_mount_is_system_internal), (g_unix_mount_guess_type),
(type_to_icon), (g_unix_mount_guess_name),
(g_unix_mount_guess_icon), (g_unix_mount_point_guess_name),
(g_unix_mount_point_guess_icon), (_canonicalize_filename),
(_resolve_symlink), (_resolve_dev_root):
* gunixmounts.h:
* gunixvolume.c: (g_unix_volume_finalize), (_g_unix_volume_new),
(_g_unix_volume_disconnected), (_g_unix_volume_set_mount),
(_g_unix_volume_unset_mount), (g_unix_volume_get_icon),
(g_unix_volume_get_name), (g_unix_volume_can_mount),
(g_unix_volume_get_drive), (g_unix_volume_get_mount),
(_g_unix_volume_has_mount_path), (mount_cb), (mount_read_error),
(g_unix_volume_mount), (g_unix_volume_mount_finish),
(g_unix_volume_volume_iface_init):
* gunixvolume.h:
* gunixvolumemonitor.c: (g_unix_volume_monitor_finalize),
(get_mounts), (get_volumes), (get_connected_drives),
(get_mount_for_mount_path), (g_unix_volume_monitor_class_init),
(mountpoints_changed), (mounts_changed),
(g_unix_volume_monitor_init),
(_g_unix_volume_monitor_lookup_volume_for_mount_path),
(find_mount_by_mountpath), (update_volumes), (update_mounts):
* gunixvolumemonitor.h:
* gvolume.c: (g_volume_get_mount), (g_volume_can_mount),
(g_volume_mount), (g_volume_mount_finish):
* gvolume.h:
* gvolumemonitor.c: (g_volume_monitor_class_init),
(g_volume_monitor_get_connected_drives),
(g_volume_monitor_get_volumes), (g_volume_monitor_get_mounts):
* gvolumemonitor.h:
svn path=/trunk/; revision=6095
2007-12-11 22:23:55 +01:00
|
|
|
_("Containing mount does not exist"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-02-25 15:04:38 +01:00
|
|
|
|
Rework how volumes, drives and volume monitoring is done. Previosly the
2007-12-11 David Zeuthen <davidz@redhat.com>
Rework how volumes, drives and volume monitoring is
done. Previosly the model was
GDrive <1-1> GVolume
where a GDrive instance represented a mount point and a GVolume
instance represented a mounted file system. This patch changes it
the model to
GDrive <1-N> GVolume <1-1> GMount
where GMount now serves the purpose of the old GVolume and the new
GVolume serves the purpose of the old GDrive. In addition the new
GDrive interface is used to represent a collection of GVolume
instances (typically partitions) and also contains utility to query
the state of the physical drive the GDrive object represents (such
as checking for media, polling the drive, ejecting the media etc.).
Also implement mounting and unmounting in the Unix volume monitor
backend. A subquent patch will introduce GDrive support for ejection
of media.
* Makefile.am:
* gdrive.c: (g_drive_is_media_check_automatic),
(g_drive_is_media_removable), (g_drive_has_media),
(g_drive_can_poll_for_media), (g_drive_eject),
(g_drive_eject_finish), (g_drive_poll_for_media),
(g_drive_poll_for_media_finish):
* gdrive.h:
* gfile.c: (g_file_find_enclosing_mount):
* gfile.h:
* gio.symbols:
* glocaldirectorymonitor.c:
(g_local_directory_monitor_constructor), (mounts_changed):
* glocalfile.c: (get_mount_info),
(g_local_file_find_enclosing_mount),
(g_local_file_file_iface_init):
* gnativevolumemonitor.h:
* gunionvolumemonitor.c: (get_mounts), (get_volumes),
(get_connected_drives), (g_union_volume_monitor_class_init),
(child_volume_added), (child_volume_removed),
(child_volume_changed), (child_mount_added), (child_mount_removed),
(child_mount_pre_unmount), (child_mount_changed),
(child_drive_changed), (g_union_volume_monitor_add_monitor),
(g_union_volume_monitor_remove_monitor),
(_g_mount_get_for_mount_path):
* gunixmounts.c: (g_unix_is_mount_path_system_internal),
(guess_system_internal), (_g_get_unix_mounts),
(_g_get_unix_mount_points), (g_get_unix_mount_at),
(g_unix_mount_free), (g_unix_mount_compare),
(g_unix_mount_get_mount_path), (g_unix_mount_get_device_path),
(g_unix_mount_get_fs_type), (g_unix_mount_is_readonly),
(g_unix_mount_is_system_internal), (g_unix_mount_guess_type),
(type_to_icon), (g_unix_mount_guess_name),
(g_unix_mount_guess_icon), (g_unix_mount_point_guess_name),
(g_unix_mount_point_guess_icon), (_canonicalize_filename),
(_resolve_symlink), (_resolve_dev_root):
* gunixmounts.h:
* gunixvolume.c: (g_unix_volume_finalize), (_g_unix_volume_new),
(_g_unix_volume_disconnected), (_g_unix_volume_set_mount),
(_g_unix_volume_unset_mount), (g_unix_volume_get_icon),
(g_unix_volume_get_name), (g_unix_volume_can_mount),
(g_unix_volume_get_drive), (g_unix_volume_get_mount),
(_g_unix_volume_has_mount_path), (mount_cb), (mount_read_error),
(g_unix_volume_mount), (g_unix_volume_mount_finish),
(g_unix_volume_volume_iface_init):
* gunixvolume.h:
* gunixvolumemonitor.c: (g_unix_volume_monitor_finalize),
(get_mounts), (get_volumes), (get_connected_drives),
(get_mount_for_mount_path), (g_unix_volume_monitor_class_init),
(mountpoints_changed), (mounts_changed),
(g_unix_volume_monitor_init),
(_g_unix_volume_monitor_lookup_volume_for_mount_path),
(find_mount_by_mountpath), (update_volumes), (update_mounts):
* gunixvolumemonitor.h:
* gvolume.c: (g_volume_get_mount), (g_volume_can_mount),
(g_volume_mount), (g_volume_mount_finish):
* gvolume.h:
* gvolumemonitor.c: (g_volume_monitor_class_init),
(g_volume_monitor_get_connected_drives),
(g_volume_monitor_get_volumes), (g_volume_monitor_get_mounts):
* gvolumemonitor.h:
svn path=/trunk/; revision=6095
2007-12-11 22:23:55 +01:00
|
|
|
return (* iface->find_enclosing_mount) (file, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
2008-07-16 06:21:50 +02:00
|
|
|
|
2008-01-21 04:49:20 +01:00
|
|
|
/**
|
|
|
|
* g_file_find_enclosing_mount_async:
|
|
|
|
* @file: a #GFile
|
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
|
|
|
* of the request.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Asynchronously gets the mount for the file.
|
|
|
|
*
|
|
|
|
* For more details, see g_file_find_enclosing_mount() which is
|
|
|
|
* the synchronous version of this call.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_find_enclosing_mount_finish() to get the result of the operation.
|
|
|
|
*/
|
2008-01-17 15:22:13 +01:00
|
|
|
void
|
|
|
|
g_file_find_enclosing_mount_async (GFile *file,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
(* iface->find_enclosing_mount_async) (file,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
2008-01-21 04:49:20 +01:00
|
|
|
/**
|
|
|
|
* g_file_find_enclosing_mount_finish:
|
|
|
|
* @file: a #GFile
|
|
|
|
* @res: a #GAsyncResult
|
|
|
|
* @error: a #GError
|
|
|
|
*
|
|
|
|
* Finishes an asynchronous find mount request.
|
|
|
|
* See g_file_find_enclosing_mount_async().
|
|
|
|
*
|
|
|
|
* Returns: #GMount for given @file or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2008-01-21 04:49:20 +01:00
|
|
|
**/
|
2008-01-17 15:22:13 +01:00
|
|
|
GMount *
|
2008-01-21 04:49:20 +01:00
|
|
|
g_file_find_enclosing_mount_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2008-01-17 15:22:13 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->find_enclosing_mount_finish) (file, res, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/**
|
|
|
|
* g_file_read:
|
|
|
|
* @file: #GFile to read.
|
|
|
|
* @cancellable: a #GCancellable
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Opens a file for reading. The result is a #GFileInputStream that
|
|
|
|
* can be used to read the contents of the file.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-11-27 15:00:13 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
|
|
|
|
* If the file is a directory, the G_IO_ERROR_IS_DIRECTORY error will be returned.
|
|
|
|
* Other errors are possible too, and depend on what kind of filesystem the file is on.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Returns: #GFileInputStream or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileInputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_read (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
2007-12-05 11:38:03 +01:00
|
|
|
if (iface->read_fn == NULL)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-05 11:38:03 +01:00
|
|
|
return (* iface->read_fn) (file, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_append_to:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @flags: a set of #GFileCreateFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Gets an output stream for appending data to the file. If
|
|
|
|
* the file doesn't already exist it is created.
|
|
|
|
*
|
|
|
|
* By default files created are generally readable by everyone,
|
2007-12-14 12:07:31 +01:00
|
|
|
* but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
|
2007-12-12 13:19:02 +01:00
|
|
|
* will be made readable only to the current user, to the level that
|
|
|
|
* is supported on the target filesystem.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-11-27 15:00:13 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
2008-01-11 17:23:30 +01:00
|
|
|
* Some file systems don't allow all file names, and may
|
2008-06-30 07:02:06 +02:00
|
|
|
* return an %G_IO_ERROR_INVALID_FILENAME error.
|
|
|
|
* If the file is a directory the %G_IO_ERROR_IS_DIRECTORY error will be
|
2007-12-12 13:19:02 +01:00
|
|
|
* returned. Other errors are possible too, and depend on what kind of
|
|
|
|
* filesystem the file is on.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2008-07-16 07:49:16 +02:00
|
|
|
* Returns: a #GFileOutputStream, or %NULL on error.
|
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileOutputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_append_to (GFile *file,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->append_to == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (* iface->append_to) (file, flags, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_create:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @flags: a set of #GFileCreateFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Creates a new file and returns an output stream for writing to it.
|
2008-04-15 16:32:58 +02:00
|
|
|
* The file must not already exist.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* By default files created are generally readable by everyone,
|
2007-12-14 12:07:31 +01:00
|
|
|
* but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
|
2007-12-12 13:19:02 +01:00
|
|
|
* will be made readable only to the current user, to the level that
|
|
|
|
* is supported on the target filesystem.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-11-27 15:00:13 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
2008-02-06 13:59:49 +01:00
|
|
|
* If a file or directory with this name already exists the G_IO_ERROR_EXISTS
|
2007-12-12 13:19:02 +01:00
|
|
|
* error will be returned.
|
2008-01-11 17:23:30 +01:00
|
|
|
* Some file systems don't allow all file names, and may
|
2007-12-12 13:19:02 +01:00
|
|
|
* return an G_IO_ERROR_INVALID_FILENAME error, and if the name
|
|
|
|
* is to long G_IO_ERROR_FILENAME_TOO_LONG will be returned.
|
|
|
|
* Other errors are possible too, and depend on what kind of
|
|
|
|
* filesystem the file is on.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* Returns: a #GFileOutputStream for the newly created file, or
|
2008-07-16 07:49:16 +02:00
|
|
|
* %NULL on error.
|
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileOutputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_create (GFile *file,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->create == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (* iface->create) (file, flags, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_replace:
|
|
|
|
* @file: input #GFile.
|
2007-12-12 13:19:02 +01:00
|
|
|
* @etag: an optional <link linkend="gfile-etag">entity tag</link> for the
|
|
|
|
* current #GFile, or #NULL to ignore.
|
|
|
|
* @make_backup: %TRUE if a backup should be created.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @flags: a set of #GFileCreateFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Returns an output stream for overwriting the file, possibly
|
2008-04-08 17:56:42 +02:00
|
|
|
* creating a backup copy of the file first. If the file doesn't exist,
|
|
|
|
* it will be created.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* This will try to replace the file in the safest way possible so
|
|
|
|
* that any errors during the writing will not affect an already
|
|
|
|
* existing copy of the file. For instance, for local files it
|
|
|
|
* may write to a temporary file and then atomically rename over
|
|
|
|
* the destination when the stream is closed.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* By default files created are generally readable by everyone,
|
2007-12-14 12:07:31 +01:00
|
|
|
* but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
|
2007-12-12 13:19:02 +01:00
|
|
|
* will be made readable only to the current user, to the level that
|
|
|
|
* is supported on the target filesystem.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-11-27 15:00:13 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* If you pass in a non-#NULL @etag value, then this value is
|
|
|
|
* compared to the current entity tag of the file, and if they differ
|
|
|
|
* an G_IO_ERROR_WRONG_ETAG error is returned. This generally means
|
|
|
|
* that the file has been changed since you last read it. You can get
|
|
|
|
* the new etag from g_file_output_stream_get_etag() after you've
|
|
|
|
* finished writing and closed the #GFileOutputStream. When you load
|
|
|
|
* a new file you can use g_file_input_stream_query_info() to get
|
|
|
|
* the etag of the file.
|
|
|
|
*
|
|
|
|
* If @make_backup is %TRUE, this function will attempt to make a backup
|
|
|
|
* of the current file before overwriting it. If this fails a G_IO_ERROR_CANT_CREATE_BACKUP
|
|
|
|
* error will be returned. If you want to replace anyway, try again with
|
|
|
|
* @make_backup set to %FALSE.
|
|
|
|
*
|
|
|
|
* If the file is a directory the G_IO_ERROR_IS_DIRECTORY error will be returned,
|
|
|
|
* and if the file is some other form of non-regular file then a
|
|
|
|
* G_IO_ERROR_NOT_REGULAR_FILE error will be returned.
|
2008-01-11 17:23:30 +01:00
|
|
|
* Some file systems don't allow all file names, and may
|
2007-12-12 13:19:02 +01:00
|
|
|
* return an G_IO_ERROR_INVALID_FILENAME error, and if the name
|
|
|
|
* is to long G_IO_ERROR_FILENAME_TOO_LONG will be returned.
|
|
|
|
* Other errors are possible too, and depend on what kind of
|
|
|
|
* filesystem the file is on.
|
|
|
|
*
|
|
|
|
* Returns: a #GFileOutputStream or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileOutputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_replace (GFile *file,
|
|
|
|
const char *etag,
|
|
|
|
gboolean make_backup,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->replace == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Handle empty tag string as NULL in consistent way. */
|
|
|
|
if (etag && *etag == 0)
|
|
|
|
etag = NULL;
|
|
|
|
|
|
|
|
return (* iface->replace) (file, etag, make_backup, flags, cancellable, error);
|
|
|
|
}
|
|
|
|
|
2009-05-13 13:00:26 +02:00
|
|
|
/**
|
|
|
|
* g_file_open_readwrite:
|
|
|
|
* @file: #GFile to open
|
|
|
|
* @cancellable: a #GCancellable
|
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Opens an existing file for reading and writing. The result is
|
|
|
|
* a #GFileIOStream that can be used to read and write the contents of the file.
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* If the file does not exist, the G_IO_ERROR_NOT_FOUND error will be returned.
|
|
|
|
* If the file is a directory, the G_IO_ERROR_IS_DIRECTORY error will be returned.
|
|
|
|
* Other errors are possible too, and depend on what kind of filesystem the file is on.
|
|
|
|
* Note that in many non-local file cases read and write streams are not supported,
|
|
|
|
* so make sure you really need to do read and write streaming, rather than
|
|
|
|
* just opening for reading or writing.
|
|
|
|
*
|
|
|
|
* Returns: #GFileIOStream or %NULL on error.
|
|
|
|
* Free the returned object with g_object_unref().
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
**/
|
|
|
|
GFileIOStream *
|
|
|
|
g_file_open_readwrite (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->open_readwrite == NULL)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (* iface->open_readwrite) (file, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_create_readwrite:
|
2009-05-28 00:20:08 +02:00
|
|
|
* @file: a #GFile
|
|
|
|
* @flags: a set of #GFileCreateFlags
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore
|
|
|
|
* @error: return location for a #GError, or %NULL
|
2009-05-13 13:00:26 +02:00
|
|
|
*
|
|
|
|
* Creates a new file and returns a stream for reading and writing to it.
|
|
|
|
* The file must not already exist.
|
|
|
|
*
|
|
|
|
* By default files created are generally readable by everyone,
|
|
|
|
* but if you pass #G_FILE_CREATE_PRIVATE in @flags the file
|
|
|
|
* will be made readable only to the current user, to the level that
|
|
|
|
* is supported on the target filesystem.
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2009-05-28 00:20:08 +02:00
|
|
|
* If a file or directory with this name already exists the %G_IO_ERROR_EXISTS
|
|
|
|
* error will be returned. Some file systems don't allow all file names,
|
|
|
|
* and may return an %G_IO_ERROR_INVALID_FILENAME error, and if the name
|
|
|
|
* is too long, %G_IO_ERROR_FILENAME_TOO_LONG will be returned. Other errors
|
|
|
|
* are possible too, and depend on what kind of filesystem the file is on.
|
2009-05-13 13:00:26 +02:00
|
|
|
*
|
2009-05-28 00:20:08 +02:00
|
|
|
* Note that in many non-local file cases read and write streams are not
|
|
|
|
* supported, so make sure you really need to do read and write streaming,
|
|
|
|
* rather than just opening for reading or writing.
|
2009-05-13 13:00:26 +02:00
|
|
|
*
|
2009-05-28 00:20:08 +02:00
|
|
|
* Returns: a #GFileIOStream for the newly created file, or %NULL on error.
|
2009-05-13 13:00:26 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-13 13:00:26 +02:00
|
|
|
GFileIOStream *
|
2009-05-28 00:20:08 +02:00
|
|
|
g_file_create_readwrite (GFile *file,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2009-05-13 13:00:26 +02:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->create_readwrite == NULL)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (* iface->create_readwrite) (file, flags, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-05-18 13:02:11 +02:00
|
|
|
* g_file_replace_readwrite:
|
2009-05-28 00:20:08 +02:00
|
|
|
* @file: a #GFile
|
2009-05-13 13:00:26 +02:00
|
|
|
* @etag: an optional <link linkend="gfile-etag">entity tag</link> for the
|
2009-05-28 00:20:08 +02:00
|
|
|
* current #GFile, or #NULL to ignore
|
|
|
|
* @make_backup: %TRUE if a backup should be created
|
|
|
|
* @flags: a set of #GFileCreateFlags
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore
|
|
|
|
* @error: return location for a #GError, or %NULL
|
2009-05-13 13:00:26 +02:00
|
|
|
*
|
|
|
|
* Returns an output stream for overwriting the file in readwrite mode,
|
2009-05-28 00:20:08 +02:00
|
|
|
* possibly creating a backup copy of the file first. If the file doesn't
|
|
|
|
* exist, it will be created.
|
2009-05-13 13:00:26 +02:00
|
|
|
*
|
|
|
|
* For details about the behaviour, see g_file_replace() which does the same
|
|
|
|
* thing but returns an output stream only.
|
|
|
|
*
|
2009-05-28 00:20:08 +02:00
|
|
|
* Note that in many non-local file cases read and write streams are not
|
|
|
|
* supported, so make sure you really need to do read and write streaming,
|
|
|
|
* rather than just opening for reading or writing.
|
2009-05-13 13:00:26 +02:00
|
|
|
*
|
|
|
|
* Returns: a #GFileIOStream or %NULL on error.
|
|
|
|
* Free the returned object with g_object_unref().
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-13 13:00:26 +02:00
|
|
|
GFileIOStream *
|
2009-05-28 00:20:08 +02:00
|
|
|
g_file_replace_readwrite (GFile *file,
|
|
|
|
const char *etag,
|
|
|
|
gboolean make_backup,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2009-05-13 13:00:26 +02:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->replace_readwrite == NULL)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (* iface->replace_readwrite) (file, etag, make_backup, flags, cancellable, error);
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/**
|
|
|
|
* g_file_read_async:
|
2009-05-28 00:20:08 +02:00
|
|
|
* @file: input #GFile
|
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
|
|
|
* of the request.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-12-09 16:51:12 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Asynchronously opens @file for reading.
|
|
|
|
*
|
|
|
|
* For more details, see g_file_read() which is
|
|
|
|
* the synchronous version of this call.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_read_finish() to get the result of the operation.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_read_async (GFile *file,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
(* iface->read_async) (file,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_read_finish:
|
|
|
|
* @file: input #GFile.
|
2007-11-27 15:00:13 +01:00
|
|
|
* @res: a #GAsyncResult.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* Finishes an asynchronous file read operation started with
|
|
|
|
* g_file_read_async().
|
|
|
|
*
|
|
|
|
* Returns: a #GFileInputStream or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileInputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_read_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->read_finish) (file, res, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_append_to_async:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @flags: a set of #GFileCreateFlags.
|
2007-11-30 19:11:03 +01:00
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
2007-11-30 06:51:10 +01:00
|
|
|
* of the request.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-12-09 16:51:12 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Asynchronously opens @file for appending.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* For more details, see g_file_append_to() which is
|
|
|
|
* the synchronous version of this call.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_append_to_finish() to get the result of the operation.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_append_to_async (GFile *file,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
(* iface->append_to_async) (file,
|
|
|
|
flags,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_append_to_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @res: #GAsyncResult
|
2007-11-29 08:17:59 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Finishes an asynchronous file append operation started with
|
|
|
|
* g_file_append_to_async().
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* Returns: a valid #GFileOutputStream or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileOutputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_append_to_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->append_to_finish) (file, res, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_create_async:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @flags: a set of #GFileCreateFlags.
|
2007-11-30 19:11:03 +01:00
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
2007-11-30 06:51:10 +01:00
|
|
|
* of the request.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-12-09 16:51:12 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Asynchronously creates a new file and returns an output stream for writing to it.
|
2008-04-15 16:32:58 +02:00
|
|
|
* The file must not already exist.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2008-01-11 17:23:30 +01:00
|
|
|
* For more details, see g_file_create() which is
|
2007-12-12 13:19:02 +01:00
|
|
|
* the synchronous version of this call.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_create_finish() to get the result of the operation.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_create_async (GFile *file,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
(* iface->create_async) (file,
|
|
|
|
flags,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_create_finish:
|
|
|
|
* @file: input #GFile.
|
2007-11-27 15:00:13 +01:00
|
|
|
* @res: a #GAsyncResult.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Finishes an asynchronous file create operation started with
|
|
|
|
* g_file_create_async().
|
2007-11-29 11:18:55 +01:00
|
|
|
*
|
|
|
|
* Returns: a #GFileOutputStream or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileOutputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_create_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->create_finish) (file, res, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_replace_async:
|
|
|
|
* @file: input #GFile.
|
2007-11-30 19:11:03 +01:00
|
|
|
* @etag: an <link linkend="gfile-etag">entity tag</link> for the
|
2008-01-09 18:04:06 +01:00
|
|
|
* current #GFile, or NULL to ignore.
|
|
|
|
* @make_backup: %TRUE if a backup should be created.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @flags: a set of #GFileCreateFlags.
|
2007-11-30 19:11:03 +01:00
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
2007-11-30 06:51:10 +01:00
|
|
|
* of the request.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-12-09 16:51:12 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2008-01-11 17:23:30 +01:00
|
|
|
* Asynchronously overwrites the file, replacing the contents, possibly
|
2007-12-12 13:19:02 +01:00
|
|
|
* creating a backup copy of the file first.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* For more details, see g_file_replace() which is
|
|
|
|
* the synchronous version of this call.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_replace_finish() to get the result of the operation.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_replace_async (GFile *file,
|
|
|
|
const char *etag,
|
|
|
|
gboolean make_backup,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
(* iface->replace_async) (file,
|
|
|
|
etag,
|
|
|
|
make_backup,
|
|
|
|
flags,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_replace_finish:
|
|
|
|
* @file: input #GFile.
|
2007-11-27 15:00:13 +01:00
|
|
|
* @res: a #GAsyncResult.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Finishes an asynchronous file replace operation started with
|
|
|
|
* g_file_replace_async().
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Returns: a #GFileOutputStream, or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileOutputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_replace_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->replace_finish) (file, res, error);
|
|
|
|
}
|
|
|
|
|
2009-05-13 13:00:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_open_readwrite_async:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
|
|
|
* of the request.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Asynchronously opens @file for reading and writing.
|
|
|
|
*
|
|
|
|
* For more details, see g_file_open_readwrite() which is
|
|
|
|
* the synchronous version of this call.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_open_readwrite_finish() to get the result of the operation.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_file_open_readwrite_async (GFile *file,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
(* iface->open_readwrite_async) (file,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_open_readwrite_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @res: a #GAsyncResult.
|
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Finishes an asynchronous file read operation started with
|
|
|
|
* g_file_open_readwrite_async().
|
|
|
|
*
|
|
|
|
* Returns: a #GFileIOStream or %NULL on error.
|
|
|
|
* Free the returned object with g_object_unref().
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
**/
|
|
|
|
GFileIOStream *
|
|
|
|
g_file_open_readwrite_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->open_readwrite_finish) (file, res, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_create_readwrite_async:
|
2009-05-28 00:20:08 +02:00
|
|
|
* @file: input #GFile
|
|
|
|
* @flags: a set of #GFileCreateFlags
|
2009-05-13 13:00:26 +02:00
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
2009-05-28 00:20:08 +02:00
|
|
|
* of the request
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore
|
2009-05-13 13:00:26 +02:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
|
|
|
*
|
2009-05-28 00:20:08 +02:00
|
|
|
* Asynchronously creates a new file and returns a stream for reading and
|
|
|
|
* writing to it. The file must not already exist.
|
2009-05-13 13:00:26 +02:00
|
|
|
*
|
|
|
|
* For more details, see g_file_create_readwrite() which is
|
|
|
|
* the synchronous version of this call.
|
|
|
|
*
|
2009-05-28 00:20:08 +02:00
|
|
|
* When the operation is finished, @callback will be called. You can then
|
|
|
|
* call g_file_create_readwrite_finish() to get the result of the operation.
|
2009-05-13 13:00:26 +02:00
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-13 13:00:26 +02:00
|
|
|
void
|
2009-05-28 00:20:08 +02:00
|
|
|
g_file_create_readwrite_async (GFile *file,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2009-05-13 13:00:26 +02:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
(* iface->create_readwrite_async) (file,
|
|
|
|
flags,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_create_readwrite_finish:
|
2009-05-28 00:20:08 +02:00
|
|
|
* @file: input #GFile
|
|
|
|
* @res: a #GAsyncResult
|
2009-05-13 13:00:26 +02:00
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Finishes an asynchronous file create operation started with
|
|
|
|
* g_file_create_readwrite_async().
|
|
|
|
*
|
|
|
|
* Returns: a #GFileIOStream or %NULL on error.
|
|
|
|
* Free the returned object with g_object_unref().
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
**/
|
|
|
|
GFileIOStream *
|
2009-05-28 00:20:08 +02:00
|
|
|
g_file_create_readwrite_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2009-05-13 13:00:26 +02:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->create_readwrite_finish) (file, res, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_replace_readwrite_async:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @etag: an <link linkend="gfile-etag">entity tag</link> for the
|
|
|
|
* current #GFile, or NULL to ignore.
|
|
|
|
* @make_backup: %TRUE if a backup should be created.
|
|
|
|
* @flags: a set of #GFileCreateFlags.
|
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
|
|
|
* of the request.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
|
|
|
*
|
2009-05-28 00:20:08 +02:00
|
|
|
* Asynchronously overwrites the file in read-write mode, replacing the
|
|
|
|
* contents, possibly creating a backup copy of the file first.
|
2009-05-13 13:00:26 +02:00
|
|
|
*
|
|
|
|
* For more details, see g_file_replace_readwrite() which is
|
|
|
|
* the synchronous version of this call.
|
|
|
|
*
|
2009-05-28 00:20:08 +02:00
|
|
|
* When the operation is finished, @callback will be called. You can then
|
|
|
|
* call g_file_replace_readwrite_finish() to get the result of the operation.
|
2009-05-13 13:00:26 +02:00
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-13 13:00:26 +02:00
|
|
|
void
|
2009-05-28 00:20:08 +02:00
|
|
|
g_file_replace_readwrite_async (GFile *file,
|
|
|
|
const char *etag,
|
|
|
|
gboolean make_backup,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2009-05-13 13:00:26 +02:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
(* iface->replace_readwrite_async) (file,
|
|
|
|
etag,
|
|
|
|
make_backup,
|
|
|
|
flags,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_replace_readwrite_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @res: a #GAsyncResult.
|
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Finishes an asynchronous file replace operation started with
|
|
|
|
* g_file_replace_readwrite_async().
|
|
|
|
*
|
|
|
|
* Returns: a #GFileIOStream, or %NULL on error.
|
|
|
|
* Free the returned object with g_object_unref().
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-13 13:00:26 +02:00
|
|
|
GFileIOStream *
|
2009-05-28 00:20:08 +02:00
|
|
|
g_file_replace_readwrite_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2009-05-13 13:00:26 +02:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->replace_readwrite_finish) (file, res, error);
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
static gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
copy_symlink (GFile *destination,
|
|
|
|
GFileCopyFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
const char *target,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GError *my_error;
|
|
|
|
gboolean tried_delete;
|
|
|
|
GFileInfo *info;
|
|
|
|
GFileType file_type;
|
|
|
|
|
|
|
|
tried_delete = FALSE;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
my_error = NULL;
|
|
|
|
if (!g_file_make_symbolic_link (destination, target, cancellable, &my_error))
|
|
|
|
{
|
|
|
|
/* Maybe it already existed, and we want to overwrite? */
|
|
|
|
if (!tried_delete && (flags & G_FILE_COPY_OVERWRITE) &&
|
|
|
|
my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_EXISTS)
|
|
|
|
{
|
|
|
|
g_error_free (my_error);
|
|
|
|
|
|
|
|
|
|
|
|
/* Don't overwrite if the destination is a directory */
|
2007-12-20 14:30:47 +01:00
|
|
|
info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
2007-11-26 17:13:05 +01:00
|
|
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
|
|
|
cancellable, &my_error);
|
|
|
|
if (info != NULL)
|
|
|
|
{
|
|
|
|
file_type = g_file_info_get_file_type (info);
|
|
|
|
g_object_unref (info);
|
|
|
|
|
|
|
|
if (file_type == G_FILE_TYPE_DIRECTORY)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY,
|
|
|
|
_("Can't copy over directory"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_file_delete (destination, cancellable, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
tried_delete = TRUE;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
/* Nah, fail */
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GInputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
open_source_for_copy (GFile *source,
|
|
|
|
GFile *destination,
|
|
|
|
GFileCopyFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GError *my_error;
|
|
|
|
GInputStream *in;
|
|
|
|
GFileInfo *info;
|
|
|
|
GFileType file_type;
|
|
|
|
|
|
|
|
my_error = NULL;
|
|
|
|
in = (GInputStream *)g_file_read (source, cancellable, &my_error);
|
|
|
|
if (in != NULL)
|
|
|
|
return in;
|
|
|
|
|
|
|
|
/* There was an error opening the source, try to set a good error for it: */
|
|
|
|
|
|
|
|
if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_IS_DIRECTORY)
|
|
|
|
{
|
2007-11-29 08:17:59 +01:00
|
|
|
/* The source is a directory, don't fail with WOULD_RECURSE immediately,
|
|
|
|
* as that is less useful to the app. Better check for errors on the
|
|
|
|
* target instead.
|
|
|
|
*/
|
2007-11-26 17:13:05 +01:00
|
|
|
g_error_free (my_error);
|
|
|
|
my_error = NULL;
|
|
|
|
|
2007-12-20 14:30:47 +01:00
|
|
|
info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
2007-11-26 17:13:05 +01:00
|
|
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
|
|
|
cancellable, &my_error);
|
|
|
|
if (info != NULL)
|
|
|
|
{
|
|
|
|
file_type = g_file_info_get_file_type (info);
|
|
|
|
g_object_unref (info);
|
|
|
|
|
|
|
|
if (flags & G_FILE_COPY_OVERWRITE)
|
|
|
|
{
|
|
|
|
if (file_type == G_FILE_TYPE_DIRECTORY)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_MERGE,
|
|
|
|
_("Can't copy directory over directory"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* continue to would_recurse error */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
|
|
|
|
_("Target file exists"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-29 08:17:59 +01:00
|
|
|
/* Error getting info from target, return that error
|
|
|
|
* (except for NOT_FOUND, which is no error here)
|
|
|
|
*/
|
2007-11-26 17:13:05 +01:00
|
|
|
if (my_error->domain != G_IO_ERROR && my_error->code != G_IO_ERROR_NOT_FOUND)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
g_error_free (my_error);
|
|
|
|
}
|
|
|
|
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_RECURSE,
|
|
|
|
_("Can't recursively copy directory"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
should_copy (GFileAttributeInfo *info,
|
2008-09-22 01:53:40 +02:00
|
|
|
gboolean as_move,
|
|
|
|
gboolean skip_perms)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2008-09-22 01:53:40 +02:00
|
|
|
if (skip_perms && strcmp(info->name, "unix::mode") == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
if (as_move)
|
2007-12-14 12:07:31 +01:00
|
|
|
return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED;
|
|
|
|
return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE;
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
build_attribute_list_for_copy (GFileAttributeInfoList *attributes,
|
|
|
|
GFileAttributeInfoList *namespaces,
|
2008-09-22 01:53:40 +02:00
|
|
|
gboolean as_move,
|
|
|
|
gboolean skip_perms)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GString *s;
|
|
|
|
gboolean first;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
first = TRUE;
|
|
|
|
s = g_string_new ("");
|
|
|
|
|
|
|
|
if (attributes)
|
|
|
|
{
|
|
|
|
for (i = 0; i < attributes->n_infos; i++)
|
|
|
|
{
|
2008-09-22 01:53:40 +02:00
|
|
|
if (should_copy (&attributes->infos[i], as_move, skip_perms))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
if (first)
|
|
|
|
first = FALSE;
|
|
|
|
else
|
|
|
|
g_string_append_c (s, ',');
|
|
|
|
|
|
|
|
g_string_append (s, attributes->infos[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (namespaces)
|
|
|
|
{
|
|
|
|
for (i = 0; i < namespaces->n_infos; i++)
|
|
|
|
{
|
2008-09-22 01:53:40 +02:00
|
|
|
if (should_copy (&namespaces->infos[i], as_move, FALSE))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
if (first)
|
|
|
|
first = FALSE;
|
|
|
|
else
|
|
|
|
g_string_append_c (s, ',');
|
|
|
|
|
|
|
|
g_string_append (s, namespaces->infos[i].name);
|
2009-06-23 15:07:00 +02:00
|
|
|
g_string_append (s, "::*");
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_string_free (s, FALSE);
|
|
|
|
}
|
|
|
|
|
2007-12-09 16:51:12 +01:00
|
|
|
/**
|
|
|
|
* g_file_copy_attributes:
|
|
|
|
* @source: a #GFile with attributes.
|
|
|
|
* @destination: a #GFile to copy attributes to.
|
|
|
|
* @flags: a set of #GFileCopyFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @error: a #GError, %NULL to ignore.
|
|
|
|
*
|
|
|
|
* Copies the file attributes from @source to @destination.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Normally only a subset of the file attributes are copied,
|
|
|
|
* those that are copies in a normal file copy operation
|
2008-12-09 12:15:36 +01:00
|
|
|
* (which for instance does not include e.g. owner). However
|
2007-12-12 13:19:02 +01:00
|
|
|
* if #G_FILE_COPY_ALL_METADATA is specified in @flags, then
|
2008-12-09 12:15:36 +01:00
|
|
|
* all the metadata that is possible to copy is copied. This
|
|
|
|
* is useful when implementing move by copy + delete source.
|
2007-12-09 16:51:12 +01:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if the attributes were copied successfully, %FALSE otherwise.
|
|
|
|
**/
|
2007-11-26 17:13:05 +01:00
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_copy_attributes (GFile *source,
|
|
|
|
GFile *destination,
|
|
|
|
GFileCopyFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileAttributeInfoList *attributes, *namespaces;
|
|
|
|
char *attrs_to_read;
|
|
|
|
gboolean res;
|
|
|
|
GFileInfo *info;
|
|
|
|
gboolean as_move;
|
|
|
|
gboolean source_nofollow_symlinks;
|
2008-09-22 01:53:40 +02:00
|
|
|
gboolean skip_perms;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
as_move = flags & G_FILE_COPY_ALL_METADATA;
|
|
|
|
source_nofollow_symlinks = flags & G_FILE_COPY_NOFOLLOW_SYMLINKS;
|
2008-09-26 18:00:17 +02:00
|
|
|
skip_perms = (flags & G_FILE_COPY_TARGET_DEFAULT_PERMS) != 0;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
/* Ignore errors here, if the target supports no attributes there is nothing to copy */
|
|
|
|
attributes = g_file_query_settable_attributes (destination, cancellable, NULL);
|
|
|
|
namespaces = g_file_query_writable_namespaces (destination, cancellable, NULL);
|
|
|
|
|
|
|
|
if (attributes == NULL && namespaces == NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
2008-09-22 01:53:40 +02:00
|
|
|
attrs_to_read = build_attribute_list_for_copy (attributes, namespaces, as_move, skip_perms);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
/* Ignore errors here, if we can't read some info (e.g. if it doesn't exist)
|
2007-11-29 08:17:59 +01:00
|
|
|
* we just don't copy it.
|
|
|
|
*/
|
2007-11-26 17:13:05 +01:00
|
|
|
info = g_file_query_info (source, attrs_to_read,
|
|
|
|
source_nofollow_symlinks ? G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS:0,
|
|
|
|
cancellable,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_free (attrs_to_read);
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
res = g_file_set_attributes_from_info (destination,
|
2008-08-04 17:58:25 +02:00
|
|
|
info,
|
|
|
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
2007-11-26 17:13:05 +01:00
|
|
|
cancellable,
|
|
|
|
error);
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_file_attribute_info_list_unref (attributes);
|
|
|
|
g_file_attribute_info_list_unref (namespaces);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Closes the streams */
|
|
|
|
static gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
copy_stream_with_progress (GInputStream *in,
|
|
|
|
GOutputStream *out,
|
2008-03-28 13:43:11 +01:00
|
|
|
GFile *source,
|
2007-11-29 08:17:59 +01:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GFileProgressCallback progress_callback,
|
|
|
|
gpointer progress_callback_data,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
gssize n_read, n_written;
|
|
|
|
goffset current_size;
|
2008-03-19 13:16:20 +01:00
|
|
|
char buffer[1024*64], *p;
|
2007-11-26 17:13:05 +01:00
|
|
|
gboolean res;
|
|
|
|
goffset total_size;
|
|
|
|
GFileInfo *info;
|
|
|
|
|
2008-03-28 13:43:11 +01:00
|
|
|
total_size = -1;
|
2009-06-08 15:27:12 +02:00
|
|
|
/* avoid performance impact of querying total size when it's not needed */
|
|
|
|
if (progress_callback)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2009-06-08 15:27:12 +02:00
|
|
|
info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (in),
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_SIZE,
|
|
|
|
cancellable, NULL);
|
2008-03-28 13:43:11 +01:00
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
|
|
|
|
total_size = g_file_info_get_size (info);
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
2009-06-08 15:27:12 +02:00
|
|
|
|
|
|
|
if (total_size == -1)
|
|
|
|
{
|
|
|
|
info = g_file_query_info (source,
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_SIZE,
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
cancellable, NULL);
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
|
|
|
|
total_size = g_file_info_get_size (info);
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
}
|
2008-03-28 13:43:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (total_size == -1)
|
|
|
|
total_size = 0;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
current_size = 0;
|
|
|
|
res = TRUE;
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
n_read = g_input_stream_read (in, buffer, sizeof (buffer), cancellable, error);
|
|
|
|
if (n_read == -1)
|
|
|
|
{
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_read == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
current_size += n_read;
|
|
|
|
|
|
|
|
p = buffer;
|
|
|
|
while (n_read > 0)
|
|
|
|
{
|
|
|
|
n_written = g_output_stream_write (out, p, n_read, cancellable, error);
|
|
|
|
if (n_written == -1)
|
|
|
|
{
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
p += n_written;
|
|
|
|
n_read -= n_written;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
break;
|
2008-03-28 13:43:11 +01:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
if (progress_callback)
|
|
|
|
progress_callback (current_size, total_size, progress_callback_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
error = NULL; /* Ignore further errors */
|
|
|
|
|
|
|
|
/* Make sure we send full copied size */
|
|
|
|
if (progress_callback)
|
|
|
|
progress_callback (current_size, total_size, progress_callback_data);
|
|
|
|
|
|
|
|
/* Don't care about errors in source here */
|
|
|
|
g_input_stream_close (in, cancellable, NULL);
|
|
|
|
|
|
|
|
/* But write errors on close are bad! */
|
|
|
|
if (!g_output_stream_close (out, cancellable, error))
|
|
|
|
res = FALSE;
|
|
|
|
|
|
|
|
g_object_unref (in);
|
|
|
|
g_object_unref (out);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
file_copy_fallback (GFile *source,
|
|
|
|
GFile *destination,
|
|
|
|
GFileCopyFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GFileProgressCallback progress_callback,
|
|
|
|
gpointer progress_callback_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GInputStream *in;
|
|
|
|
GOutputStream *out;
|
|
|
|
GFileInfo *info;
|
|
|
|
const char *target;
|
|
|
|
|
2009-02-19 16:26:32 +01:00
|
|
|
/* need to know the file type */
|
|
|
|
info = g_file_query_info (source,
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
|
|
|
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
|
|
|
cancellable,
|
|
|
|
error);
|
|
|
|
|
|
|
|
if (info == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/* Maybe copy the symlink? */
|
2009-02-19 16:26:32 +01:00
|
|
|
if ((flags & G_FILE_COPY_NOFOLLOW_SYMLINKS) &&
|
|
|
|
g_file_info_get_file_type (info) == G_FILE_TYPE_SYMBOLIC_LINK)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2009-02-19 16:26:32 +01:00
|
|
|
target = g_file_info_get_symlink_target (info);
|
|
|
|
if (target)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
if (!copy_symlink (destination, flags, cancellable, target, error))
|
|
|
|
{
|
|
|
|
g_object_unref (info);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
goto copied_file;
|
|
|
|
}
|
2009-02-19 16:26:32 +01:00
|
|
|
/* ... else fall back on a regular file copy */
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
/* Handle "special" files (pipes, device nodes, ...)? */
|
|
|
|
else if (g_file_info_get_file_type (info) == G_FILE_TYPE_SPECIAL)
|
|
|
|
{
|
|
|
|
/* FIXME: could try to recreate device nodes and others? */
|
|
|
|
|
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Can't copy special file"));
|
2007-11-26 17:13:05 +01:00
|
|
|
g_object_unref (info);
|
2009-02-19 16:26:32 +01:00
|
|
|
return FALSE;
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
2009-02-19 16:26:32 +01:00
|
|
|
/* Everything else should just fall back on a regular copy. */
|
|
|
|
else
|
|
|
|
g_object_unref (info);
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
in = open_source_for_copy (source, destination, flags, cancellable, error);
|
|
|
|
if (in == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (flags & G_FILE_COPY_OVERWRITE)
|
|
|
|
{
|
|
|
|
out = (GOutputStream *)g_file_replace (destination,
|
2008-04-08 03:59:47 +02:00
|
|
|
NULL,
|
2007-11-26 17:13:05 +01:00
|
|
|
flags & G_FILE_COPY_BACKUP,
|
2009-02-18 15:49:25 +01:00
|
|
|
G_FILE_CREATE_REPLACE_DESTINATION,
|
2007-11-26 17:13:05 +01:00
|
|
|
cancellable, error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out = (GOutputStream *)g_file_create (destination, 0, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (out == NULL)
|
|
|
|
{
|
|
|
|
g_object_unref (in);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-03-28 13:43:11 +01:00
|
|
|
if (!copy_stream_with_progress (in, out, source, cancellable,
|
2007-11-26 17:13:05 +01:00
|
|
|
progress_callback, progress_callback_data,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
copied_file:
|
|
|
|
|
|
|
|
/* Ignore errors here. Failure to copy metadata is not a hard error */
|
|
|
|
g_file_copy_attributes (source, destination,
|
|
|
|
flags, cancellable, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_copy:
|
|
|
|
* @source: input #GFile.
|
|
|
|
* @destination: destination #GFile
|
|
|
|
* @flags: set of #GFileCopyFlags
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @progress_callback: function to callback with progress information
|
2008-01-11 17:23:30 +01:00
|
|
|
* @progress_callback_data: user data to pass to @progress_callback
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: #GError to set on error, or %NULL
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
|
|
|
* Copies the file @source to the location specified by @destination.
|
|
|
|
* Can not handle recursive copies of directories.
|
|
|
|
*
|
|
|
|
* If the flag #G_FILE_COPY_OVERWRITE is specified an already
|
|
|
|
* existing @destination file is overwritten.
|
|
|
|
*
|
|
|
|
* If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
|
|
|
|
* will be copied as symlinks, otherwise the target of the
|
|
|
|
* @source symlink will be copied.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* If @progress_callback is not %NULL, then the operation can be monitored by
|
|
|
|
* setting this to a #GFileProgressCallback function. @progress_callback_data
|
2007-12-12 13:19:02 +01:00
|
|
|
* will be passed to this function. It is guaranteed that this callback will
|
2008-01-11 17:23:30 +01:00
|
|
|
* be called after all data has been transferred with the total number of bytes
|
2007-12-12 13:19:02 +01:00
|
|
|
* copied during the operation.
|
|
|
|
*
|
|
|
|
* If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
|
|
|
|
* error is returned, independent on the status of the @destination.
|
|
|
|
*
|
|
|
|
* If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then the
|
|
|
|
* error G_IO_ERROR_EXISTS is returned.
|
|
|
|
*
|
|
|
|
* If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY
|
|
|
|
* error is returned. If trying to overwrite a directory with a directory the
|
|
|
|
* G_IO_ERROR_WOULD_MERGE error is returned.
|
|
|
|
*
|
|
|
|
* If the source is a directory and the target does not exist, or #G_FILE_COPY_OVERWRITE is
|
|
|
|
* specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error
|
|
|
|
* is returned.
|
2007-12-03 19:25:24 +01:00
|
|
|
*
|
|
|
|
* If you are interested in copying the #GFile object itself (not the on-disk
|
|
|
|
* file), see g_file_dup().
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE on success, %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_file_copy (GFile *source,
|
|
|
|
GFile *destination,
|
|
|
|
GFileCopyFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GFileProgressCallback progress_callback,
|
|
|
|
gpointer progress_callback_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
GError *my_error;
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (source), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_FILE (destination), FALSE);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2008-01-17 11:57:48 +01:00
|
|
|
iface = G_FILE_GET_IFACE (destination);
|
|
|
|
if (iface->copy)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2008-01-17 11:57:48 +01:00
|
|
|
my_error = NULL;
|
|
|
|
res = (* iface->copy) (source, destination,
|
|
|
|
flags, cancellable,
|
|
|
|
progress_callback, progress_callback_data,
|
|
|
|
&my_error);
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-08-10 12:55:57 +02:00
|
|
|
else
|
|
|
|
g_clear_error (&my_error);
|
2008-01-17 11:57:48 +01:00
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2008-01-17 11:57:48 +01:00
|
|
|
/* If the types are different, and the destination method failed
|
|
|
|
also try the source method */
|
|
|
|
if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
|
|
|
|
{
|
|
|
|
iface = G_FILE_GET_IFACE (source);
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
if (iface->copy)
|
|
|
|
{
|
|
|
|
my_error = NULL;
|
2008-01-17 11:57:48 +01:00
|
|
|
res = (* iface->copy) (source, destination,
|
|
|
|
flags, cancellable,
|
|
|
|
progress_callback, progress_callback_data,
|
|
|
|
&my_error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (res)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-08-10 12:55:57 +02:00
|
|
|
else
|
|
|
|
g_clear_error (&my_error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
}
|
2008-01-17 11:57:48 +01:00
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
return file_copy_fallback (source, destination, flags, cancellable,
|
|
|
|
progress_callback, progress_callback_data,
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
|
2008-01-24 12:04:05 +01:00
|
|
|
/**
|
|
|
|
* g_file_copy_async:
|
|
|
|
* @source: input #GFile.
|
|
|
|
* @destination: destination #GFile
|
|
|
|
* @flags: set of #GFileCopyFlags
|
2008-01-28 18:09:26 +01:00
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
|
|
|
* of the request.
|
2008-01-24 12:04:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @progress_callback: function to callback with progress information
|
|
|
|
* @progress_callback_data: user data to pass to @progress_callback
|
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
|
|
|
*
|
2008-01-28 18:09:26 +01:00
|
|
|
* Copies the file @source to the location specified by @destination
|
|
|
|
* asynchronously. For details of the behaviour, see g_file_copy().
|
2008-01-24 12:04:05 +01:00
|
|
|
*
|
|
|
|
* If @progress_callback is not %NULL, then that function that will be called
|
|
|
|
* just like in g_file_copy(), however the callback will run in the main loop,
|
|
|
|
* not in the thread that is doing the I/O operation.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_copy_finish() to get the result of the operation.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_file_copy_async (GFile *source,
|
|
|
|
GFile *destination,
|
|
|
|
GFileCopyFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GFileProgressCallback progress_callback,
|
|
|
|
gpointer progress_callback_data,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (source));
|
|
|
|
g_return_if_fail (G_IS_FILE (destination));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (source);
|
|
|
|
(* iface->copy_async) (source,
|
|
|
|
destination,
|
|
|
|
flags,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
progress_callback,
|
|
|
|
progress_callback_data,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_copy_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @res: a #GAsyncResult.
|
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Finishes copying the file started with
|
|
|
|
* g_file_copy_async().
|
|
|
|
*
|
|
|
|
* Returns: a %TRUE on success, %FALSE on error.
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_file_copy_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->copy_finish) (file, res, error);
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_move:
|
2007-11-27 15:00:13 +01:00
|
|
|
* @source: #GFile pointing to the source location.
|
|
|
|
* @destination: #GFile pointing to the destination location.
|
2007-11-29 08:17:59 +01:00
|
|
|
* @flags: set of #GFileCopyFlags.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-29 08:17:59 +01:00
|
|
|
* @progress_callback: #GFileProgressCallback function for updates.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @progress_callback_data: gpointer to user data for the callback function.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: #GError for returning error conditions, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
|
|
|
* Tries to move the file or directory @source to the location specified by @destination.
|
2008-01-18 10:41:09 +01:00
|
|
|
* If native move operations are supported then this is used, otherwise a copy + delete
|
2007-12-12 13:19:02 +01:00
|
|
|
* fallback is used. The native implementation may support moving directories (for instance
|
|
|
|
* on moves inside the same filesystem), but the fallback code does not.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* If the flag #G_FILE_COPY_OVERWRITE is specified an already
|
|
|
|
* existing @destination file is overwritten.
|
|
|
|
*
|
|
|
|
* If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
|
|
|
|
* will be copied as symlinks, otherwise the target of the
|
|
|
|
* @source symlink will be copied.
|
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* If @progress_callback is not %NULL, then the operation can be monitored by
|
|
|
|
* setting this to a #GFileProgressCallback function. @progress_callback_data
|
2007-12-12 13:19:02 +01:00
|
|
|
* will be passed to this function. It is guaranteed that this callback will
|
2008-01-11 17:23:30 +01:00
|
|
|
* be called after all data has been transferred with the total number of bytes
|
2007-12-12 13:19:02 +01:00
|
|
|
* copied during the operation.
|
|
|
|
*
|
|
|
|
* If the @source file does not exist then the G_IO_ERROR_NOT_FOUND
|
|
|
|
* error is returned, independent on the status of the @destination.
|
|
|
|
*
|
|
|
|
* If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then the
|
|
|
|
* error G_IO_ERROR_EXISTS is returned.
|
|
|
|
*
|
|
|
|
* If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY
|
|
|
|
* error is returned. If trying to overwrite a directory with a directory the
|
|
|
|
* G_IO_ERROR_WOULD_MERGE error is returned.
|
|
|
|
*
|
|
|
|
* If the source is a directory and the target does not exist, or #G_FILE_COPY_OVERWRITE is
|
|
|
|
* specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error
|
2008-01-11 17:23:30 +01:00
|
|
|
* may be returned (if the native move operation isn't available).
|
2007-11-28 07:43:33 +01:00
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE on successful move, %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_file_move (GFile *source,
|
|
|
|
GFile *destination,
|
|
|
|
GFileCopyFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GFileProgressCallback progress_callback,
|
|
|
|
gpointer progress_callback_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
GError *my_error;
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (source), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_FILE (destination), FALSE);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2008-01-17 11:57:48 +01:00
|
|
|
iface = G_FILE_GET_IFACE (destination);
|
|
|
|
if (iface->move)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2008-01-17 11:57:48 +01:00
|
|
|
my_error = NULL;
|
|
|
|
res = (* iface->move) (source, destination,
|
|
|
|
flags, cancellable,
|
|
|
|
progress_callback, progress_callback_data,
|
|
|
|
&my_error);
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2008-01-17 11:57:48 +01:00
|
|
|
/* If the types are different, and the destination method failed
|
|
|
|
also try the source method */
|
|
|
|
if (G_OBJECT_TYPE (source) != G_OBJECT_TYPE (destination))
|
|
|
|
{
|
|
|
|
iface = G_FILE_GET_IFACE (source);
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
if (iface->move)
|
|
|
|
{
|
|
|
|
my_error = NULL;
|
2008-01-17 11:57:48 +01:00
|
|
|
res = (* iface->move) (source, destination,
|
|
|
|
flags, cancellable,
|
|
|
|
progress_callback, progress_callback_data,
|
|
|
|
&my_error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (res)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (my_error->domain != G_IO_ERROR || my_error->code != G_IO_ERROR_NOT_SUPPORTED)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-01-17 11:57:48 +01:00
|
|
|
|
2007-12-03 10:11:48 +01:00
|
|
|
if (flags & G_FILE_COPY_NO_FALLBACK_FOR_MOVE)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2007-12-03 10:11:48 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
flags |= G_FILE_COPY_ALL_METADATA;
|
|
|
|
if (!g_file_copy (source, destination, flags, cancellable,
|
|
|
|
progress_callback, progress_callback_data,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_file_delete (source, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_make_directory
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2008-06-11 17:48:06 +02:00
|
|
|
* Creates a directory. Note that this will only create a child directory of
|
|
|
|
* the immediate parent directory of the path or URI given by the #GFile. To
|
|
|
|
* recursively create directories, see g_file_make_directory_with_parents().
|
|
|
|
* This function will fail if the parent directory does not exist, setting
|
|
|
|
* @error to %G_IO_ERROR_NOT_FOUND. If the file system doesn't support creating
|
|
|
|
* directories, this function will fail, setting @error to
|
|
|
|
* %G_IO_ERROR_NOT_SUPPORTED.
|
2008-08-09 10:41:43 +02:00
|
|
|
*
|
|
|
|
* For a local #GFile the newly created directory will have the default
|
|
|
|
* (current) ownership and permissions of the current process.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE on successful creation, %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_make_directory (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->make_directory == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (* iface->make_directory) (file, cancellable, error);
|
|
|
|
}
|
|
|
|
|
2008-06-11 17:48:06 +02:00
|
|
|
/**
|
|
|
|
* g_file_make_directory_with_parents:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Creates a directory and any parent directories that may not exist similar to
|
|
|
|
* 'mkdir -p'. If the file system does not support creating directories, this
|
|
|
|
* function will fail, setting @error to %G_IO_ERROR_NOT_SUPPORTED.
|
|
|
|
*
|
2008-08-09 10:41:43 +02:00
|
|
|
* For a local #GFile the newly created directories will have the default
|
|
|
|
* (current) ownership and permissions of the current process.
|
|
|
|
*
|
2008-06-11 17:48:06 +02:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if all directories have been successfully created, %FALSE
|
|
|
|
* otherwise.
|
|
|
|
*
|
|
|
|
* Since: 2.18
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_file_make_directory_with_parents (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
GFile *parent_file, *work_file;
|
|
|
|
GList *list = NULL, *l;
|
|
|
|
GError *my_error = NULL;
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
result = g_file_make_directory (file, cancellable, &my_error);
|
|
|
|
if (result || my_error->code != G_IO_ERROR_NOT_FOUND)
|
|
|
|
{
|
|
|
|
if (my_error)
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
work_file = file;
|
|
|
|
|
|
|
|
while (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
|
|
|
|
{
|
|
|
|
g_clear_error (&my_error);
|
|
|
|
|
|
|
|
parent_file = g_file_get_parent (work_file);
|
|
|
|
if (parent_file == NULL)
|
|
|
|
break;
|
|
|
|
result = g_file_make_directory (parent_file, cancellable, &my_error);
|
|
|
|
|
|
|
|
if (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
|
|
|
|
list = g_list_prepend (list, parent_file);
|
|
|
|
|
|
|
|
work_file = parent_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (l = list; result && l; l = l->next)
|
|
|
|
{
|
|
|
|
result = g_file_make_directory ((GFile *) l->data, cancellable, &my_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean up */
|
|
|
|
while (list != NULL)
|
|
|
|
{
|
|
|
|
g_object_unref ((GFile *) list->data);
|
|
|
|
list = g_list_remove (list, list->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_file_make_directory (file, cancellable, error);
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/**
|
|
|
|
* g_file_make_symbolic_link:
|
|
|
|
* @file: input #GFile.
|
2007-12-12 13:19:02 +01:00
|
|
|
* @symlink_value: a string with the value of the new symlink.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @error: a #GError.
|
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Creates a symbolic link.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE on the creation of a new symlink, %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_make_symbolic_link (GFile *file,
|
|
|
|
const char *symlink_value,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (symlink_value != NULL, FALSE);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (*symlink_value == '\0')
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("Invalid symlink value given"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->make_symbolic_link == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (* iface->make_symbolic_link) (file, symlink_value, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_delete:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2008-03-01 15:52:03 +01:00
|
|
|
* Deletes a file. If the @file is a directory, it will only be deleted if it
|
|
|
|
* is empty.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE if the file was deleted. %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_delete (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->delete_file == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (* iface->delete_file) (file, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_trash:
|
2007-11-27 15:00:13 +01:00
|
|
|
* @file: #GFile to send to trash.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Sends @file to the "Trashcan", if possible. This is similar to
|
|
|
|
* deleting it, but the user can recover it before emptying the trashcan.
|
2008-01-11 17:23:30 +01:00
|
|
|
* Not all file systems support trashing, so this call can return the
|
2007-12-12 13:19:02 +01:00
|
|
|
* %G_IO_ERROR_NOT_SUPPORTED error.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE on successful trash, %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_trash (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->trash == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error,
|
|
|
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Trash not supported"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (* iface->trash) (file, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_set_display_name:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @display_name: a string.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Renames @file to the specified display name.
|
|
|
|
*
|
|
|
|
* The display name is converted from UTF8 to the correct encoding for the target
|
|
|
|
* filesystem if possible and the @file is renamed to this.
|
|
|
|
*
|
|
|
|
* If you want to implement a rename operation in the user interface the edit name
|
2007-12-20 14:30:47 +01:00
|
|
|
* (#G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the initial value in the rename
|
2007-12-12 13:19:02 +01:00
|
|
|
* widget, and then the result after editing should be passed to g_file_set_display_name().
|
|
|
|
*
|
|
|
|
* On success the resulting converted filename is returned.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2008-07-16 07:49:16 +02:00
|
|
|
* Returns: a #GFile specifying what @file was renamed to, or %NULL
|
|
|
|
* if there was an error.
|
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFile *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_display_name (GFile *file,
|
|
|
|
const char *display_name,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (display_name != NULL, NULL);
|
|
|
|
|
2007-12-10 12:19:41 +01:00
|
|
|
if (strchr (display_name, G_DIR_SEPARATOR) != NULL)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2007-12-10 12:19:41 +01:00
|
|
|
_("File names cannot contain '%c'"), G_DIR_SEPARATOR);
|
2007-11-26 17:13:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
return (* iface->set_display_name) (file, display_name, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_set_display_name_async:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @display_name: a string.
|
2007-11-30 19:11:03 +01:00
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
2007-11-30 06:51:10 +01:00
|
|
|
* of the request.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-12-09 16:51:12 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* Asynchronously sets the display name for a given #GFile.
|
2008-01-09 18:04:06 +01:00
|
|
|
*
|
2009-04-09 20:35:36 +02:00
|
|
|
* For more details, see g_file_set_display_name() which is
|
2008-01-09 18:04:06 +01:00
|
|
|
* the synchronous version of this call.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_set_display_name_finish() to get the result of the operation.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_display_name_async (GFile *file,
|
|
|
|
const char *display_name,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
g_return_if_fail (display_name != NULL);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
(* iface->set_display_name_async) (file,
|
|
|
|
display_name,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_set_display_name_finish:
|
|
|
|
* @file: input #GFile.
|
2007-11-27 15:00:13 +01:00
|
|
|
* @res: a #GAsyncResult.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Finishes setting a display name started with
|
|
|
|
* g_file_set_display_name_async().
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: a #GFile or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFile *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_display_name_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->set_display_name_finish) (file, res, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_query_settable_attributes:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Obtain the list of settable attributes for the file.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Returns the type and full attribute name of all the attributes
|
|
|
|
* that can be set on this file. This doesn't mean setting it will always
|
|
|
|
* succeed though, you might get an access failure, or some specific
|
|
|
|
* file may not support a specific attribute.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Returns: a #GFileAttributeInfoList describing the settable attributes.
|
|
|
|
* When you are done with it, release it with g_file_attribute_info_list_unref()
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileAttributeInfoList *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_query_settable_attributes (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
GError *my_error;
|
|
|
|
GFileAttributeInfoList *list;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->query_settable_attributes == NULL)
|
|
|
|
return g_file_attribute_info_list_new ();
|
|
|
|
|
|
|
|
my_error = NULL;
|
|
|
|
list = (* iface->query_settable_attributes) (file, cancellable, &my_error);
|
|
|
|
|
|
|
|
if (list == NULL)
|
|
|
|
{
|
|
|
|
if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
|
|
|
|
{
|
|
|
|
list = g_file_attribute_info_list_new ();
|
|
|
|
g_error_free (my_error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_query_writable_namespaces:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Obtain the list of attribute namespaces where new attributes
|
2007-12-12 13:19:02 +01:00
|
|
|
* can be created by a user. An example of this is extended
|
|
|
|
* attributes (in the "xattr" namespace).
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Returns: a #GFileAttributeInfoList describing the writable namespaces.
|
|
|
|
* When you are done with it, release it with g_file_attribute_info_list_unref()
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileAttributeInfoList *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_query_writable_namespaces (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
GError *my_error;
|
|
|
|
GFileAttributeInfoList *list;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->query_writable_namespaces == NULL)
|
|
|
|
return g_file_attribute_info_list_new ();
|
|
|
|
|
|
|
|
my_error = NULL;
|
|
|
|
list = (* iface->query_writable_namespaces) (file, cancellable, &my_error);
|
|
|
|
|
|
|
|
if (list == NULL)
|
|
|
|
{
|
|
|
|
if (my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_SUPPORTED)
|
|
|
|
{
|
|
|
|
list = g_file_attribute_info_list_new ();
|
|
|
|
g_error_free (my_error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_set_attribute:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @attribute: a string containing the attribute's name.
|
2007-12-14 16:56:56 +01:00
|
|
|
* @type: The type of the attribute
|
|
|
|
* @value_p: a pointer to the value (or the pointer itself if the type is a pointer type)
|
2007-11-27 15:00:13 +01:00
|
|
|
* @flags: a set of #GFileQueryInfoFlags.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Sets an attribute in the file with attribute name @attribute to @value.
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the attribute was set, %FALSE otherwise.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_attribute (GFile *file,
|
|
|
|
const char *attribute,
|
2007-12-14 16:56:56 +01:00
|
|
|
GFileAttributeType type,
|
|
|
|
gpointer value_p,
|
2007-11-29 08:17:59 +01:00
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->set_attribute == NULL)
|
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-12-14 16:56:56 +01:00
|
|
|
return (* iface->set_attribute) (file, attribute, type, value_p, flags, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_set_attributes_from_info:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @info: a #GFileInfo.
|
|
|
|
* @flags: #GFileQueryInfoFlags
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-28 07:43:33 +01:00
|
|
|
* Tries to set all attributes in the #GFileInfo on the target values,
|
|
|
|
* not stopping on the first error.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* If there is any error during this operation then @error will be set to
|
|
|
|
* the first error. Error on particular fields are flagged by setting
|
|
|
|
* the "status" field in the attribute value to
|
|
|
|
* %G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can also detect
|
|
|
|
* further errors.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Returns: %TRUE if there was any error, %FALSE otherwise.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_attributes_from_info (GFile *file,
|
|
|
|
GFileInfo *info,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
|
|
|
|
|
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_file_info_clear_status (info);
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
2007-11-29 08:17:59 +01:00
|
|
|
return (* iface->set_attributes_from_info) (file,
|
|
|
|
info,
|
|
|
|
flags,
|
|
|
|
cancellable,
|
|
|
|
error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_set_attributes_from_info (GFile *file,
|
|
|
|
GFileInfo *info,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
char **attributes;
|
|
|
|
int i;
|
|
|
|
gboolean res;
|
|
|
|
GFileAttributeValue *value;
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
|
|
|
|
attributes = g_file_info_list_attributes (info, NULL);
|
|
|
|
|
|
|
|
for (i = 0; attributes[i] != NULL; i++)
|
|
|
|
{
|
2007-12-14 16:56:56 +01:00
|
|
|
value = _g_file_info_get_attribute_value (info, attributes[i]);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (value->status != G_FILE_ATTRIBUTE_STATUS_UNSET)
|
|
|
|
continue;
|
|
|
|
|
2007-12-14 16:56:56 +01:00
|
|
|
if (!g_file_set_attribute (file, attributes[i],
|
|
|
|
value->type, _g_file_attribute_value_peek_as_pointer (value),
|
|
|
|
flags, cancellable, error))
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
value->status = G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING;
|
|
|
|
res = FALSE;
|
|
|
|
/* Don't set error multiple times */
|
|
|
|
error = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
value->status = G_FILE_ATTRIBUTE_STATUS_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (attributes);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_set_attributes_async:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @info: a #GFileInfo.
|
|
|
|
* @flags: a #GFileQueryInfoFlags.
|
2007-11-30 19:11:03 +01:00
|
|
|
* @io_priority: the <link linkend="io-priority">I/O priority</link>
|
2007-11-30 06:51:10 +01:00
|
|
|
* of the request.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @callback: a #GAsyncReadyCallback.
|
|
|
|
* @user_data: a #gpointer.
|
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Asynchronously sets the attributes of @file with @info.
|
2008-01-09 18:04:06 +01:00
|
|
|
*
|
|
|
|
* For more details, see g_file_set_attributes_from_info() which is
|
|
|
|
* the synchronous version of this call.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_set_attributes_finish() to get the result of the operation.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_attributes_async (GFile *file,
|
|
|
|
GFileInfo *info,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
g_return_if_fail (G_IS_FILE_INFO (info));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
2007-11-29 08:17:59 +01:00
|
|
|
(* iface->set_attributes_async) (file,
|
|
|
|
info,
|
|
|
|
flags,
|
|
|
|
io_priority,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_set_attributes_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @result: a #GAsyncResult.
|
|
|
|
* @info: a #GFileInfo.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Finishes setting an attribute started in g_file_set_attributes_async().
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE if the attributes were set correctly, %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_attributes_finish (GFile *file,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GFileInfo **info,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
|
|
|
|
|
|
|
|
/* No standard handling of errors here, as we must set info even
|
2007-11-29 08:17:59 +01:00
|
|
|
* on errors
|
|
|
|
*/
|
2007-11-26 17:13:05 +01:00
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->set_attributes_finish) (file, result, info, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_set_attribute_string:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @attribute: a string containing the attribute's name.
|
|
|
|
* @value: a string containing the attribute's value.
|
|
|
|
* @flags: #GFileQueryInfoFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value.
|
|
|
|
* If @attribute is of a different type, this operation will fail.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_attribute_string (GFile *file,
|
|
|
|
const char *attribute,
|
|
|
|
const char *value,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2007-12-14 16:56:56 +01:00
|
|
|
return g_file_set_attribute (file, attribute,
|
|
|
|
G_FILE_ATTRIBUTE_TYPE_STRING, (gpointer)value,
|
|
|
|
flags, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-27 15:00:13 +01:00
|
|
|
* g_file_set_attribute_byte_string:
|
2007-11-26 17:13:05 +01:00
|
|
|
* @file: input #GFile.
|
|
|
|
* @attribute: a string containing the attribute's name.
|
|
|
|
* @value: a string containing the attribute's new value.
|
|
|
|
* @flags: a #GFileQueryInfoFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value.
|
|
|
|
* If @attribute is of a different type, this operation will fail,
|
|
|
|
* returning %FALSE.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE if the @attribute was successfully set to @value
|
|
|
|
* in the @file, %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_attribute_byte_string (GFile *file,
|
|
|
|
const char *attribute,
|
|
|
|
const char *value,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2007-12-14 16:56:56 +01:00
|
|
|
return g_file_set_attribute (file, attribute,
|
|
|
|
G_FILE_ATTRIBUTE_TYPE_BYTE_STRING, (gpointer)value,
|
|
|
|
flags, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_set_attribute_uint32:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @attribute: a string containing the attribute's name.
|
|
|
|
* @value: a #guint32 containing the attribute's new value.
|
|
|
|
* @flags: a #GFileQueryInfoFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value.
|
|
|
|
* If @attribute is of a different type, this operation will fail.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE if the @attribute was successfully set to @value
|
|
|
|
* in the @file, %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_attribute_uint32 (GFile *file,
|
|
|
|
const char *attribute,
|
|
|
|
guint32 value,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2007-12-14 16:56:56 +01:00
|
|
|
return g_file_set_attribute (file, attribute,
|
|
|
|
G_FILE_ATTRIBUTE_TYPE_UINT32, &value,
|
|
|
|
flags, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_set_attribute_int32:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @attribute: a string containing the attribute's name.
|
|
|
|
* @value: a #gint32 containing the attribute's new value.
|
|
|
|
* @flags: a #GFileQueryInfoFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value.
|
|
|
|
* If @attribute is of a different type, this operation will fail.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE if the @attribute was successfully set to @value
|
|
|
|
* in the @file, %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_attribute_int32 (GFile *file,
|
|
|
|
const char *attribute,
|
|
|
|
gint32 value,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2007-12-14 16:56:56 +01:00
|
|
|
return g_file_set_attribute (file, attribute,
|
|
|
|
G_FILE_ATTRIBUTE_TYPE_INT32, &value,
|
|
|
|
flags, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_set_attribute_uint64:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @attribute: a string containing the attribute's name.
|
|
|
|
* @value: a #guint64 containing the attribute's new value.
|
|
|
|
* @flags: a #GFileQueryInfoFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value.
|
|
|
|
* If @attribute is of a different type, this operation will fail.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE if the @attribute was successfully set to @value
|
|
|
|
* in the @file, %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_attribute_uint64 (GFile *file,
|
|
|
|
const char *attribute,
|
|
|
|
guint64 value,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2007-12-14 16:56:56 +01:00
|
|
|
return g_file_set_attribute (file, attribute,
|
|
|
|
G_FILE_ATTRIBUTE_TYPE_UINT64, &value,
|
|
|
|
flags, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_set_attribute_int64:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @attribute: a string containing the attribute's name.
|
|
|
|
* @value: a #guint64 containing the attribute's new value.
|
|
|
|
* @flags: a #GFileQueryInfoFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value.
|
|
|
|
* If @attribute is of a different type, this operation will fail.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the @attribute was successfully set, %FALSE otherwise.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_set_attribute_int64 (GFile *file,
|
|
|
|
const char *attribute,
|
|
|
|
gint64 value,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
2007-12-14 16:56:56 +01:00
|
|
|
return g_file_set_attribute (file, attribute,
|
|
|
|
G_FILE_ATTRIBUTE_TYPE_INT64, &value,
|
|
|
|
flags, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_mount_mountable:
|
|
|
|
* @file: input #GFile.
|
2008-02-11 12:12:36 +01:00
|
|
|
* @flags: flags affecting the operation
|
2007-12-19 10:39:50 +01:00
|
|
|
* @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2008-01-15 15:08:41 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
|
2007-12-09 16:51:12 +01:00
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Mounts a file of type G_FILE_TYPE_MOUNTABLE.
|
2008-01-09 18:04:06 +01:00
|
|
|
* Using @mount_operation, you can request callbacks when, for instance,
|
2007-12-12 13:19:02 +01:00
|
|
|
* passwords are needed during authentication.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-12-12 13:19:02 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_mount_mountable_finish() to get the result of the operation.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_mount_mountable (GFile *file,
|
2008-02-11 12:12:36 +01:00
|
|
|
GMountMountFlags flags,
|
2007-11-29 08:17:59 +01:00
|
|
|
GMountOperation *mount_operation,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
2008-02-20 19:52:10 +01:00
|
|
|
if (iface->mount_mountable == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_report_error_in_idle (G_OBJECT (file),
|
|
|
|
callback,
|
|
|
|
user_data,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
return;
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
(* iface->mount_mountable) (file,
|
2008-02-11 12:12:36 +01:00
|
|
|
flags,
|
2007-11-26 17:13:05 +01:00
|
|
|
mount_operation,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_mount_mountable_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @result: a #GAsyncResult.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-29 11:18:55 +01:00
|
|
|
*
|
|
|
|
* Finishes a mount operation. See g_file_mount_mountable() for details.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Finish an asynchronous mount operation that was started
|
|
|
|
* with g_file_mount_mountable().
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: a #GFile or %NULL on error.
|
2008-07-16 07:49:16 +02:00
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFile *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_mount_mountable_finish (GFile *file,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (result))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->mount_mountable_finish) (file, result, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_unmount_mountable:
|
|
|
|
* @file: input #GFile.
|
2007-12-20 12:48:14 +01:00
|
|
|
* @flags: flags affecting the operation
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2008-01-15 15:08:41 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
|
2007-12-09 16:51:12 +01:00
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-29 11:18:55 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-12-12 13:19:02 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
2008-01-09 18:04:06 +01:00
|
|
|
* g_file_unmount_mountable_finish() to get the result of the operation.
|
2009-07-06 03:59:38 +02:00
|
|
|
*
|
|
|
|
* Deprecated: 2.22: Use g_file_unmount_mountable_with_operation() instead.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_unmount_mountable (GFile *file,
|
2007-12-20 12:48:14 +01:00
|
|
|
GMountUnmountFlags flags,
|
2007-11-29 08:17:59 +01:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->unmount_mountable == NULL)
|
2008-02-20 19:52:10 +01:00
|
|
|
{
|
|
|
|
g_simple_async_report_error_in_idle (G_OBJECT (file),
|
|
|
|
callback,
|
|
|
|
user_data,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
return;
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
(* iface->unmount_mountable) (file,
|
2007-12-20 12:48:14 +01:00
|
|
|
flags,
|
2007-11-26 17:13:05 +01:00
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_unmount_mountable_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @result: a #GAsyncResult.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-29 11:18:55 +01:00
|
|
|
*
|
|
|
|
* Finishes an unmount operation, see g_file_unmount_mountable() for details.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Finish an asynchronous unmount operation that was started
|
|
|
|
* with g_file_unmount_mountable().
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE if the operation finished successfully. %FALSE
|
|
|
|
* otherwise.
|
2009-07-06 03:59:38 +02:00
|
|
|
*
|
|
|
|
* Deprecated: 2.22: Use g_file_unmount_mountable_with_operation_finish() instead.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_unmount_mountable_finish (GFile *file,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (result))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->unmount_mountable_finish) (file, result, error);
|
|
|
|
}
|
|
|
|
|
2009-07-06 03:59:38 +02:00
|
|
|
/**
|
|
|
|
* g_file_unmount_mountable_with_operation:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @flags: flags affecting the operation
|
|
|
|
* @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
|
|
|
|
* @user_data: the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_unmount_mountable_finish() to get the result of the operation.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_file_unmount_mountable_with_operation (GFile *file,
|
|
|
|
GMountUnmountFlags flags,
|
|
|
|
GMountOperation *mount_operation,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->unmount_mountable == NULL && iface->unmount_mountable_with_operation == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_report_error_in_idle (G_OBJECT (file),
|
|
|
|
callback,
|
|
|
|
user_data,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iface->unmount_mountable_with_operation != NULL)
|
|
|
|
(* iface->unmount_mountable_with_operation) (file,
|
|
|
|
flags,
|
|
|
|
mount_operation,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
else
|
|
|
|
(* iface->unmount_mountable) (file,
|
|
|
|
flags,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_unmount_mountable_with_operation_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @result: a #GAsyncResult.
|
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Finishes an unmount operation, see g_file_unmount_mountable_with_operation() for details.
|
|
|
|
*
|
|
|
|
* Finish an asynchronous unmount operation that was started
|
|
|
|
* with g_file_unmount_mountable_with_operation().
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the operation finished successfully. %FALSE
|
|
|
|
* otherwise.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_file_unmount_mountable_with_operation_finish (GFile *file,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (result))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
if (iface->unmount_mountable_with_operation_finish != NULL)
|
|
|
|
return (* iface->unmount_mountable_with_operation_finish) (file, result, error);
|
|
|
|
else
|
|
|
|
return (* iface->unmount_mountable_finish) (file, result, error);
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/**
|
|
|
|
* g_file_eject_mountable:
|
|
|
|
* @file: input #GFile.
|
2007-12-20 12:48:14 +01:00
|
|
|
* @flags: flags affecting the operation
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2008-01-15 15:08:41 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
|
2007-12-09 16:51:12 +01:00
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Starts an asynchronous eject on a mountable.
|
|
|
|
* When this operation has completed, @callback will be called with
|
|
|
|
* @user_user data, and the operation can be finalized with
|
|
|
|
* g_file_eject_mountable_finish().
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2009-07-06 03:59:38 +02:00
|
|
|
*
|
|
|
|
* Deprecated: 2.22: Use g_file_eject_mountable_with_operation() instead.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_eject_mountable (GFile *file,
|
2007-12-20 12:48:14 +01:00
|
|
|
GMountUnmountFlags flags,
|
2007-11-29 08:17:59 +01:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
2008-02-20 19:52:10 +01:00
|
|
|
if (iface->eject_mountable == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_report_error_in_idle (G_OBJECT (file),
|
|
|
|
callback,
|
|
|
|
user_data,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
return;
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
(* iface->eject_mountable) (file,
|
2007-12-20 12:48:14 +01:00
|
|
|
flags,
|
2007-11-26 17:13:05 +01:00
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_eject_mountable_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @result: a #GAsyncResult.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Finishes an asynchronous eject operation started by
|
|
|
|
* g_file_eject_mountable().
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE if the @file was ejected successfully. %FALSE
|
|
|
|
* otherwise.
|
2009-07-06 03:59:38 +02:00
|
|
|
*
|
|
|
|
* Deprecated: 2.22: Use g_file_eject_mountable_with_operation_finish() instead.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_eject_mountable_finish (GFile *file,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (result))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->eject_mountable_finish) (file, result, error);
|
|
|
|
}
|
|
|
|
|
2009-07-06 03:59:38 +02:00
|
|
|
/**
|
|
|
|
* g_file_eject_mountable_with_operation:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @flags: flags affecting the operation
|
|
|
|
* @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
|
|
|
|
* @user_data: the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Starts an asynchronous eject on a mountable.
|
|
|
|
* When this operation has completed, @callback will be called with
|
|
|
|
* @user_user data, and the operation can be finalized with
|
|
|
|
* g_file_eject_mountable_with_operation_finish().
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_file_eject_mountable_with_operation (GFile *file,
|
|
|
|
GMountUnmountFlags flags,
|
|
|
|
GMountOperation *mount_operation,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->eject_mountable == NULL && iface->eject_mountable_with_operation == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_report_error_in_idle (G_OBJECT (file),
|
|
|
|
callback,
|
|
|
|
user_data,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iface->eject_mountable_with_operation != NULL)
|
|
|
|
(* iface->eject_mountable_with_operation) (file,
|
|
|
|
flags,
|
|
|
|
mount_operation,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
else
|
|
|
|
(* iface->eject_mountable) (file,
|
|
|
|
flags,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_eject_mountable_with_operation_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @result: a #GAsyncResult.
|
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Finishes an asynchronous eject operation started by
|
|
|
|
* g_file_eject_mountable_with_operation().
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the @file was ejected successfully. %FALSE
|
|
|
|
* otherwise.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_file_eject_mountable_with_operation_finish (GFile *file,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (result))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
if (iface->eject_mountable_with_operation_finish != NULL)
|
|
|
|
return (* iface->eject_mountable_with_operation_finish) (file, result, error);
|
|
|
|
else
|
|
|
|
return (* iface->eject_mountable_finish) (file, result, error);
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/**
|
|
|
|
* g_file_monitor_directory:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @flags: a set of #GFileMonitorFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2008-01-14 16:00:31 +01:00
|
|
|
* @error: a #GError, or %NULL.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Obtains a directory monitor for the given file.
|
2007-12-12 13:19:02 +01:00
|
|
|
* This may fail if directory monitoring is not supported.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2008-07-16 07:49:16 +02:00
|
|
|
* Returns: a #GFileMonitor for the given @file, or %NULL on error.
|
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
2008-01-07 14:42:08 +01:00
|
|
|
GFileMonitor*
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_monitor_directory (GFile *file,
|
|
|
|
GFileMonitorFlags flags,
|
2008-01-14 16:00:31 +01:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
2008-01-14 16:00:31 +01:00
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->monitor_dir == NULL)
|
2008-01-14 16:00:31 +01:00
|
|
|
{
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
2008-01-14 16:00:31 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-11-26 17:13:05 +01:00
|
|
|
|
2008-01-14 16:00:31 +01:00
|
|
|
return (* iface->monitor_dir) (file, flags, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_monitor_file:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @flags: a set of #GFileMonitorFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2008-01-14 16:00:31 +01:00
|
|
|
* @error: a #GError, or %NULL.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Obtains a file monitor for the given file. If no file notification
|
|
|
|
* mechanism exists, then regular polling of the file is used.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2008-07-16 07:49:16 +02:00
|
|
|
* Returns: a #GFileMonitor for the given @file, or %NULL on error.
|
|
|
|
* Free the returned object with g_object_unref().
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFileMonitor*
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_monitor_file (GFile *file,
|
|
|
|
GFileMonitorFlags flags,
|
2008-01-14 16:00:31 +01:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
GFileMonitor *monitor;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
2008-01-14 16:00:31 +01:00
|
|
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
|
|
return NULL;
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
monitor = NULL;
|
|
|
|
|
|
|
|
if (iface->monitor_file)
|
2008-01-14 16:04:25 +01:00
|
|
|
monitor = (* iface->monitor_file) (file, flags, cancellable, NULL);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
/* Fallback to polling */
|
|
|
|
if (monitor == NULL)
|
2007-11-28 17:01:59 +01:00
|
|
|
monitor = _g_poll_file_monitor_new (file);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
return monitor;
|
|
|
|
}
|
|
|
|
|
2008-07-02 19:19:16 +02:00
|
|
|
/**
|
|
|
|
* g_file_monitor:
|
|
|
|
* @file: input #GFile
|
|
|
|
* @flags: a set of #GFileMonitorFlags
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore
|
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Obtains a file or directory monitor for the given file, depending
|
|
|
|
* on the type of the file.
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2008-07-16 07:49:16 +02:00
|
|
|
* Returns: a #GFileMonitor for the given @file, or %NULL on error.
|
|
|
|
* Free the returned object with g_object_unref().
|
2008-07-02 19:19:16 +02:00
|
|
|
*
|
|
|
|
* Since: 2.18
|
|
|
|
*/
|
|
|
|
GFileMonitor*
|
|
|
|
g_file_monitor (GFile *file,
|
|
|
|
GFileMonitorFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
if (g_file_query_file_type (file, 0, cancellable) == G_FILE_TYPE_DIRECTORY)
|
|
|
|
return g_file_monitor_directory (file, flags, cancellable, error);
|
|
|
|
else
|
|
|
|
return g_file_monitor_file (file, flags, cancellable, error);
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/********************************************
|
|
|
|
* Default implementation of async ops *
|
|
|
|
********************************************/
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *attributes;
|
|
|
|
GFileQueryInfoFlags flags;
|
|
|
|
GFileInfo *info;
|
|
|
|
} QueryInfoAsyncData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
query_info_data_free (QueryInfoAsyncData *data)
|
|
|
|
{
|
|
|
|
if (data->info)
|
|
|
|
g_object_unref (data->info);
|
|
|
|
g_free (data->attributes);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
query_info_async_thread (GSimpleAsyncResult *res,
|
2007-11-29 08:17:59 +01:00
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
QueryInfoAsyncData *data;
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
|
|
|
|
info = g_file_query_info (G_FILE (object), data->attributes, data->flags, cancellable, &error);
|
|
|
|
|
|
|
|
if (info == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
data->info = info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_query_info_async (GFile *file,
|
|
|
|
const char *attributes,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
QueryInfoAsyncData *data;
|
|
|
|
|
|
|
|
data = g_new0 (QueryInfoAsyncData, 1);
|
|
|
|
data->attributes = g_strdup (attributes);
|
|
|
|
data->flags = flags;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_query_info_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_info_data_free);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, query_info_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GFileInfo *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_query_info_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
QueryInfoAsyncData *data;
|
|
|
|
|
2007-12-10 15:07:42 +01:00
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_info_async);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
if (data->info)
|
|
|
|
return g_object_ref (data->info);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
Implement this function by moving bits from glocalfileinfo.c
2008-02-21 David Zeuthen <davidz@redhat.com>
* glocalfileinfo.c: (_g_local_file_info_get):
* gcontenttype.c:
(g_content_type_get_icon): Implement this function by
moving bits from glocalfileinfo.c
(g_content_type_get_description): Unalias before getting
description (#517687)
* gfile.c: (g_file_class_init),
(g_file_query_filesystem_info_async),
(g_file_query_filesystem_info_finish),
(query_filesystem_info_data_free),
(query_filesystem_info_async_thread),
(g_file_real_query_filesystem_info_async),
(g_file_real_query_filesystem_info_finish):
* gfile.h: Implement async version of
g_file_query_filesystem_info()
* gfileinfo.h: Add new attributes for filesystem::use-preview
* gio.symbols: Update
* gthemedicon.c: (g_themed_icon_append_name):
* gthemedicon.h: Add new new convenience function.
* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
(get_mounts), (get_volumes), (get_connected_drives),
(get_volume_for_uuid), (get_mount_for_uuid),
(g_union_volume_monitor_init), (populate_union_monitor),
(g_volume_monitor_get), (_g_mount_get_for_mount_path),
(g_volume_monitor_adopt_orphan_mount):
* gvolumemonitor.c:
* gvolumemonitor.h: Use recursive locks so it's safe for volume
monitor implementations to call into the main volume monitor. Also
separate object initialization and volume monitor initialization
such that non-native volume monitors can properly adopt their
mounts away.
svn path=/trunk/; revision=6550
2008-02-21 13:35:05 +01:00
|
|
|
typedef struct {
|
|
|
|
char *attributes;
|
|
|
|
GFileInfo *info;
|
|
|
|
} QueryFilesystemInfoAsyncData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
query_filesystem_info_data_free (QueryFilesystemInfoAsyncData *data)
|
|
|
|
{
|
|
|
|
if (data->info)
|
|
|
|
g_object_unref (data->info);
|
|
|
|
g_free (data->attributes);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
query_filesystem_info_async_thread (GSimpleAsyncResult *res,
|
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
QueryFilesystemInfoAsyncData *data;
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
|
|
|
|
info = g_file_query_filesystem_info (G_FILE (object), data->attributes, cancellable, &error);
|
|
|
|
|
|
|
|
if (info == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
data->info = info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_file_real_query_filesystem_info_async (GFile *file,
|
|
|
|
const char *attributes,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
QueryFilesystemInfoAsyncData *data;
|
|
|
|
|
|
|
|
data = g_new0 (QueryFilesystemInfoAsyncData, 1);
|
|
|
|
data->attributes = g_strdup (attributes);
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_query_filesystem_info_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_filesystem_info_data_free);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, query_filesystem_info_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GFileInfo *
|
|
|
|
g_file_real_query_filesystem_info_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
QueryFilesystemInfoAsyncData *data;
|
|
|
|
|
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_filesystem_info_async);
|
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
if (data->info)
|
|
|
|
return g_object_ref (data->info);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
typedef struct {
|
|
|
|
char *attributes;
|
|
|
|
GFileQueryInfoFlags flags;
|
|
|
|
GFileEnumerator *enumerator;
|
|
|
|
} EnumerateChildrenAsyncData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
enumerate_children_data_free (EnumerateChildrenAsyncData *data)
|
|
|
|
{
|
|
|
|
if (data->enumerator)
|
|
|
|
g_object_unref (data->enumerator);
|
|
|
|
g_free (data->attributes);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
enumerate_children_async_thread (GSimpleAsyncResult *res,
|
2007-11-29 08:17:59 +01:00
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
EnumerateChildrenAsyncData *data;
|
|
|
|
GFileEnumerator *enumerator;
|
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
|
|
|
|
enumerator = g_file_enumerate_children (G_FILE (object), data->attributes, data->flags, cancellable, &error);
|
|
|
|
|
|
|
|
if (enumerator == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
data->enumerator = enumerator;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_enumerate_children_async (GFile *file,
|
|
|
|
const char *attributes,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
EnumerateChildrenAsyncData *data;
|
|
|
|
|
|
|
|
data = g_new0 (EnumerateChildrenAsyncData, 1);
|
|
|
|
data->attributes = g_strdup (attributes);
|
|
|
|
data->flags = flags;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_enumerate_children_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)enumerate_children_data_free);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, enumerate_children_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GFileEnumerator *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_enumerate_children_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
EnumerateChildrenAsyncData *data;
|
|
|
|
|
2007-12-10 15:07:42 +01:00
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_enumerate_children_async);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
if (data->enumerator)
|
|
|
|
return g_object_ref (data->enumerator);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
open_read_async_thread (GSimpleAsyncResult *res,
|
2007-11-29 08:17:59 +01:00
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
GFileInputStream *stream;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (object);
|
|
|
|
|
2008-07-18 19:48:30 +02:00
|
|
|
if (iface->read_fn == NULL)
|
|
|
|
{
|
2008-07-28 21:12:19 +02:00
|
|
|
g_set_error_literal (&error, G_IO_ERROR,
|
2008-07-18 19:48:30 +02:00
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-05 11:38:03 +01:00
|
|
|
stream = iface->read_fn (G_FILE (object), cancellable, &error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_read_async (GFile *file,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_read_async);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, open_read_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GFileInputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_read_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
gpointer op;
|
|
|
|
|
2007-12-10 15:07:42 +01:00
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_read_async);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
op = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
if (op)
|
|
|
|
return g_object_ref (op);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
append_to_async_thread (GSimpleAsyncResult *res,
|
2007-11-29 08:17:59 +01:00
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
GFileCreateFlags *data;
|
|
|
|
GFileOutputStream *stream;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (object);
|
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
|
|
|
|
stream = iface->append_to (G_FILE (object), *data, cancellable, &error);
|
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_append_to_async (GFile *file,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileCreateFlags *data;
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
data = g_new0 (GFileCreateFlags, 1);
|
|
|
|
*data = flags;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_append_to_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, append_to_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GFileOutputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_append_to_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
gpointer op;
|
|
|
|
|
2007-12-10 15:07:42 +01:00
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_append_to_async);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
op = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
if (op)
|
|
|
|
return g_object_ref (op);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_async_thread (GSimpleAsyncResult *res,
|
2007-11-29 08:17:59 +01:00
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
GFileCreateFlags *data;
|
|
|
|
GFileOutputStream *stream;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (object);
|
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
|
|
|
|
stream = iface->create (G_FILE (object), *data, cancellable, &error);
|
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_create_async (GFile *file,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileCreateFlags *data;
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
data = g_new0 (GFileCreateFlags, 1);
|
|
|
|
*data = flags;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_create_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, create_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GFileOutputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_create_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
gpointer op;
|
|
|
|
|
2007-12-10 15:07:42 +01:00
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_async);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
op = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
if (op)
|
|
|
|
return g_object_ref (op);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GFileOutputStream *stream;
|
|
|
|
char *etag;
|
|
|
|
gboolean make_backup;
|
|
|
|
GFileCreateFlags flags;
|
|
|
|
} ReplaceAsyncData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
replace_async_data_free (ReplaceAsyncData *data)
|
|
|
|
{
|
|
|
|
if (data->stream)
|
|
|
|
g_object_unref (data->stream);
|
|
|
|
g_free (data->etag);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
replace_async_thread (GSimpleAsyncResult *res,
|
2007-11-29 08:17:59 +01:00
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
GFileOutputStream *stream;
|
|
|
|
GError *error = NULL;
|
|
|
|
ReplaceAsyncData *data;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (object);
|
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
|
|
|
|
stream = iface->replace (G_FILE (object),
|
|
|
|
data->etag,
|
|
|
|
data->make_backup,
|
|
|
|
data->flags,
|
|
|
|
cancellable,
|
|
|
|
&error);
|
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
data->stream = stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_replace_async (GFile *file,
|
|
|
|
const char *etag,
|
|
|
|
gboolean make_backup,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
ReplaceAsyncData *data;
|
|
|
|
|
|
|
|
data = g_new0 (ReplaceAsyncData, 1);
|
|
|
|
data->etag = g_strdup (etag);
|
|
|
|
data->make_backup = make_backup;
|
|
|
|
data->flags = flags;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_replace_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_async_data_free);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, replace_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GFileOutputStream *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_replace_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
ReplaceAsyncData *data;
|
|
|
|
|
2007-12-10 15:07:42 +01:00
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_async);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
if (data->stream)
|
|
|
|
return g_object_ref (data->stream);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-13 13:00:26 +02:00
|
|
|
static void
|
|
|
|
open_readwrite_async_thread (GSimpleAsyncResult *res,
|
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
GFileIOStream *stream;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (object);
|
|
|
|
|
|
|
|
if (iface->open_readwrite == NULL)
|
|
|
|
{
|
|
|
|
g_set_error_literal (&error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = iface->open_readwrite (G_FILE (object), cancellable, &error);
|
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_file_real_open_readwrite_async (GFile *file,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_open_readwrite_async);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, open_readwrite_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GFileIOStream *
|
|
|
|
g_file_real_open_readwrite_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
gpointer op;
|
|
|
|
|
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_open_readwrite_async);
|
|
|
|
|
|
|
|
op = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
if (op)
|
|
|
|
return g_object_ref (op);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_readwrite_async_thread (GSimpleAsyncResult *res,
|
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
GFileCreateFlags *data;
|
|
|
|
GFileIOStream *stream;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (object);
|
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
|
|
|
|
if (iface->create_readwrite == NULL)
|
|
|
|
{
|
|
|
|
g_set_error_literal (&error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = iface->create_readwrite (G_FILE (object), *data, cancellable, &error);
|
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_file_real_create_readwrite_async (GFile *file,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GFileCreateFlags *data;
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
data = g_new0 (GFileCreateFlags, 1);
|
|
|
|
*data = flags;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_create_readwrite_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, create_readwrite_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GFileIOStream *
|
|
|
|
g_file_real_create_readwrite_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
gpointer op;
|
|
|
|
|
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_readwrite_async);
|
|
|
|
|
|
|
|
op = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
if (op)
|
|
|
|
return g_object_ref (op);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GFileIOStream *stream;
|
|
|
|
char *etag;
|
|
|
|
gboolean make_backup;
|
|
|
|
GFileCreateFlags flags;
|
|
|
|
} ReplaceRWAsyncData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
replace_rw_async_data_free (ReplaceRWAsyncData *data)
|
|
|
|
{
|
|
|
|
if (data->stream)
|
|
|
|
g_object_unref (data->stream);
|
|
|
|
g_free (data->etag);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
replace_readwrite_async_thread (GSimpleAsyncResult *res,
|
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
GFileIOStream *stream;
|
|
|
|
GError *error = NULL;
|
|
|
|
ReplaceRWAsyncData *data;
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (object);
|
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
|
|
|
|
stream = iface->replace_readwrite (G_FILE (object),
|
|
|
|
data->etag,
|
|
|
|
data->make_backup,
|
|
|
|
data->flags,
|
|
|
|
cancellable,
|
|
|
|
&error);
|
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
data->stream = stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_file_real_replace_readwrite_async (GFile *file,
|
|
|
|
const char *etag,
|
|
|
|
gboolean make_backup,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
ReplaceRWAsyncData *data;
|
|
|
|
|
|
|
|
data = g_new0 (ReplaceRWAsyncData, 1);
|
|
|
|
data->etag = g_strdup (etag);
|
|
|
|
data->make_backup = make_backup;
|
|
|
|
data->flags = flags;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_replace_readwrite_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_rw_async_data_free);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, replace_readwrite_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GFileIOStream *
|
|
|
|
g_file_real_replace_readwrite_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
ReplaceRWAsyncData *data;
|
|
|
|
|
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_readwrite_async);
|
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
if (data->stream)
|
|
|
|
return g_object_ref (data->stream);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
typedef struct {
|
|
|
|
char *name;
|
|
|
|
GFile *file;
|
|
|
|
} SetDisplayNameAsyncData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_display_name_data_free (SetDisplayNameAsyncData *data)
|
|
|
|
{
|
|
|
|
g_free (data->name);
|
|
|
|
if (data->file)
|
|
|
|
g_object_unref (data->file);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_display_name_async_thread (GSimpleAsyncResult *res,
|
2007-11-29 08:17:59 +01:00
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
SetDisplayNameAsyncData *data;
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
|
|
|
|
file = g_file_set_display_name (G_FILE (object), data->name, cancellable, &error);
|
|
|
|
|
|
|
|
if (file == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
data->file = file;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_set_display_name_async (GFile *file,
|
|
|
|
const char *display_name,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
SetDisplayNameAsyncData *data;
|
|
|
|
|
|
|
|
data = g_new0 (SetDisplayNameAsyncData, 1);
|
|
|
|
data->name = g_strdup (display_name);
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_set_display_name_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)set_display_name_data_free);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, set_display_name_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GFile *
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_set_display_name_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
SetDisplayNameAsyncData *data;
|
|
|
|
|
2007-12-10 15:07:42 +01:00
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_display_name_async);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
if (data->file)
|
|
|
|
return g_object_ref (data->file);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GFileQueryInfoFlags flags;
|
|
|
|
GFileInfo *info;
|
|
|
|
gboolean res;
|
|
|
|
GError *error;
|
|
|
|
} SetInfoAsyncData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_info_data_free (SetInfoAsyncData *data)
|
|
|
|
{
|
|
|
|
if (data->info)
|
|
|
|
g_object_unref (data->info);
|
|
|
|
if (data->error)
|
|
|
|
g_error_free (data->error);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_info_async_thread (GSimpleAsyncResult *res,
|
2007-11-29 08:17:59 +01:00
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
SetInfoAsyncData *data;
|
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
|
|
|
|
data->error = NULL;
|
|
|
|
data->res = g_file_set_attributes_from_info (G_FILE (object),
|
|
|
|
data->info,
|
|
|
|
data->flags,
|
|
|
|
cancellable,
|
|
|
|
&data->error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_set_attributes_async (GFile *file,
|
|
|
|
GFileInfo *info,
|
|
|
|
GFileQueryInfoFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
SetInfoAsyncData *data;
|
|
|
|
|
|
|
|
data = g_new0 (SetInfoAsyncData, 1);
|
|
|
|
data->info = g_file_info_dup (info);
|
|
|
|
data->flags = flags;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_set_attributes_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)set_info_data_free);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, set_info_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_real_set_attributes_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GFileInfo **info,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
SetInfoAsyncData *data;
|
|
|
|
|
2007-12-10 15:07:42 +01:00
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_attributes_async);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
*info = g_object_ref (data->info);
|
|
|
|
|
2007-11-29 08:17:59 +01:00
|
|
|
if (error != NULL && data->error)
|
2007-11-26 17:13:05 +01:00
|
|
|
*error = g_error_copy (data->error);
|
|
|
|
|
|
|
|
return data->res;
|
|
|
|
}
|
|
|
|
|
2008-01-17 15:22:13 +01:00
|
|
|
static void
|
|
|
|
find_enclosing_mount_async_thread (GSimpleAsyncResult *res,
|
|
|
|
GObject *object,
|
|
|
|
GCancellable *cancellable)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
GMount *mount;
|
|
|
|
|
|
|
|
mount = g_file_find_enclosing_mount (G_FILE (object), cancellable, &error);
|
|
|
|
|
|
|
|
if (mount == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, mount, (GDestroyNotify)g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_file_real_find_enclosing_mount_async (GFile *file,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_find_enclosing_mount_async);
|
|
|
|
|
|
|
|
g_simple_async_result_run_in_thread (res, find_enclosing_mount_async_thread, io_priority, cancellable);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GMount *
|
|
|
|
g_file_real_find_enclosing_mount_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
GMount *mount;
|
|
|
|
|
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_find_enclosing_mount_async);
|
|
|
|
|
|
|
|
mount = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
return g_object_ref (mount);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-24 12:04:05 +01:00
|
|
|
typedef struct {
|
|
|
|
GFile *source;
|
|
|
|
GFile *destination;
|
|
|
|
GFileCopyFlags flags;
|
|
|
|
GFileProgressCallback progress_cb;
|
|
|
|
gpointer progress_cb_data;
|
|
|
|
GIOSchedulerJob *job;
|
|
|
|
} CopyAsyncData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_async_data_free (CopyAsyncData *data)
|
|
|
|
{
|
|
|
|
g_object_unref (data->source);
|
|
|
|
g_object_unref (data->destination);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
CopyAsyncData *data;
|
|
|
|
goffset current_num_bytes;
|
|
|
|
goffset total_num_bytes;
|
|
|
|
} ProgressData;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
copy_async_progress_in_main (gpointer user_data)
|
|
|
|
{
|
|
|
|
ProgressData *progress = user_data;
|
|
|
|
CopyAsyncData *data = progress->data;
|
|
|
|
|
|
|
|
data->progress_cb (progress->current_num_bytes,
|
|
|
|
progress->total_num_bytes,
|
|
|
|
data->progress_cb_data);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
mainloop_barrier (gpointer user_data)
|
|
|
|
{
|
|
|
|
/* Does nothing, but ensures all queued idles before
|
|
|
|
this are run */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2008-01-25 15:40:54 +01:00
|
|
|
copy_async_progress_callback (goffset current_num_bytes,
|
|
|
|
goffset total_num_bytes,
|
2008-01-24 12:04:05 +01:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
CopyAsyncData *data = user_data;
|
|
|
|
ProgressData *progress;
|
|
|
|
|
|
|
|
progress = g_new (ProgressData, 1);
|
|
|
|
progress->data = data;
|
|
|
|
progress->current_num_bytes = current_num_bytes;
|
|
|
|
progress->total_num_bytes = total_num_bytes;
|
|
|
|
|
|
|
|
g_io_scheduler_job_send_to_mainloop_async (data->job,
|
|
|
|
copy_async_progress_in_main,
|
|
|
|
progress,
|
|
|
|
g_free);
|
|
|
|
}
|
|
|
|
|
2008-01-25 15:40:54 +01:00
|
|
|
static gboolean
|
2008-01-24 12:04:05 +01:00
|
|
|
copy_async_thread (GIOSchedulerJob *job,
|
2008-01-25 15:40:54 +01:00
|
|
|
GCancellable *cancellable,
|
|
|
|
gpointer user_data)
|
2008-01-24 12:04:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
CopyAsyncData *data;
|
|
|
|
gboolean result;
|
|
|
|
GError *error;
|
|
|
|
|
|
|
|
res = user_data;
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
data->job = job;
|
|
|
|
result = g_file_copy (data->source,
|
|
|
|
data->destination,
|
|
|
|
data->flags,
|
|
|
|
cancellable,
|
|
|
|
(data->progress_cb != NULL) ? copy_async_progress_callback : NULL,
|
|
|
|
data,
|
|
|
|
&error);
|
|
|
|
|
|
|
|
/* Ensure all progress callbacks are done running in main thread */
|
|
|
|
if (data->progress_cb != NULL)
|
|
|
|
g_io_scheduler_job_send_to_mainloop (job,
|
|
|
|
mainloop_barrier,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_from_error (res, error);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_simple_async_result_complete_in_idle (res);
|
2008-01-25 15:40:54 +01:00
|
|
|
|
|
|
|
return FALSE;
|
2008-01-24 12:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_file_real_copy_async (GFile *source,
|
|
|
|
GFile *destination,
|
|
|
|
GFileCopyFlags flags,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GFileProgressCallback progress_callback,
|
|
|
|
gpointer progress_callback_data,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
CopyAsyncData *data;
|
|
|
|
|
|
|
|
data = g_new0 (CopyAsyncData, 1);
|
|
|
|
data->source = g_object_ref (source);
|
|
|
|
data->destination = g_object_ref (destination);
|
|
|
|
data->flags = flags;
|
|
|
|
data->progress_cb = progress_callback;
|
|
|
|
data->progress_cb_data = progress_callback_data;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (source), callback, user_data, g_file_real_copy_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)copy_async_data_free);
|
|
|
|
|
|
|
|
g_io_scheduler_push_job (copy_async_thread, res, g_object_unref, io_priority, cancellable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_file_real_copy_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
/* Error handled in g_file_copy_finish() */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/********************************************
|
|
|
|
* Default VFS operations *
|
|
|
|
********************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_new_for_path:
|
|
|
|
* @path: a string containing a relative or absolute path.
|
|
|
|
*
|
2007-11-28 07:43:33 +01:00
|
|
|
* Constructs a #GFile for a given path. This operation never
|
2007-11-26 17:13:05 +01:00
|
|
|
* fails, but the returned object might not support any I/O
|
2007-11-28 07:43:33 +01:00
|
|
|
* operation if @path is malformed.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-28 05:29:02 +01:00
|
|
|
* Returns: a new #GFile for the given @path.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFile *
|
|
|
|
g_file_new_for_path (const char *path)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (path != NULL, NULL);
|
|
|
|
|
2007-11-29 08:17:59 +01:00
|
|
|
return g_vfs_get_file_for_path (g_vfs_get_default (), path);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_new_for_uri:
|
|
|
|
* @uri: a string containing a URI.
|
|
|
|
*
|
2007-11-28 07:43:33 +01:00
|
|
|
* Constructs a #GFile for a given URI. This operation never
|
|
|
|
* fails, but the returned object might not support any I/O
|
|
|
|
* operation if @uri is malformed or if the uri type is
|
|
|
|
* not supported.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-28 05:29:02 +01:00
|
|
|
* Returns: a #GFile for the given @uri.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFile *
|
|
|
|
g_file_new_for_uri (const char *uri)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (uri != NULL, NULL);
|
|
|
|
|
2007-11-29 08:17:59 +01:00
|
|
|
return g_vfs_get_file_for_uri (g_vfs_get_default (), uri);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_parse_name:
|
|
|
|
* @parse_name: a file name or path to be parsed.
|
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Constructs a #GFile with the given @parse_name (i.e. something given by g_file_get_parse_name()).
|
|
|
|
* This operation never fails, but the returned object might not support any I/O
|
|
|
|
* operation if the @parse_name cannot be parsed.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-28 05:29:02 +01:00
|
|
|
* Returns: a new #GFile.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFile *
|
|
|
|
g_file_parse_name (const char *parse_name)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (parse_name != NULL, NULL);
|
|
|
|
|
2007-11-29 08:17:59 +01:00
|
|
|
return g_vfs_parse_name (g_vfs_get_default (), parse_name);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_valid_scheme_character (char c)
|
|
|
|
{
|
|
|
|
return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
|
|
|
|
}
|
|
|
|
|
2008-05-13 14:42:40 +02:00
|
|
|
/* Following RFC 2396, valid schemes are built like:
|
|
|
|
* scheme = alpha *( alpha | digit | "+" | "-" | "." )
|
|
|
|
*/
|
2007-11-26 17:13:05 +01:00
|
|
|
static gboolean
|
|
|
|
has_valid_scheme (const char *uri)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
p = uri;
|
|
|
|
|
2008-05-13 14:42:40 +02:00
|
|
|
if (!g_ascii_isalpha (*p))
|
2007-11-26 17:13:05 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
do {
|
|
|
|
p++;
|
|
|
|
} while (is_valid_scheme_character (*p));
|
|
|
|
|
|
|
|
return *p == ':';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_new_for_commandline_arg:
|
|
|
|
* @arg: a command line string.
|
|
|
|
*
|
2008-01-01 15:39:51 +01:00
|
|
|
* Creates a #GFile with the given argument from the command line. The value of
|
|
|
|
* @arg can be either a URI, an absolute path or a relative path resolved
|
|
|
|
* relative to the current working directory.
|
|
|
|
* This operation never fails, but the returned object might not support any
|
|
|
|
* I/O operation if @arg points to a malformed path.
|
|
|
|
*
|
2007-11-28 05:29:02 +01:00
|
|
|
* Returns: a new #GFile.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GFile *
|
|
|
|
g_file_new_for_commandline_arg (const char *arg)
|
|
|
|
{
|
|
|
|
GFile *file;
|
|
|
|
char *filename;
|
|
|
|
char *current_dir;
|
|
|
|
|
|
|
|
g_return_val_if_fail (arg != NULL, NULL);
|
|
|
|
|
|
|
|
if (g_path_is_absolute (arg))
|
|
|
|
return g_file_new_for_path (arg);
|
|
|
|
|
|
|
|
if (has_valid_scheme (arg))
|
|
|
|
return g_file_new_for_uri (arg);
|
|
|
|
|
|
|
|
current_dir = g_get_current_dir ();
|
|
|
|
filename = g_build_filename (current_dir, arg, NULL);
|
|
|
|
g_free (current_dir);
|
|
|
|
|
|
|
|
file = g_file_new_for_path (filename);
|
|
|
|
g_free (filename);
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-12-13 17:22:43 +01:00
|
|
|
* g_file_mount_enclosing_volume:
|
2007-11-26 17:13:05 +01:00
|
|
|
* @location: input #GFile.
|
2008-02-11 12:12:36 +01:00
|
|
|
* @flags: flags affecting the operation
|
2007-12-19 10:39:50 +01:00
|
|
|
* @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2008-01-15 15:08:41 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
|
2007-12-09 16:51:12 +01:00
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-12 13:19:02 +01:00
|
|
|
* Starts a @mount_operation, mounting the volume that contains the file @location.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* When this operation has completed, @callback will be called with
|
|
|
|
* @user_user data, and the operation can be finalized with
|
2007-12-13 17:22:43 +01:00
|
|
|
* g_file_mount_enclosing_volume_finish().
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-12-13 17:22:43 +01:00
|
|
|
g_file_mount_enclosing_volume (GFile *location,
|
2008-02-11 12:12:36 +01:00
|
|
|
GMountMountFlags flags,
|
2007-12-13 17:22:43 +01:00
|
|
|
GMountOperation *mount_operation,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (location));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (location);
|
|
|
|
|
2007-12-13 17:22:43 +01:00
|
|
|
if (iface->mount_enclosing_volume == NULL)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
g_simple_async_report_error_in_idle (G_OBJECT (location),
|
|
|
|
callback, user_data,
|
|
|
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("volume doesn't implement mount"));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-11 12:12:36 +01:00
|
|
|
(* iface->mount_enclosing_volume) (location, flags, mount_operation, cancellable, callback, user_data);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-12-13 17:22:43 +01:00
|
|
|
* g_file_mount_enclosing_volume_finish:
|
2007-11-26 17:13:05 +01:00
|
|
|
* @location: input #GFile.
|
|
|
|
* @result: a #GAsyncResult.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-13 17:22:43 +01:00
|
|
|
* Finishes a mount operation started by g_file_mount_enclosing_volume().
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Returns: %TRUE if successful. If an error
|
2008-01-11 17:23:30 +01:00
|
|
|
* has occurred, this function will return %FALSE and set @error
|
2007-11-27 15:00:13 +01:00
|
|
|
* appropriately if present.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
2007-12-13 17:22:43 +01:00
|
|
|
g_file_mount_enclosing_volume_finish (GFile *location,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (location), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (result))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (location);
|
|
|
|
|
2007-12-13 17:22:43 +01:00
|
|
|
return (* iface->mount_enclosing_volume_finish) (location, result, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************
|
|
|
|
* Utility functions *
|
|
|
|
********************************************/
|
|
|
|
|
2008-01-29 13:23:24 +01:00
|
|
|
/**
|
|
|
|
* g_file_query_default_handler:
|
|
|
|
* @file: a #GFile to open.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Returns the #GAppInfo that is registered as the default
|
2008-02-06 17:02:20 +01:00
|
|
|
* application to handle the file specified by @file.
|
2008-01-29 13:23:24 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* Returns: a #GAppInfo if the handle was found, %NULL if there were errors.
|
|
|
|
* When you are done with it, release it with g_object_unref()
|
|
|
|
**/
|
2008-01-29 13:18:48 +01:00
|
|
|
GAppInfo *
|
|
|
|
g_file_query_default_handler (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
char *uri_scheme;
|
|
|
|
const char *content_type;
|
|
|
|
GAppInfo *appinfo;
|
|
|
|
GFileInfo *info;
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
uri_scheme = g_file_get_uri_scheme (file);
|
2009-11-19 01:43:30 +01:00
|
|
|
if (uri_scheme && uri_scheme[0] != '\0')
|
2009-10-25 07:56:13 +01:00
|
|
|
{
|
|
|
|
appinfo = g_app_info_get_default_for_uri_scheme (uri_scheme);
|
|
|
|
g_free (uri_scheme);
|
2008-01-29 13:18:48 +01:00
|
|
|
|
2009-10-25 07:56:13 +01:00
|
|
|
if (appinfo != NULL)
|
|
|
|
return appinfo;
|
|
|
|
}
|
2008-01-29 13:18:48 +01:00
|
|
|
|
|
|
|
info = g_file_query_info (file,
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
|
|
|
|
0,
|
|
|
|
cancellable,
|
|
|
|
error);
|
|
|
|
if (info == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
appinfo = NULL;
|
|
|
|
|
|
|
|
content_type = g_file_info_get_content_type (info);
|
|
|
|
if (content_type)
|
|
|
|
{
|
|
|
|
/* Don't use is_native(), as we want to support fuse paths if availible */
|
|
|
|
path = g_file_get_path (file);
|
|
|
|
appinfo = g_app_info_get_default_for_type (content_type,
|
|
|
|
path == NULL);
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
|
|
|
|
if (appinfo != NULL)
|
|
|
|
return appinfo;
|
|
|
|
|
2008-06-16 18:53:58 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("No application is registered as handling this file"));
|
2008-01-29 13:18:48 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
#define GET_CONTENT_BLOCK_SIZE 8192
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_load_contents:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-27 15:00:13 +01:00
|
|
|
* @contents: a location to place the contents of the file.
|
2008-07-16 06:21:50 +02:00
|
|
|
* @length: a location to place the length of the contents of the file,
|
|
|
|
* or %NULL if the length is not needed
|
|
|
|
* @etag_out: a location to place the current entity tag for the file,
|
|
|
|
* or %NULL if the entity tag is not needed
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-12-12 13:19:02 +01:00
|
|
|
*
|
2008-07-16 06:21:50 +02:00
|
|
|
* Loads the content of the file into memory. The data is always
|
|
|
|
* zero-terminated, but this is not included in the resultant @length.
|
|
|
|
* The returned @content should be freed with g_free() when no longer
|
|
|
|
* needed.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE if the @file's contents were successfully loaded.
|
2008-07-16 06:21:50 +02:00
|
|
|
* %FALSE if there were errors.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_load_contents (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
char **contents,
|
|
|
|
gsize *length,
|
|
|
|
char **etag_out,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileInputStream *in;
|
|
|
|
GByteArray *content;
|
|
|
|
gsize pos;
|
|
|
|
gssize res;
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (contents != NULL, FALSE);
|
|
|
|
|
2007-11-29 08:17:59 +01:00
|
|
|
in = g_file_read (file, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
if (in == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
content = g_byte_array_new ();
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
|
|
|
|
while ((res = g_input_stream_read (G_INPUT_STREAM (in),
|
|
|
|
content->data + pos,
|
|
|
|
GET_CONTENT_BLOCK_SIZE,
|
|
|
|
cancellable, error)) > 0)
|
|
|
|
{
|
|
|
|
pos += res;
|
|
|
|
g_byte_array_set_size (content, pos + GET_CONTENT_BLOCK_SIZE + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (etag_out)
|
|
|
|
{
|
|
|
|
*etag_out = NULL;
|
|
|
|
|
|
|
|
info = g_file_input_stream_query_info (in,
|
|
|
|
G_FILE_ATTRIBUTE_ETAG_VALUE,
|
|
|
|
cancellable,
|
|
|
|
NULL);
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
*etag_out = g_strdup (g_file_info_get_etag (info));
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ignore errors on close */
|
|
|
|
g_input_stream_close (G_INPUT_STREAM (in), cancellable, NULL);
|
|
|
|
g_object_unref (in);
|
|
|
|
|
|
|
|
if (res < 0)
|
|
|
|
{
|
|
|
|
/* error is set already */
|
|
|
|
g_byte_array_free (content, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length)
|
|
|
|
*length = pos;
|
|
|
|
|
|
|
|
/* Zero terminate (we got an extra byte allocated for this */
|
|
|
|
content->data[pos] = 0;
|
|
|
|
|
|
|
|
*contents = (char *)g_byte_array_free (content, FALSE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GFile *file;
|
|
|
|
GError *error;
|
|
|
|
GCancellable *cancellable;
|
|
|
|
GFileReadMoreCallback read_more_callback;
|
|
|
|
GAsyncReadyCallback callback;
|
|
|
|
gpointer user_data;
|
|
|
|
GByteArray *content;
|
|
|
|
gsize pos;
|
|
|
|
char *etag;
|
|
|
|
} LoadContentsData;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
load_contents_data_free (LoadContentsData *data)
|
|
|
|
{
|
|
|
|
if (data->error)
|
|
|
|
g_error_free (data->error);
|
|
|
|
if (data->cancellable)
|
|
|
|
g_object_unref (data->cancellable);
|
|
|
|
if (data->content)
|
|
|
|
g_byte_array_free (data->content, TRUE);
|
|
|
|
g_free (data->etag);
|
|
|
|
g_object_unref (data->file);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
load_contents_close_callback (GObject *obj,
|
|
|
|
GAsyncResult *close_res,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GInputStream *stream = G_INPUT_STREAM (obj);
|
|
|
|
LoadContentsData *data = user_data;
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
/* Ignore errors here, we're only reading anyway */
|
|
|
|
g_input_stream_close_finish (stream, close_res, NULL);
|
|
|
|
g_object_unref (stream);
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (data->file),
|
|
|
|
data->callback,
|
|
|
|
data->user_data,
|
|
|
|
g_file_load_contents_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)load_contents_data_free);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
load_contents_fstat_callback (GObject *obj,
|
2007-11-26 17:13:05 +01:00
|
|
|
GAsyncResult *stat_res,
|
2007-11-29 08:17:59 +01:00
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GInputStream *stream = G_INPUT_STREAM (obj);
|
|
|
|
LoadContentsData *data = user_data;
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
info = g_file_input_stream_query_info_finish (G_FILE_INPUT_STREAM (stream),
|
|
|
|
stat_res, NULL);
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
data->etag = g_strdup (g_file_info_get_etag (info));
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_input_stream_close_async (stream, 0,
|
|
|
|
data->cancellable,
|
|
|
|
load_contents_close_callback, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
load_contents_read_callback (GObject *obj,
|
2007-11-26 17:13:05 +01:00
|
|
|
GAsyncResult *read_res,
|
2007-11-29 08:17:59 +01:00
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GInputStream *stream = G_INPUT_STREAM (obj);
|
|
|
|
LoadContentsData *data = user_data;
|
|
|
|
GError *error = NULL;
|
|
|
|
gssize read_size;
|
|
|
|
|
|
|
|
read_size = g_input_stream_read_finish (stream, read_res, &error);
|
|
|
|
|
|
|
|
if (read_size < 0)
|
|
|
|
{
|
|
|
|
/* Error or EOF, close the file */
|
|
|
|
data->error = error;
|
|
|
|
g_input_stream_close_async (stream, 0,
|
|
|
|
data->cancellable,
|
|
|
|
load_contents_close_callback, data);
|
|
|
|
}
|
|
|
|
else if (read_size == 0)
|
|
|
|
{
|
|
|
|
g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
|
|
|
|
G_FILE_ATTRIBUTE_ETAG_VALUE,
|
|
|
|
0,
|
|
|
|
data->cancellable,
|
|
|
|
load_contents_fstat_callback,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
else if (read_size > 0)
|
|
|
|
{
|
|
|
|
data->pos += read_size;
|
|
|
|
|
|
|
|
g_byte_array_set_size (data->content,
|
|
|
|
data->pos + GET_CONTENT_BLOCK_SIZE);
|
|
|
|
|
|
|
|
|
|
|
|
if (data->read_more_callback &&
|
|
|
|
!data->read_more_callback ((char *)data->content->data, data->pos, data->user_data))
|
|
|
|
g_file_input_stream_query_info_async (G_FILE_INPUT_STREAM (stream),
|
|
|
|
G_FILE_ATTRIBUTE_ETAG_VALUE,
|
|
|
|
0,
|
|
|
|
data->cancellable,
|
|
|
|
load_contents_fstat_callback,
|
|
|
|
data);
|
|
|
|
else
|
|
|
|
g_input_stream_read_async (stream,
|
|
|
|
data->content->data + data->pos,
|
|
|
|
GET_CONTENT_BLOCK_SIZE,
|
|
|
|
0,
|
|
|
|
data->cancellable,
|
|
|
|
load_contents_read_callback,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
load_contents_open_callback (GObject *obj,
|
2007-11-26 17:13:05 +01:00
|
|
|
GAsyncResult *open_res,
|
2007-11-29 08:17:59 +01:00
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFile *file = G_FILE (obj);
|
|
|
|
GFileInputStream *stream;
|
|
|
|
LoadContentsData *data = user_data;
|
|
|
|
GError *error = NULL;
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
stream = g_file_read_finish (file, open_res, &error);
|
|
|
|
|
|
|
|
if (stream)
|
|
|
|
{
|
|
|
|
g_byte_array_set_size (data->content,
|
|
|
|
data->pos + GET_CONTENT_BLOCK_SIZE);
|
|
|
|
g_input_stream_read_async (G_INPUT_STREAM (stream),
|
|
|
|
data->content->data + data->pos,
|
|
|
|
GET_CONTENT_BLOCK_SIZE,
|
|
|
|
0,
|
|
|
|
data->cancellable,
|
|
|
|
load_contents_read_callback,
|
|
|
|
data);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = g_simple_async_result_new_from_error (G_OBJECT (data->file),
|
|
|
|
data->callback,
|
|
|
|
data->user_data,
|
|
|
|
error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_error_free (error);
|
|
|
|
load_contents_data_free (data);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_load_partial_contents_async:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2008-01-09 18:04:06 +01:00
|
|
|
* @read_more_callback: a #GFileReadMoreCallback to receive partial data and to specify whether further data should be read.
|
2007-12-09 16:51:12 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to the callback functions.
|
|
|
|
*
|
|
|
|
* Reads the partial contents of a file. A #GFileReadMoreCallback should be
|
|
|
|
* used to stop reading from the file when appropriate, else this function
|
|
|
|
* will behave exactly as g_file_load_contents_async(). This operation
|
|
|
|
* can be finished by g_file_load_partial_contents_finish().
|
|
|
|
*
|
|
|
|
* Users of this function should be aware that @user_data is passed to
|
|
|
|
* both the @read_more_callback and the @callback.
|
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-11-27 15:00:13 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_load_partial_contents_async (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GFileReadMoreCallback read_more_callback,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
LoadContentsData *data;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
data = g_new0 (LoadContentsData, 1);
|
|
|
|
|
|
|
|
if (cancellable)
|
|
|
|
data->cancellable = g_object_ref (cancellable);
|
|
|
|
data->read_more_callback = read_more_callback;
|
|
|
|
data->callback = callback;
|
|
|
|
data->user_data = user_data;
|
|
|
|
data->content = g_byte_array_new ();
|
|
|
|
data->file = g_object_ref (file);
|
|
|
|
|
|
|
|
g_file_read_async (file,
|
|
|
|
0,
|
|
|
|
cancellable,
|
|
|
|
load_contents_open_callback,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_load_partial_contents_finish:
|
|
|
|
* @file: input #GFile.
|
2007-11-27 15:00:13 +01:00
|
|
|
* @res: a #GAsyncResult.
|
|
|
|
* @contents: a location to place the contents of the file.
|
2008-07-16 06:21:50 +02:00
|
|
|
* @length: a location to place the length of the contents of the file,
|
|
|
|
* or %NULL if the length is not needed
|
|
|
|
* @etag_out: a location to place the current entity tag for the file,
|
|
|
|
* or %NULL if the entity tag is not needed
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Finishes an asynchronous partial load operation that was started
|
2008-07-16 06:21:50 +02:00
|
|
|
* with g_file_load_partial_contents_async(). The data is always
|
|
|
|
* zero-terminated, but this is not included in the resultant @length.
|
|
|
|
* The returned @content should be freed with g_free() when no longer
|
|
|
|
* needed.
|
2007-11-29 08:17:59 +01:00
|
|
|
*
|
2007-11-26 17:13:05 +01:00
|
|
|
* Returns: %TRUE if the load was successful. If %FALSE and @error is
|
|
|
|
* present, it will be set appropriately.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_load_partial_contents_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
char **contents,
|
|
|
|
gsize *length,
|
|
|
|
char **etag_out,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple;
|
|
|
|
LoadContentsData *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE);
|
|
|
|
g_return_val_if_fail (contents != NULL, FALSE);
|
|
|
|
|
|
|
|
simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2007-12-10 15:07:42 +01:00
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_load_contents_async);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
|
|
|
|
if (data->error)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, data->error);
|
|
|
|
data->error = NULL;
|
|
|
|
*contents = NULL;
|
|
|
|
if (length)
|
|
|
|
*length = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length)
|
|
|
|
*length = data->pos;
|
|
|
|
|
|
|
|
if (etag_out)
|
|
|
|
{
|
|
|
|
*etag_out = data->etag;
|
|
|
|
data->etag = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Zero terminate */
|
2007-11-29 08:17:59 +01:00
|
|
|
g_byte_array_set_size (data->content, data->pos + 1);
|
2007-11-26 17:13:05 +01:00
|
|
|
data->content->data[data->pos] = 0;
|
|
|
|
|
|
|
|
*contents = (char *)g_byte_array_free (data->content, FALSE);
|
|
|
|
data->content = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_load_contents_async:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-12-09 16:51:12 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2008-01-09 18:04:06 +01:00
|
|
|
* Starts an asynchronous load of the @file's contents.
|
|
|
|
*
|
|
|
|
* For more details, see g_file_load_contents() which is
|
|
|
|
* the synchronous version of this call.
|
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* When the load operation has completed, @callback will be called
|
2008-01-11 17:23:30 +01:00
|
|
|
* with @user data. To finish the operation, call
|
2007-11-29 08:17:59 +01:00
|
|
|
* g_file_load_contents_finish() with the #GAsyncResult returned by
|
|
|
|
* the @callback.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-11-27 15:00:13 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_load_contents_async (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
g_file_load_partial_contents_async (file,
|
|
|
|
cancellable,
|
|
|
|
NULL,
|
|
|
|
callback, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_load_contents_finish:
|
|
|
|
* @file: input #GFile.
|
2007-11-27 15:00:13 +01:00
|
|
|
* @res: a #GAsyncResult.
|
|
|
|
* @contents: a location to place the contents of the file.
|
2008-07-16 06:21:50 +02:00
|
|
|
* @length: a location to place the length of the contents of the file,
|
|
|
|
* or %NULL if the length is not needed
|
|
|
|
* @etag_out: a location to place the current entity tag for the file,
|
|
|
|
* or %NULL if the entity tag is not needed
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 08:17:59 +01:00
|
|
|
* Finishes an asynchronous load of the @file's contents.
|
|
|
|
* The contents are placed in @contents, and @length is set to the
|
2008-07-16 06:21:50 +02:00
|
|
|
* size of the @contents string. The @content should be freed with
|
|
|
|
* g_free() when no longer needed. If @etag_out is present, it will be
|
2007-11-29 08:17:59 +01:00
|
|
|
* set to the new entity tag for the @file.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if the load was successful. If %FALSE and @error is
|
|
|
|
* present, it will be set appropriately.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_load_contents_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
char **contents,
|
|
|
|
gsize *length,
|
|
|
|
char **etag_out,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
return g_file_load_partial_contents_finish (file,
|
|
|
|
res,
|
|
|
|
contents,
|
|
|
|
length,
|
|
|
|
etag_out,
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_replace_contents:
|
|
|
|
* @file: input #GFile.
|
2007-11-27 15:00:13 +01:00
|
|
|
* @contents: a string containing the new contents for @file.
|
|
|
|
* @length: the length of @contents in bytes.
|
2007-11-30 19:11:03 +01:00
|
|
|
* @etag: the old <link linkend="gfile-etag">entity tag</link>
|
2008-07-16 06:21:50 +02:00
|
|
|
* for the document, or %NULL
|
2008-01-09 18:04:06 +01:00
|
|
|
* @make_backup: %TRUE if a backup should be created.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @flags: a set of #GFileCreateFlags.
|
2007-11-30 19:11:03 +01:00
|
|
|
* @new_etag: a location to a new <link linkend="gfile-etag">entity tag</link>
|
2008-01-27 08:25:29 +01:00
|
|
|
* for the document. This should be freed with g_free() when no longer
|
2008-07-16 06:21:50 +02:00
|
|
|
* needed, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-12-07 10:16:32 +01:00
|
|
|
* Replaces the contents of @file with @contents of @length bytes.
|
|
|
|
|
|
|
|
* If @etag is specified (not %NULL) any existing file must have that etag, or
|
|
|
|
* the error %G_IO_ERROR_WRONG_ETAG will be returned.
|
|
|
|
*
|
|
|
|
* If @make_backup is %TRUE, this function will attempt to make a backup of @file.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-11-27 15:00:13 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2007-12-07 10:16:32 +01:00
|
|
|
*
|
|
|
|
* The returned @new_etag can be used to verify that the file hasn't changed the
|
|
|
|
* next time it is saved over.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if successful. If an error
|
2008-01-11 17:23:30 +01:00
|
|
|
* has occurred, this function will return %FALSE and set @error
|
2007-11-26 17:13:05 +01:00
|
|
|
* appropriately if present.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_replace_contents (GFile *file,
|
|
|
|
const char *contents,
|
|
|
|
gsize length,
|
|
|
|
const char *etag,
|
|
|
|
gboolean make_backup,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
char **new_etag,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFileOutputStream *out;
|
|
|
|
gsize pos, remainder;
|
|
|
|
gssize res;
|
2008-06-10 13:40:45 +02:00
|
|
|
gboolean ret;
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (contents != NULL, FALSE);
|
|
|
|
|
2007-11-28 07:01:13 +01:00
|
|
|
out = g_file_replace (file, etag, make_backup, flags, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
if (out == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
remainder = length;
|
|
|
|
while (remainder > 0 &&
|
|
|
|
(res = g_output_stream_write (G_OUTPUT_STREAM (out),
|
|
|
|
contents + pos,
|
|
|
|
MIN (remainder, GET_CONTENT_BLOCK_SIZE),
|
|
|
|
cancellable,
|
|
|
|
error)) > 0)
|
|
|
|
{
|
|
|
|
pos += res;
|
|
|
|
remainder -= res;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remainder > 0 && res < 0)
|
|
|
|
{
|
|
|
|
/* Ignore errors on close */
|
|
|
|
g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, NULL);
|
2008-06-10 13:40:45 +02:00
|
|
|
g_object_unref (out);
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/* error is set already */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-06-10 13:40:45 +02:00
|
|
|
ret = g_output_stream_close (G_OUTPUT_STREAM (out), cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
if (new_etag)
|
|
|
|
*new_etag = g_file_output_stream_get_etag (out);
|
2008-06-10 13:40:45 +02:00
|
|
|
|
2008-06-11 16:05:45 +02:00
|
|
|
g_object_unref (out);
|
|
|
|
|
2008-06-10 13:40:45 +02:00
|
|
|
return ret;
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GFile *file;
|
|
|
|
GError *error;
|
|
|
|
GCancellable *cancellable;
|
|
|
|
GAsyncReadyCallback callback;
|
|
|
|
gpointer user_data;
|
|
|
|
const char *content;
|
|
|
|
gsize length;
|
|
|
|
gsize pos;
|
|
|
|
char *etag;
|
|
|
|
} ReplaceContentsData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
replace_contents_data_free (ReplaceContentsData *data)
|
|
|
|
{
|
|
|
|
if (data->error)
|
|
|
|
g_error_free (data->error);
|
|
|
|
if (data->cancellable)
|
|
|
|
g_object_unref (data->cancellable);
|
|
|
|
g_object_unref (data->file);
|
|
|
|
g_free (data->etag);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
replace_contents_close_callback (GObject *obj,
|
2007-11-26 17:13:05 +01:00
|
|
|
GAsyncResult *close_res,
|
2007-11-29 08:17:59 +01:00
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GOutputStream *stream = G_OUTPUT_STREAM (obj);
|
|
|
|
ReplaceContentsData *data = user_data;
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
/* Ignore errors here, we're only reading anyway */
|
|
|
|
g_output_stream_close_finish (stream, close_res, NULL);
|
|
|
|
g_object_unref (stream);
|
|
|
|
|
|
|
|
data->etag = g_file_output_stream_get_etag (G_FILE_OUTPUT_STREAM (stream));
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (data->file),
|
|
|
|
data->callback,
|
|
|
|
data->user_data,
|
|
|
|
g_file_replace_contents_async);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_contents_data_free);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
replace_contents_write_callback (GObject *obj,
|
2007-11-26 17:13:05 +01:00
|
|
|
GAsyncResult *read_res,
|
2007-11-29 08:17:59 +01:00
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GOutputStream *stream = G_OUTPUT_STREAM (obj);
|
|
|
|
ReplaceContentsData *data = user_data;
|
|
|
|
GError *error = NULL;
|
|
|
|
gssize write_size;
|
|
|
|
|
|
|
|
write_size = g_output_stream_write_finish (stream, read_res, &error);
|
|
|
|
|
|
|
|
if (write_size <= 0)
|
|
|
|
{
|
|
|
|
/* Error or EOF, close the file */
|
|
|
|
if (write_size < 0)
|
|
|
|
data->error = error;
|
|
|
|
g_output_stream_close_async (stream, 0,
|
|
|
|
data->cancellable,
|
|
|
|
replace_contents_close_callback, data);
|
|
|
|
}
|
|
|
|
else if (write_size > 0)
|
|
|
|
{
|
|
|
|
data->pos += write_size;
|
|
|
|
|
|
|
|
if (data->pos >= data->length)
|
|
|
|
g_output_stream_close_async (stream, 0,
|
|
|
|
data->cancellable,
|
|
|
|
replace_contents_close_callback, data);
|
|
|
|
else
|
|
|
|
g_output_stream_write_async (stream,
|
|
|
|
data->content + data->pos,
|
|
|
|
data->length - data->pos,
|
|
|
|
0,
|
|
|
|
data->cancellable,
|
|
|
|
replace_contents_write_callback,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-29 08:17:59 +01:00
|
|
|
replace_contents_open_callback (GObject *obj,
|
2007-11-26 17:13:05 +01:00
|
|
|
GAsyncResult *open_res,
|
2007-11-29 08:17:59 +01:00
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GFile *file = G_FILE (obj);
|
|
|
|
GFileOutputStream *stream;
|
|
|
|
ReplaceContentsData *data = user_data;
|
|
|
|
GError *error = NULL;
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
stream = g_file_replace_finish (file, open_res, &error);
|
|
|
|
|
|
|
|
if (stream)
|
|
|
|
{
|
|
|
|
g_output_stream_write_async (G_OUTPUT_STREAM (stream),
|
|
|
|
data->content + data->pos,
|
|
|
|
data->length - data->pos,
|
|
|
|
0,
|
|
|
|
data->cancellable,
|
|
|
|
replace_contents_write_callback,
|
|
|
|
data);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = g_simple_async_result_new_from_error (G_OBJECT (data->file),
|
|
|
|
data->callback,
|
|
|
|
data->user_data,
|
|
|
|
error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_error_free (error);
|
|
|
|
replace_contents_data_free (data);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_replace_contents_async:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @contents: string of contents to replace the file with.
|
2007-11-27 15:00:13 +01:00
|
|
|
* @length: the length of @contents in bytes.
|
2008-07-16 06:21:50 +02:00
|
|
|
* @etag: a new <link linkend="gfile-etag">entity tag</link> for the @file, or %NULL
|
2008-01-09 18:04:06 +01:00
|
|
|
* @make_backup: %TRUE if a backup should be created.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @flags: a set of #GFileCreateFlags.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
2007-12-09 16:51:12 +01:00
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
|
|
|
|
* @user_data: the data to pass to callback function
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* Starts an asynchronous replacement of @file with the given
|
|
|
|
* @contents of @length bytes. @etag will replace the document's
|
|
|
|
* current entity tag.
|
|
|
|
*
|
|
|
|
* When this operation has completed, @callback will be called with
|
|
|
|
* @user_user data, and the operation can be finalized with
|
|
|
|
* g_file_replace_contents_finish().
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
2007-11-27 15:00:13 +01:00
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* If @make_backup is %TRUE, this function will attempt to
|
|
|
|
* make a backup of @file.
|
|
|
|
**/
|
|
|
|
void
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_replace_contents_async (GFile *file,
|
|
|
|
const char *contents,
|
|
|
|
gsize length,
|
|
|
|
const char *etag,
|
|
|
|
gboolean make_backup,
|
|
|
|
GFileCreateFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
ReplaceContentsData *data;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
g_return_if_fail (contents != NULL);
|
|
|
|
|
|
|
|
data = g_new0 (ReplaceContentsData, 1);
|
|
|
|
|
|
|
|
if (cancellable)
|
|
|
|
data->cancellable = g_object_ref (cancellable);
|
|
|
|
data->callback = callback;
|
|
|
|
data->user_data = user_data;
|
|
|
|
data->content = contents;
|
|
|
|
data->length = length;
|
|
|
|
data->pos = 0;
|
|
|
|
data->file = g_object_ref (file);
|
|
|
|
|
|
|
|
g_file_replace_async (file,
|
|
|
|
etag,
|
|
|
|
make_backup,
|
|
|
|
flags,
|
|
|
|
0,
|
|
|
|
cancellable,
|
|
|
|
replace_contents_open_callback,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_replace_contents_finish:
|
|
|
|
* @file: input #GFile.
|
2007-11-27 15:00:13 +01:00
|
|
|
* @res: a #GAsyncResult.
|
2007-11-30 19:11:03 +01:00
|
|
|
* @new_etag: a location of a new <link linkend="gfile-etag">entity tag</link>
|
2008-01-27 08:25:29 +01:00
|
|
|
* for the document. This should be freed with g_free() when it is no
|
2008-07-16 06:21:50 +02:00
|
|
|
* longer needed, or %NULL
|
2007-11-28 07:01:13 +01:00
|
|
|
* @error: a #GError, or %NULL
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-29 11:18:55 +01:00
|
|
|
* Finishes an asynchronous replace of the given @file. See
|
|
|
|
* g_file_replace_contents_async(). Sets @new_etag to the new entity
|
|
|
|
* tag for the document, if present.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* Returns: %TRUE on success, %FALSE on failure.
|
|
|
|
**/
|
|
|
|
gboolean
|
2007-11-29 08:17:59 +01:00
|
|
|
g_file_replace_contents_finish (GFile *file,
|
|
|
|
GAsyncResult *res,
|
|
|
|
char **new_etag,
|
|
|
|
GError **error)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple;
|
|
|
|
ReplaceContentsData *data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE);
|
|
|
|
|
|
|
|
simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2007-12-10 15:07:42 +01:00
|
|
|
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_replace_contents_async);
|
2007-11-26 17:13:05 +01:00
|
|
|
|
|
|
|
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
|
|
|
|
|
|
if (data->error)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, data->error);
|
|
|
|
data->error = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (new_etag)
|
|
|
|
{
|
|
|
|
*new_etag = data->etag;
|
|
|
|
data->etag = NULL; /* Take ownership */
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-11-28 13:39:07 +01:00
|
|
|
|
2009-06-15 16:53:41 +02:00
|
|
|
/**
|
|
|
|
* g_file_start_mountable:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @flags: flags affecting the operation
|
|
|
|
* @start_operation: a #GMountOperation, or %NULL to avoid user interaction.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
|
|
|
|
* @user_data: the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Starts a file of type G_FILE_TYPE_MOUNTABLE.
|
|
|
|
* Using @start_operation, you can request callbacks when, for instance,
|
|
|
|
* passwords are needed during authentication.
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_mount_mountable_finish() to get the result of the operation.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_file_start_mountable (GFile *file,
|
|
|
|
GDriveStartFlags flags,
|
|
|
|
GMountOperation *start_operation,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->start_mountable == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_report_error_in_idle (G_OBJECT (file),
|
|
|
|
callback,
|
|
|
|
user_data,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(* iface->start_mountable) (file,
|
|
|
|
flags,
|
|
|
|
start_operation,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_start_mountable_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @result: a #GAsyncResult.
|
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Finishes a start operation. See g_file_start_mountable() for details.
|
|
|
|
*
|
|
|
|
* Finish an asynchronous start operation that was started
|
|
|
|
* with g_file_start_mountable().
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the operation finished successfully. %FALSE
|
|
|
|
* otherwise.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
g_file_start_mountable_finish (GFile *file,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (result))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->start_mountable_finish) (file, result, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_stop_mountable:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @flags: flags affecting the operation
|
2009-07-06 03:59:38 +02:00
|
|
|
* @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
|
2009-06-15 16:53:41 +02:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
|
|
|
|
* @user_data: the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Stops a file of type G_FILE_TYPE_MOUNTABLE.
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_stop_mountable_finish() to get the result of the operation.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_file_stop_mountable (GFile *file,
|
|
|
|
GMountUnmountFlags flags,
|
2009-07-06 03:59:38 +02:00
|
|
|
GMountOperation *mount_operation,
|
2009-06-15 16:53:41 +02:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->stop_mountable == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_report_error_in_idle (G_OBJECT (file),
|
|
|
|
callback,
|
|
|
|
user_data,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(* iface->stop_mountable) (file,
|
|
|
|
flags,
|
2009-07-06 03:59:38 +02:00
|
|
|
mount_operation,
|
2009-06-15 16:53:41 +02:00
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_stop_mountable_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @result: a #GAsyncResult.
|
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Finishes an stop operation, see g_file_stop_mountable() for details.
|
|
|
|
*
|
|
|
|
* Finish an asynchronous stop operation that was started
|
|
|
|
* with g_file_stop_mountable().
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the operation finished successfully. %FALSE
|
|
|
|
* otherwise.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
g_file_stop_mountable_finish (GFile *file,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (result))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->stop_mountable_finish) (file, result, error);
|
|
|
|
}
|
|
|
|
|
2009-07-06 03:59:38 +02:00
|
|
|
/**
|
|
|
|
* g_file_poll_mountable:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
|
|
|
|
* @user_data: the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Polls a file of type G_FILE_TYPE_MOUNTABLE.
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* When the operation is finished, @callback will be called. You can then call
|
|
|
|
* g_file_mount_mountable_finish() to get the result of the operation.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_file_poll_mountable (GFile *file,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
|
|
|
|
if (iface->poll_mountable == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_report_error_in_idle (G_OBJECT (file),
|
|
|
|
callback,
|
|
|
|
user_data,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Operation not supported"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(* iface->poll_mountable) (file,
|
|
|
|
cancellable,
|
|
|
|
callback,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_file_poll_mountable_finish:
|
|
|
|
* @file: input #GFile.
|
|
|
|
* @result: a #GAsyncResult.
|
|
|
|
* @error: a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Finishes a poll operation. See g_file_poll_mountable() for details.
|
|
|
|
*
|
|
|
|
* Finish an asynchronous poll operation that was polled
|
|
|
|
* with g_file_poll_mountable().
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the operation finished successfully. %FALSE
|
|
|
|
* otherwise.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
g_file_poll_mountable_finish (GFile *file,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GFileIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
|
|
|
|
|
|
|
|
if (G_IS_SIMPLE_ASYNC_RESULT (result))
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return (* iface->poll_mountable_finish) (file, result, error);
|
|
|
|
}
|
|
|
|
|
2009-06-17 02:22:58 +02:00
|
|
|
/**
|
|
|
|
* g_file_supports_thread_contexts:
|
|
|
|
* @file: a #GFile.
|
|
|
|
*
|
|
|
|
* Checks if @file supports <link
|
|
|
|
* linkend="g-main-context-push-thread-default-context">thread-default
|
|
|
|
* contexts</link>. If this returns %FALSE, you cannot perform
|
|
|
|
* asynchronous operations on @file in a thread that has a
|
|
|
|
* thread-default context.
|
|
|
|
*
|
|
|
|
* Returns: Whether or not @file supports thread-default contexts.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
g_file_supports_thread_contexts (GFile *file)
|
|
|
|
{
|
2009-07-06 03:59:38 +02:00
|
|
|
GFileIface *iface;
|
2009-06-17 02:22:58 +02:00
|
|
|
|
2009-07-06 03:59:38 +02:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
2009-06-17 02:22:58 +02:00
|
|
|
|
2009-07-06 03:59:38 +02:00
|
|
|
iface = G_FILE_GET_IFACE (file);
|
|
|
|
return iface->supports_thread_contexts;
|
2009-06-17 02:22:58 +02:00
|
|
|
}
|
|
|
|
|
2007-11-28 13:39:07 +01:00
|
|
|
#define __G_FILE_C__
|
|
|
|
#include "gioaliasdef.c"
|