mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-09 19:06:15 +01:00
gio-tool: Various fixes related to error messages
This patch contains the following changes: - Print all errors with "gio: " prefix - Print file uri in error for each tool allowing multiple locations - Mark all error messages translatable - Do not leak strings used in error messages - Always start error messages with capital letter - Unify some error messages across various tools - Fix addional/missing new line characters https://bugzilla.gnome.org/show_bug.cgi?id=776169
This commit is contained in:
parent
a83ccc535f
commit
0beeeb2ec9
@ -77,7 +77,7 @@ cat (GFile *file)
|
||||
|
||||
if (written == -1 && errno != EINTR)
|
||||
{
|
||||
print_file_error (file, "error writing to stdout");
|
||||
print_file_error (file, _("Error writing to stdout"));
|
||||
success = FALSE;
|
||||
goto out;
|
||||
}
|
||||
@ -148,7 +148,7 @@ handle_cat (int argc, char *argv[], gboolean do_help)
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
show_help (context, _("No files given"));
|
||||
show_help (context, _("No locations given"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,7 @@ query_info (GFile *file)
|
||||
|
||||
if (info == NULL)
|
||||
{
|
||||
g_printerr ("Error getting info: %s\n", error->message);
|
||||
print_file_error (file, error->message);
|
||||
g_error_free (error);
|
||||
return FALSE;
|
||||
}
|
||||
@ -218,7 +218,7 @@ get_writable_info (GFile *file)
|
||||
list = g_file_query_settable_attributes (file, NULL, &error);
|
||||
if (list == NULL)
|
||||
{
|
||||
g_printerr (_("Error getting writable attributes: %s\n"), error->message);
|
||||
print_file_error (file, error->message);
|
||||
g_error_free (error);
|
||||
return FALSE;
|
||||
}
|
||||
@ -239,7 +239,7 @@ get_writable_info (GFile *file)
|
||||
list = g_file_query_writable_namespaces (file, NULL, &error);
|
||||
if (list == NULL)
|
||||
{
|
||||
g_printerr ("Error getting writable namespaces: %s\n", error->message);
|
||||
print_file_error (file, error->message);
|
||||
g_error_free (error);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -156,14 +156,14 @@ handle_mime (int argc, char *argv[], gboolean do_help)
|
||||
info = get_app_info_for_id (handler);
|
||||
if (info == NULL)
|
||||
{
|
||||
g_printerr (_("Failed to load info for handler “%s”\n"), handler);
|
||||
print_error (_("Failed to load info for handler “%s”"), handler);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (g_app_info_set_as_default_for_type (info, mimetype, &error) == FALSE)
|
||||
{
|
||||
g_printerr (_("Failed to set “%s” as the default handler for “%s”: %s\n"),
|
||||
handler, mimetype, error->message);
|
||||
print_error (_("Failed to set “%s” as the default handler for “%s”: %s\n"),
|
||||
handler, mimetype, error->message);
|
||||
g_error_free (error);
|
||||
g_object_unref (info);
|
||||
return 1;
|
||||
|
@ -180,7 +180,7 @@ add_watch (const gchar *cmdline,
|
||||
return TRUE;
|
||||
|
||||
err:
|
||||
g_printerr ("error: %s: %s", cmdline, error->message);
|
||||
print_file_error (file, error->message);
|
||||
g_error_free (error);
|
||||
|
||||
return FALSE;
|
||||
@ -193,7 +193,6 @@ handle_monitor (int argc, gchar *argv[], gboolean do_help)
|
||||
gchar *param;
|
||||
GError *error = NULL;
|
||||
GFileMonitorFlags flags;
|
||||
guint total = 0;
|
||||
guint i;
|
||||
|
||||
g_set_prgname ("gio monitor");
|
||||
@ -220,6 +219,12 @@ handle_monitor (int argc, gchar *argv[], gboolean do_help)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!watch_dirs || !watch_files || !watch_direct || !watch_silent || !watch_default)
|
||||
{
|
||||
show_help (context, _("No locations given"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_option_context_free (context);
|
||||
|
||||
flags = (no_moves ? 0 : G_FILE_MONITOR_WATCH_MOVES) |
|
||||
@ -230,7 +235,6 @@ handle_monitor (int argc, gchar *argv[], gboolean do_help)
|
||||
for (i = 0; watch_dirs[i]; i++)
|
||||
if (!add_watch (watch_dirs[i], WATCH_DIR, flags, TRUE))
|
||||
return 1;
|
||||
total++;
|
||||
}
|
||||
|
||||
if (watch_files)
|
||||
@ -238,7 +242,6 @@ handle_monitor (int argc, gchar *argv[], gboolean do_help)
|
||||
for (i = 0; watch_files[i]; i++)
|
||||
if (!add_watch (watch_files[i], WATCH_FILE, flags, TRUE))
|
||||
return 1;
|
||||
total++;
|
||||
}
|
||||
|
||||
if (watch_direct)
|
||||
@ -246,7 +249,6 @@ handle_monitor (int argc, gchar *argv[], gboolean do_help)
|
||||
for (i = 0; watch_direct[i]; i++)
|
||||
if (!add_watch (watch_direct[i], WATCH_FILE, flags | G_FILE_MONITOR_WATCH_HARD_LINKS, TRUE))
|
||||
return 1;
|
||||
total++;
|
||||
}
|
||||
|
||||
if (watch_silent)
|
||||
@ -254,7 +256,6 @@ handle_monitor (int argc, gchar *argv[], gboolean do_help)
|
||||
for (i = 0; watch_silent[i]; i++)
|
||||
if (!add_watch (watch_silent[i], WATCH_FILE, flags | G_FILE_MONITOR_WATCH_HARD_LINKS, FALSE))
|
||||
return 1;
|
||||
total++;
|
||||
}
|
||||
|
||||
if (watch_default)
|
||||
@ -262,13 +263,6 @@ handle_monitor (int argc, gchar *argv[], gboolean do_help)
|
||||
for (i = 0; watch_default[i]; i++)
|
||||
if (!add_watch (watch_default[i], WATCH_AUTO, flags, TRUE))
|
||||
return 1;
|
||||
total++;
|
||||
}
|
||||
|
||||
if (!total)
|
||||
{
|
||||
g_printerr ("gio: Must give at least one file to monitor\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (TRUE)
|
||||
|
@ -243,9 +243,9 @@ mount_mountable_done_cb (GObject *object,
|
||||
{
|
||||
success = FALSE;
|
||||
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ABORTED)
|
||||
g_printerr (_("Error mounting location: Anonymous access denied\n"));
|
||||
print_file_error (G_FILE (object), _("Anonymous access denied"));
|
||||
else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED))
|
||||
g_printerr (_("Error mounting location: %s\n"), error->message);
|
||||
print_file_error (G_FILE (object), error->message);
|
||||
|
||||
g_error_free (error);
|
||||
}
|
||||
@ -273,9 +273,9 @@ mount_done_cb (GObject *object,
|
||||
{
|
||||
success = FALSE;
|
||||
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ABORTED)
|
||||
g_printerr (_("Error mounting location: Anonymous access denied\n"));
|
||||
print_file_error (G_FILE (object), _("Anonymous access denied"));
|
||||
else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED))
|
||||
g_printerr (_("Error mounting location: %s\n"), error->message);
|
||||
print_file_error (G_FILE (object), error->message);
|
||||
|
||||
g_error_free (error);
|
||||
}
|
||||
@ -331,6 +331,7 @@ unmount_done_cb (GObject *object,
|
||||
{
|
||||
gboolean succeeded;
|
||||
GError *error = NULL;
|
||||
GFile *file = G_FILE (user_data);
|
||||
|
||||
succeeded = g_mount_unmount_with_operation_finish (G_MOUNT (object), res, &error);
|
||||
|
||||
@ -338,11 +339,13 @@ unmount_done_cb (GObject *object,
|
||||
|
||||
if (!succeeded)
|
||||
{
|
||||
g_printerr (_("Error unmounting mount: %s\n"), error->message);
|
||||
print_file_error (file, error->message);
|
||||
success = FALSE;
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_object_unref (file);
|
||||
|
||||
outstanding_mounts--;
|
||||
|
||||
if (outstanding_mounts == 0)
|
||||
@ -363,7 +366,7 @@ unmount (GFile *file)
|
||||
mount = g_file_find_enclosing_mount (file, NULL, &error);
|
||||
if (mount == NULL)
|
||||
{
|
||||
g_printerr (_("Error finding enclosing mount: %s\n"), error->message);
|
||||
print_file_error (file, error->message);
|
||||
success = FALSE;
|
||||
g_error_free (error);
|
||||
return;
|
||||
@ -371,7 +374,7 @@ unmount (GFile *file)
|
||||
|
||||
mount_op = new_mount_op ();
|
||||
flags = force ? G_MOUNT_UNMOUNT_FORCE : G_MOUNT_UNMOUNT_NONE;
|
||||
g_mount_unmount_with_operation (mount, flags, mount_op, NULL, unmount_done_cb, NULL);
|
||||
g_mount_unmount_with_operation (mount, flags, mount_op, NULL, unmount_done_cb, g_object_ref (file));
|
||||
g_object_unref (mount_op);
|
||||
|
||||
outstanding_mounts++;
|
||||
@ -384,6 +387,7 @@ eject_done_cb (GObject *object,
|
||||
{
|
||||
gboolean succeeded;
|
||||
GError *error = NULL;
|
||||
GFile *file = G_FILE (user_data);
|
||||
|
||||
succeeded = g_mount_eject_with_operation_finish (G_MOUNT (object), res, &error);
|
||||
|
||||
@ -391,11 +395,13 @@ eject_done_cb (GObject *object,
|
||||
|
||||
if (!succeeded)
|
||||
{
|
||||
g_printerr (_("Error ejecting mount: %s\n"), error->message);
|
||||
print_file_error (file, error->message);
|
||||
success = FALSE;
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_object_unref (file);
|
||||
|
||||
outstanding_mounts--;
|
||||
|
||||
if (outstanding_mounts == 0)
|
||||
@ -416,7 +422,7 @@ eject (GFile *file)
|
||||
mount = g_file_find_enclosing_mount (file, NULL, &error);
|
||||
if (mount == NULL)
|
||||
{
|
||||
g_printerr (_("Error finding enclosing mount: %s\n"), error->message);
|
||||
print_file_error (file, error->message);
|
||||
success = FALSE;
|
||||
g_error_free (error);
|
||||
return;
|
||||
@ -424,7 +430,7 @@ eject (GFile *file)
|
||||
|
||||
mount_op = new_mount_op ();
|
||||
flags = force ? G_MOUNT_UNMOUNT_FORCE : G_MOUNT_UNMOUNT_NONE;
|
||||
g_mount_eject_with_operation (mount, flags, mount_op, NULL, eject_done_cb, NULL);
|
||||
g_mount_eject_with_operation (mount, flags, mount_op, NULL, eject_done_cb, g_object_ref (file));
|
||||
g_object_unref (mount_op);
|
||||
|
||||
outstanding_mounts++;
|
||||
@ -865,6 +871,7 @@ mount_with_device_file_cb (GObject *object,
|
||||
GVolume *volume;
|
||||
gboolean succeeded;
|
||||
GError *error = NULL;
|
||||
gchar *device_path = (gchar *)user_data;
|
||||
|
||||
volume = G_VOLUME (object);
|
||||
|
||||
@ -872,9 +879,7 @@ mount_with_device_file_cb (GObject *object,
|
||||
|
||||
if (!succeeded)
|
||||
{
|
||||
g_printerr (_("Error mounting %s: %s\n"),
|
||||
g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE),
|
||||
error->message);
|
||||
print_error ("%s: %s", device_path, error->message);
|
||||
g_error_free (error);
|
||||
success = FALSE;
|
||||
}
|
||||
@ -888,15 +893,15 @@ mount_with_device_file_cb (GObject *object,
|
||||
root = g_mount_get_root (mount);
|
||||
mount_path = g_file_get_path (root);
|
||||
|
||||
g_print (_("Mounted %s at %s\n"),
|
||||
g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE),
|
||||
mount_path);
|
||||
g_print (_("Mounted %s at %s\n"), device_path, mount_path);
|
||||
|
||||
g_object_unref (mount);
|
||||
g_object_unref (root);
|
||||
g_free (mount_path);
|
||||
}
|
||||
|
||||
g_free (device_path);
|
||||
|
||||
outstanding_mounts--;
|
||||
|
||||
if (outstanding_mounts == 0)
|
||||
@ -916,9 +921,10 @@ mount_with_device_file (const char *device_file)
|
||||
for (l = volumes; l != NULL; l = l->next)
|
||||
{
|
||||
GVolume *volume = G_VOLUME (l->data);
|
||||
gchar *id;
|
||||
|
||||
if (g_strcmp0 (g_volume_get_identifier (volume,
|
||||
G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE), device_file) == 0)
|
||||
id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
|
||||
if (g_strcmp0 (id, device_file) == 0)
|
||||
{
|
||||
GMountOperation *op;
|
||||
|
||||
@ -929,16 +935,18 @@ mount_with_device_file (const char *device_file)
|
||||
op,
|
||||
NULL,
|
||||
mount_with_device_file_cb,
|
||||
op);
|
||||
id);
|
||||
|
||||
outstanding_mounts++;
|
||||
}
|
||||
else
|
||||
g_free (id);
|
||||
}
|
||||
g_list_free_full (volumes, g_object_unref);
|
||||
|
||||
if (outstanding_mounts == 0)
|
||||
{
|
||||
g_print (_("No volume for device file %s\n"), device_file);
|
||||
g_print ("%s: %s\n", device_file, _("No volume for device file"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ handle_open (int argc, char *argv[], gboolean do_help)
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
show_help (context, _("No files to open"));
|
||||
show_help (context, _("No locations given"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ handle_remove (int argc, char *argv[], gboolean do_help)
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
show_help (context, _("No files to delete"));
|
||||
show_help (context, _("No locations given"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ handle_rename (int argc, char *argv[], gboolean do_help)
|
||||
|
||||
if (new_file == NULL)
|
||||
{
|
||||
g_printerr (_("Error: %s\n"), error->message);
|
||||
print_error (error->message);
|
||||
g_error_free (error);
|
||||
retval = 1;
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ save (GFile *file)
|
||||
if (written == -1)
|
||||
{
|
||||
save_res = FALSE;
|
||||
g_printerr ("gio: Error writing to stream: %s\n", error->message);
|
||||
print_error (error->message);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
@ -116,7 +116,7 @@ save (GFile *file)
|
||||
else if (res < 0)
|
||||
{
|
||||
save_res = FALSE;
|
||||
g_printerr ("gio: Error reading from standard input\n");
|
||||
print_error (_("Error reading from standard input"));
|
||||
break;
|
||||
}
|
||||
else if (res == 0)
|
||||
@ -129,7 +129,7 @@ save (GFile *file)
|
||||
if (!close_res)
|
||||
{
|
||||
save_res = FALSE;
|
||||
g_printerr ("gio: Error closing: %s\n", error->message);
|
||||
print_error (error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ handle_set (int argc, char *argv[], gboolean do_help)
|
||||
break;
|
||||
case G_FILE_ATTRIBUTE_TYPE_OBJECT:
|
||||
default:
|
||||
g_printerr (_("Invalid attribute type %s\n"), attr_type);
|
||||
print_error (_("Invalid attribute type “%s“"), attr_type);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ handle_set (int argc, char *argv[], gboolean do_help)
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
NULL, &error))
|
||||
{
|
||||
g_printerr (_("Error setting attribute: %s\n"), error->message);
|
||||
print_error (error->message);
|
||||
g_error_free (error);
|
||||
return 1;
|
||||
}
|
||||
|
@ -31,9 +31,35 @@
|
||||
|
||||
|
||||
void
|
||||
print_file_error (GFile *file, const char *message)
|
||||
print_error (const char *format, ...)
|
||||
{
|
||||
g_printerr ("gio: %s: %s\n", g_file_get_uri (file), message);
|
||||
gchar *message;
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
message = g_strdup_vprintf (format, args);
|
||||
va_end (args);
|
||||
|
||||
g_printerr ("gio: %s\n", message);
|
||||
g_free (message);
|
||||
}
|
||||
|
||||
void
|
||||
print_file_error (GFile *file, const gchar *format, ...)
|
||||
{
|
||||
gchar *uri;
|
||||
gchar *message;
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
message = g_strdup_vprintf (format, args);
|
||||
va_end (args);
|
||||
|
||||
uri = g_file_get_uri (file);
|
||||
print_error ("%s: %s", uri, message);
|
||||
g_free (uri);
|
||||
|
||||
g_free (message);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -20,8 +20,11 @@
|
||||
#ifndef __GIO_TOOL_H__
|
||||
#define __GIO_TOOL_H__
|
||||
|
||||
void print_error (const gchar *format,
|
||||
...);
|
||||
void print_file_error (GFile *file,
|
||||
const char *message);
|
||||
const gchar *format,
|
||||
...);
|
||||
void show_help (GOptionContext *context,
|
||||
const char *message);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user