* 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.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Author: Alexander Larsson <alexl@redhat.com>
* David Zeuthen <davidz@redhat.com>
*/
-#include <config.h>
+#include "config.h"
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <glib.h>
+#include "gsubprocess.h"
+#include "gioenums.h"
#include "gunixvolumemonitor.h"
#include "gunixmount.h"
+#include "gunixmounts.h"
#include "gunixvolume.h"
#include "gmountprivate.h"
+#include "gmount.h"
+#include "gfile.h"
#include "gvolumemonitor.h"
#include "gthemedicon.h"
#include "gsimpleasyncresult.h"
+#include "gioerror.h"
#include "glibintl.h"
+/* for BUFSIZ */
+#include <stdio.h>
-#include "gioalias.h"
struct _GUnixMount {
GObject parent;
char *name;
GIcon *icon;
+ GIcon *symbolic_icon;
char *device_path;
char *mount_path;
/* TODO: g_warn_if_fail (volume->volume == NULL); */
g_object_unref (mount->icon);
+ g_object_unref (mount->symbolic_icon);
g_free (mount->name);
g_free (mount->device_path);
g_free (mount->mount_path);
-
- if (G_OBJECT_CLASS (g_unix_mount_parent_class)->finalize)
- (*G_OBJECT_CLASS (g_unix_mount_parent_class)->finalize) (object);
+
+ G_OBJECT_CLASS (g_unix_mount_parent_class)->finalize (object);
}
static void
GUnixMount *mount;
/* No volume for mount: Ignore internal things */
- if (volume == NULL && g_unix_mount_is_system_internal (mount_entry))
+ if (volume == NULL && !g_unix_mount_guess_should_display (mount_entry))
return NULL;
mount = g_object_new (G_TYPE_UNIX_MOUNT, NULL);
mount->name = g_unix_mount_guess_name (mount_entry);
mount->icon = g_unix_mount_guess_icon (mount_entry);
+ mount->symbolic_icon = g_unix_mount_guess_symbolic_icon (mount_entry);
/* need to do this last */
mount->volume = volume;
/* TODO: Emit changed in idle to avoid locking issues */
g_signal_emit_by_name (mount, "changed");
if (mount->volume_monitor != NULL)
- g_signal_emit_by_name (mount->volume_monitor, "mount_changed", mount);
+ g_signal_emit_by_name (mount->volume_monitor, "mount-changed", mount);
}
}
return g_object_ref (unix_mount->icon);
}
+static GIcon *
+g_unix_mount_get_symbolic_icon (GMount *mount)
+{
+ GUnixMount *unix_mount = G_UNIX_MOUNT (mount);
+
+ return g_object_ref (unix_mount->symbolic_icon);
+}
+
static char *
g_unix_mount_get_uuid (GMount *mount)
{
return unix_mount->can_eject;
}
-
-typedef struct {
- GUnixMount *unix_mount;
- GAsyncReadyCallback callback;
- gpointer user_data;
- GCancellable *cancellable;
- int error_fd;
- GIOChannel *error_channel;
- guint error_channel_source_id;
- GString *error_string;
-} UnmountEjectOp;
-
-static void
-eject_unmount_cb (GPid pid, gint status, gpointer user_data)
+static void
+eject_unmount_done (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- UnmountEjectOp *data = user_data;
- GSimpleAsyncResult *simple;
-
- if (WEXITSTATUS (status) != 0)
+ GSubprocess *subprocess = G_SUBPROCESS (source);
+ GTask *task = user_data;
+ GError *error = NULL;
+ gchar *stderr_str;
+
+ if (!g_subprocess_communicate_utf8_finish (subprocess, result, NULL, &stderr_str, &error))
{
- GError *error;
- error = g_error_new_literal (G_IO_ERROR,
- G_IO_ERROR_FAILED,
- data->error_string->str);
- simple = g_simple_async_result_new_from_error (G_OBJECT (data->unix_mount),
- data->callback,
- data->user_data,
- error);
+ g_task_return_error (task, error);
g_error_free (error);
}
- else
+ else /* successful communication */
{
- simple = g_simple_async_result_new (G_OBJECT (data->unix_mount),
- data->callback,
- data->user_data,
- NULL);
+ if (!g_subprocess_get_successful (subprocess))
+ /* ...but bad exit code */
+ g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, "%s", stderr_str);
+ else
+ /* ...and successful exit code */
+ g_task_return_boolean (task, TRUE);
+
+ g_free (stderr_str);
}
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
-
- g_source_remove (data->error_channel_source_id);
- g_io_channel_unref (data->error_channel);
- g_string_free (data->error_string, TRUE);
- close (data->error_fd);
- g_spawn_close_pid (pid);
- g_free (data);
+ g_object_unref (task);
}
static gboolean
-eject_unmount_read_error (GIOChannel *channel,
- GIOCondition condition,
- gpointer user_data)
+eject_unmount_do_cb (gpointer user_data)
{
- char *str;
- gsize str_len;
- UnmountEjectOp *data = user_data;
+ GTask *task = user_data;
+ GError *error = NULL;
+ GSubprocess *subprocess;
+ const gchar **argv;
- g_io_channel_read_to_end (channel, &str, &str_len, NULL);
- g_string_append (data->error_string, str);
- g_free (str);
- return TRUE;
+ argv = g_task_get_task_data (task);
+
+ if (g_task_return_error_if_cancelled (task))
+ {
+ g_object_unref (task);
+ return G_SOURCE_REMOVE;
+ }
+
+ subprocess = g_subprocess_newv (argv, G_SUBPROCESS_FLAGS_STDOUT_SILENCE | G_SUBPROCESS_FLAGS_STDERR_PIPE, &error);
+ g_assert_no_error (error);
+
+ g_subprocess_communicate_utf8_async (subprocess, NULL,
+ g_task_get_cancellable (task),
+ eject_unmount_done, task);
+
+ return G_SOURCE_REMOVE;
}
static void
char **argv)
{
GUnixMount *unix_mount = G_UNIX_MOUNT (mount);
- UnmountEjectOp *data;
- GPid child_pid;
- GError *error;
-
- data = g_new0 (UnmountEjectOp, 1);
- data->unix_mount = unix_mount;
- data->callback = callback;
- data->user_data = user_data;
- data->cancellable = cancellable;
-
- error = NULL;
- if (!g_spawn_async_with_pipes (NULL, /* working dir */
- argv,
- NULL, /* envp */
- G_SPAWN_DO_NOT_REAP_CHILD|G_SPAWN_SEARCH_PATH,
- NULL, /* child_setup */
- NULL, /* user_data for child_setup */
- &child_pid,
- NULL, /* standard_input */
- NULL, /* standard_output */
- &(data->error_fd),
- &error)) {
- GSimpleAsyncResult *simple;
- simple = g_simple_async_result_new_from_error (G_OBJECT (data->unix_mount),
- data->callback,
- data->user_data,
- error);
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
- g_error_free (error);
- g_free (data);
- return;
- }
- data->error_string = g_string_new ("");
- data->error_channel = g_io_channel_unix_new (data->error_fd);
- data->error_channel_source_id = g_io_add_watch (data->error_channel, G_IO_IN, eject_unmount_read_error, data);
- g_child_watch_add (child_pid, eject_unmount_cb, data);
+ GTask *task;
+ GSource *timeout;
+
+ task = g_task_new (mount, cancellable, callback, user_data);
+ g_task_set_task_data (task, g_strdupv (argv), (GDestroyNotify) g_strfreev);
+
+ if (unix_mount->volume_monitor != NULL)
+ g_signal_emit_by_name (unix_mount->volume_monitor, "mount-pre-unmount", mount);
+
+ g_signal_emit_by_name (mount, "pre-unmount", 0);
+
+ timeout = g_timeout_source_new (500);
+ g_task_attach_source (task, timeout, (GSourceFunc) eject_unmount_do_cb);
+ g_source_unref (timeout);
}
static void
g_unix_mount_unmount (GMount *mount,
+ GMountUnmountFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
else
argv[1] = unix_mount->device_path;
- return eject_unmount_do (mount, cancellable, callback, user_data, argv);
+ eject_unmount_do (mount, cancellable, callback, user_data, argv);
}
static gboolean
GAsyncResult *result,
GError **error)
{
- return TRUE;
+ return g_task_propagate_boolean (G_TASK (result), error);
}
static void
g_unix_mount_eject (GMount *mount,
+ GMountUnmountFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
else
argv[1] = unix_mount->device_path;
- return eject_unmount_do (mount, cancellable, callback, user_data, argv);
+ eject_unmount_do (mount, cancellable, callback, user_data, argv);
}
static gboolean
GAsyncResult *result,
GError **error)
{
- return TRUE;
+ return g_task_propagate_boolean (G_TASK (result), error);
}
static void
iface->get_root = g_unix_mount_get_root;
iface->get_name = g_unix_mount_get_name;
iface->get_icon = g_unix_mount_get_icon;
+ iface->get_symbolic_icon = g_unix_mount_get_symbolic_icon;
iface->get_uuid = g_unix_mount_get_uuid;
iface->get_drive = g_unix_mount_get_drive;
iface->get_volume = g_unix_mount_get_volume;