Make working with GError in more right way (like with exceptions).

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2014-07-15 15:53:06 +03:00 committed by Andrew Borodin
parent a8d46f29d3
commit 512ad7d962
35 changed files with 624 additions and 492 deletions

View File

@ -27,6 +27,7 @@
#include <config.h> #include <config.h>
#include "lib/global.h" #include "lib/global.h"
#include "lib/util.h"
#include "lib/event.h" #include "lib/event.h"
#include "internal.h" #include "internal.h"
@ -49,10 +50,11 @@ GTree *mc_event_grouplist = NULL;
gboolean gboolean
mc_event_init (GError ** mcerror) mc_event_init (GError ** mcerror)
{ {
mc_return_val_if_error (mcerror, FALSE);
if (mc_event_grouplist != NULL) if (mc_event_grouplist != NULL)
{ {
g_propagate_error (mcerror, mc_propagate_error (mcerror, 1, "%s", _("Event system already initialized"));
g_error_new (MC_ERROR, 1, _("Event system already initialized")));
return FALSE; return FALSE;
} }
@ -62,8 +64,7 @@ mc_event_init (GError ** mcerror)
if (mc_event_grouplist == NULL) if (mc_event_grouplist == NULL)
{ {
g_propagate_error (mcerror, mc_propagate_error (mcerror, 2, "%s", _("Failed to initialize event system"));
g_error_new (MC_ERROR, 2, _("Failed to initialize event system")));
return FALSE; return FALSE;
} }
@ -75,9 +76,11 @@ mc_event_init (GError ** mcerror)
gboolean gboolean
mc_event_deinit (GError ** mcerror) mc_event_deinit (GError ** mcerror)
{ {
mc_return_val_if_error (mcerror, FALSE);
if (mc_event_grouplist == NULL) if (mc_event_grouplist == NULL)
{ {
g_propagate_error (mcerror, g_error_new (MC_ERROR, 1, _("Event system not initialized"))); mc_propagate_error (mcerror, 3, "%s", _("Event system not initialized"));
return FALSE; return FALSE;
} }
@ -93,6 +96,8 @@ mc_event_mass_add (event_init_t * events, GError ** mcerror)
{ {
size_t array_index; size_t array_index;
mc_return_val_if_error (mcerror, FALSE);
for (array_index = 0; events[array_index].event_group_name != NULL; array_index++) for (array_index = 0; events[array_index].event_group_name != NULL; array_index++)
{ {
if (!mc_event_add (events[array_index].event_group_name, if (!mc_event_add (events[array_index].event_group_name,

View File

@ -27,6 +27,7 @@
#include <config.h> #include <config.h>
#include "lib/global.h" #include "lib/global.h"
#include "lib/util.h"
#include "lib/event.h" #include "lib/event.h"
#include "internal.h" #include "internal.h"
@ -68,12 +69,12 @@ mc_event_add (const gchar * event_group_name, const gchar * event_name,
GPtrArray *callbacks; GPtrArray *callbacks;
mc_event_callback_t *cb; mc_event_callback_t *cb;
mc_return_val_if_error (mcerror, FALSE);
if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL
|| event_callback == NULL) || event_callback == NULL)
{ {
g_propagate_error (mcerror, mc_propagate_error (mcerror, 1, "%s", _("Check input data! Some of parameters are NULL!"));
g_error_new (MC_ERROR, 1,
_("Check input data! Some of parameters are NULL!")));
return FALSE; return FALSE;
} }
@ -159,6 +160,8 @@ mc_event_get_event_group_by_name (const gchar * event_group_name, gboolean creat
{ {
GTree *event_group; GTree *event_group;
mc_return_val_if_error (mcerror, FALSE);
event_group = (GTree *) g_tree_lookup (mc_event_grouplist, (gconstpointer) event_group_name); event_group = (GTree *) g_tree_lookup (mc_event_grouplist, (gconstpointer) event_group_name);
if (event_group == NULL && create_new) if (event_group == NULL && create_new)
{ {
@ -169,10 +172,8 @@ mc_event_get_event_group_by_name (const gchar * event_group_name, gboolean creat
(GDestroyNotify) mc_event_group_destroy_value); (GDestroyNotify) mc_event_group_destroy_value);
if (event_group == NULL) if (event_group == NULL)
{ {
g_propagate_error (mcerror, mc_propagate_error (mcerror, 1, _("Unable to create group '%s' for events!"),
g_error_new (MC_ERROR, 1, event_group_name);
_("Unable to create group '%s' for events!"),
event_group_name));
return NULL; return NULL;
} }
g_tree_insert (mc_event_grouplist, g_strdup (event_group_name), (gpointer) event_group); g_tree_insert (mc_event_grouplist, g_strdup (event_group_name), (gpointer) event_group);
@ -188,15 +189,15 @@ mc_event_get_event_by_name (GTree * event_group, const gchar * event_name, gbool
{ {
GPtrArray *callbacks; GPtrArray *callbacks;
mc_return_val_if_error (mcerror, FALSE);
callbacks = (GPtrArray *) g_tree_lookup (event_group, (gconstpointer) event_name); callbacks = (GPtrArray *) g_tree_lookup (event_group, (gconstpointer) event_name);
if (callbacks == NULL && create_new) if (callbacks == NULL && create_new)
{ {
callbacks = g_ptr_array_new (); callbacks = g_ptr_array_new ();
if (callbacks == NULL) if (callbacks == NULL)
{ {
g_propagate_error (mcerror, mc_propagate_error (mcerror, 1, _("Unable to create event '%s'!"), event_name);
g_error_new (MC_ERROR, 1,
_("Unable to create event '%s'!"), event_name));
return NULL; return NULL;
} }
g_tree_insert (event_group, g_strdup (event_name), (gpointer) callbacks); g_tree_insert (event_group, g_strdup (event_name), (gpointer) callbacks);

View File

@ -137,3 +137,32 @@ g_list_free_full (GList * list, GDestroyNotify free_func)
#endif /* ! GLIB_CHECK_VERSION (2, 28, 0) */ #endif /* ! GLIB_CHECK_VERSION (2, 28, 0) */
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
#if ! GLIB_CHECK_VERSION (2, 22, 0)
/**
* Creates a new GError with the given domain and code, and a message formatted with format.
* @param domain error domain
* @param code error code
* @param format printf()-style format for error message
* @param args va_list of parameters for the message format
* @returns a new GError
*/
GError *
g_error_new_valist (GQuark domain, gint code, const gchar * format, va_list args)
{
char *message;
GError *ret_value;
va_start (ap, format);
message = g_strdup_vprintf (format, ap);
va_end (ap);
ret_value = g_error_new_literal (domain, code, message);
g_free (message);
return ret_value;
}
#endif /* ! GLIB_CHECK_VERSION (2, 22, 0) */
/* --------------------------------------------------------------------------------------------- */

View File

@ -48,7 +48,7 @@ mc_config_t *mc_panels_config;
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
static gboolean static gboolean
mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path, GError ** error) mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path, GError ** mcerror)
{ {
gchar *data, *written_data; gchar *data, *written_data;
gsize len, total_written; gsize len, total_written;
@ -57,10 +57,12 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path,
ssize_t cur_written; ssize_t cur_written;
vfs_path_t *ini_vpath; vfs_path_t *ini_vpath;
mc_return_val_if_error (mcerror, FALSE);
data = g_key_file_to_data (mc_config->handle, &len, NULL); data = g_key_file_to_data (mc_config->handle, &len, NULL);
if (!exist_file (ini_path)) if (!exist_file (ini_path))
{ {
ret = g_file_set_contents (ini_path, data, len, error); ret = g_file_set_contents (ini_path, data, len, mcerror);
g_free (data); g_free (data);
return ret; return ret;
} }
@ -73,7 +75,7 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path,
if (fd == -1) if (fd == -1)
{ {
g_propagate_error (error, g_error_new (MC_ERROR, 0, "%s", unix_error_string (errno))); mc_propagate_error (mcerror, 0, "%s", unix_error_string (errno));
g_free (data); g_free (data);
return FALSE; return FALSE;
} }
@ -88,7 +90,7 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path,
if (cur_written == -1) if (cur_written == -1)
{ {
mc_util_restore_from_backup_if_possible (ini_path, "~"); mc_util_restore_from_backup_if_possible (ini_path, "~");
g_propagate_error (error, g_error_new (MC_ERROR, 0, "%s", unix_error_string (errno))); mc_propagate_error (mcerror, 0, "%s", unix_error_string (errno));
return FALSE; return FALSE;
} }
@ -261,25 +263,27 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean r
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean gboolean
mc_config_save_file (mc_config_t * mc_config, GError ** error) mc_config_save_file (mc_config_t * mc_config, GError ** mcerror)
{ {
mc_return_val_if_error (mcerror, FALSE);
if (mc_config == NULL || mc_config->ini_path == NULL) if (mc_config == NULL || mc_config->ini_path == NULL)
{
return FALSE; return FALSE;
}
return mc_config_new_or_override_file (mc_config, mc_config->ini_path, error); return mc_config_new_or_override_file (mc_config, mc_config->ini_path, mcerror);
} }
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean gboolean
mc_config_save_to_file (mc_config_t * mc_config, const gchar * ini_path, GError ** error) mc_config_save_to_file (mc_config_t * mc_config, const gchar * ini_path, GError ** mcerror)
{ {
mc_return_val_if_error (mcerror, FALSE);
if (mc_config == NULL) if (mc_config == NULL)
{
return FALSE; return FALSE;
}
return mc_config_new_or_override_file (mc_config, ini_path, error); return mc_config_new_or_override_file (mc_config, ini_path, mcerror);
} }

View File

@ -134,26 +134,25 @@ static const struct
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static void static void
mc_config_mkdir (const char *directory_name, GError ** error) mc_config_mkdir (const char *directory_name, GError ** mcerror)
{ {
mc_return_if_error (mcerror);
if ((!g_file_test (directory_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) && if ((!g_file_test (directory_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) &&
(g_mkdir_with_parents (directory_name, 0700) != 0)) (g_mkdir_with_parents (directory_name, 0700) != 0))
{ mc_propagate_error (mcerror, 0, _("Cannot create %s directory"), directory_name);
g_propagate_error (error,
g_error_new (MC_ERROR, 0, _("Cannot create %s directory"),
directory_name));
}
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static char * static char *
mc_config_init_one_config_path (const char *path_base, const char *subdir, GError ** error) mc_config_init_one_config_path (const char *path_base, const char *subdir, GError ** mcerror)
{ {
char *full_path; char *full_path;
full_path = g_build_filename (path_base, subdir, NULL); mc_return_val_if_error (mcerror, FALSE);
full_path = g_build_filename (path_base, subdir, NULL);
if (g_file_test (full_path, G_FILE_TEST_EXISTS)) if (g_file_test (full_path, G_FILE_TEST_EXISTS))
{ {
if (g_file_test (full_path, G_FILE_TEST_IS_DIR)) if (g_file_test (full_path, G_FILE_TEST_IS_DIR))
@ -167,8 +166,8 @@ mc_config_init_one_config_path (const char *path_base, const char *subdir, GErro
} }
} }
mc_config_mkdir (full_path, error); mc_config_mkdir (full_path, mcerror);
if (error != NULL && *error != NULL) if (mcerror != NULL && *mcerror != NULL)
{ {
g_free (full_path); g_free (full_path);
full_path = NULL; full_path = NULL;
@ -187,15 +186,17 @@ mc_config_get_deprecated_path (void)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static void static void
mc_config_copy (const char *old_name, const char *new_name, GError ** error) mc_config_copy (const char *old_name, const char *new_name, GError ** mcerror)
{ {
mc_return_if_error (mcerror);
if (g_file_test (old_name, G_FILE_TEST_IS_REGULAR)) if (g_file_test (old_name, G_FILE_TEST_IS_REGULAR))
{ {
char *contents = NULL; char *contents = NULL;
size_t length; size_t length;
if (g_file_get_contents (old_name, &contents, &length, error)) if (g_file_get_contents (old_name, &contents, &length, mcerror))
g_file_set_contents (new_name, contents, length, error); g_file_set_contents (new_name, contents, length, mcerror);
g_free (contents); g_free (contents);
return; return;
@ -207,18 +208,16 @@ mc_config_copy (const char *old_name, const char *new_name, GError ** error)
GDir *dir; GDir *dir;
const char *dir_name; const char *dir_name;
dir = g_dir_open (old_name, 0, error); dir = g_dir_open (old_name, 0, mcerror);
if (dir == NULL) if (dir == NULL)
return; return;
if (g_mkdir_with_parents (new_name, 0700) == -1) if (g_mkdir_with_parents (new_name, 0700) == -1)
{ {
g_dir_close (dir); g_dir_close (dir);
g_propagate_error (error, mc_propagate_error (mcerror, 0,
g_error_new (MC_ERROR, 0, _("An error occurred while migrating user settings: %s"),
_ unix_error_string (errno));
("An error occurred while migrating user settings: %s"),
unix_error_string (errno)));
return; return;
} }
@ -228,7 +227,7 @@ mc_config_copy (const char *old_name, const char *new_name, GError ** error)
old_name2 = g_build_filename (old_name, dir_name, NULL); old_name2 = g_build_filename (old_name, dir_name, NULL);
new_name2 = g_build_filename (new_name, dir_name, NULL); new_name2 = g_build_filename (new_name, dir_name, NULL);
mc_config_copy (old_name2, new_name2, error); mc_config_copy (old_name2, new_name2, mcerror);
g_free (new_name2); g_free (new_name2);
g_free (old_name2); g_free (old_name2);
} }
@ -286,10 +285,12 @@ mc_config_deprecated_dir_present (void)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
void void
mc_config_init_config_paths (GError ** error) mc_config_init_config_paths (GError ** mcerror)
{ {
char *dir; char *dir;
mc_return_if_error (mcerror);
if (xdg_vars_initialized) if (xdg_vars_initialized)
return; return;
@ -300,46 +301,46 @@ mc_config_init_config_paths (GError ** error)
if (mc_home != NULL) if (mc_home != NULL)
{ {
dir = g_build_filename (mc_home, ".config", (char *) NULL); dir = g_build_filename (mc_home, ".config", (char *) NULL);
mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, error); mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
g_free (dir); g_free (dir);
dir = g_build_filename (mc_home, ".cache", (char *) NULL); dir = g_build_filename (mc_home, ".cache", (char *) NULL);
mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, error); mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
g_free (dir); g_free (dir);
dir = g_build_filename (mc_home, ".local", "share", (char *) NULL); dir = g_build_filename (mc_home, ".local", "share", (char *) NULL);
mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, error); mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
g_free (dir); g_free (dir);
} }
else else
{ {
dir = (char *) g_get_user_config_dir (); dir = (char *) g_get_user_config_dir ();
if (dir != NULL && *dir != '\0') if (dir != NULL && *dir != '\0')
mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, error); mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
else else
{ {
dir = g_build_filename (homedir, ".config", (char *) NULL); dir = g_build_filename (homedir, ".config", (char *) NULL);
mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, error); mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
g_free (dir); g_free (dir);
} }
dir = (char *) g_get_user_cache_dir (); dir = (char *) g_get_user_cache_dir ();
if (dir != NULL && *dir != '\0') if (dir != NULL && *dir != '\0')
mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, error); mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
else else
{ {
dir = g_build_filename (homedir, ".cache", (char *) NULL); dir = g_build_filename (homedir, ".cache", (char *) NULL);
mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, error); mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
g_free (dir); g_free (dir);
} }
dir = (char *) g_get_user_data_dir (); dir = (char *) g_get_user_data_dir ();
if (dir != NULL && *dir != '\0') if (dir != NULL && *dir != '\0')
mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, error); mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
else else
{ {
dir = g_build_filename (homedir, ".local", "share", (char *) NULL); dir = g_build_filename (homedir, ".local", "share", (char *) NULL);
mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, error); mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, mcerror);
g_free (dir); g_free (dir);
} }
} }
@ -357,7 +358,7 @@ mc_config_init_config_paths (GError ** error)
dir = g_build_filename (mc_config_get_home_dir (), MC_USERCONF_DIR, (char *) NULL); dir = g_build_filename (mc_config_get_home_dir (), MC_USERCONF_DIR, (char *) NULL);
} }
mc_data_str = mc_cache_str = mc_config_str = mc_config_init_one_config_path (dir, "", error); mc_data_str = mc_cache_str = mc_config_str = mc_config_init_one_config_path (dir, "", mcerror);
g_free (dir); g_free (dir);
#endif /* MC_HOMEDIR_XDG */ #endif /* MC_HOMEDIR_XDG */
@ -439,24 +440,25 @@ mc_config_get_path (void)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
gboolean gboolean
mc_config_migrate_from_old_place (GError ** error, char **msg) mc_config_migrate_from_old_place (GError ** mcerror, char **msg)
{ {
char *old_dir; char *old_dir;
size_t rule_index; size_t rule_index;
mc_return_val_if_error (mcerror, FALSE);
if (!mc_config_deprecated_dir_present ()) if (!mc_config_deprecated_dir_present ())
return FALSE; return FALSE;
old_dir = mc_config_get_deprecated_path (); old_dir = mc_config_get_deprecated_path ();
g_free (mc_config_init_one_config_path (mc_config_str, EDIT_DIR, error)); g_free (mc_config_init_one_config_path (mc_config_str, EDIT_DIR, mcerror));
#ifdef MC_HOMEDIR_XDG #ifdef MC_HOMEDIR_XDG
g_free (mc_config_init_one_config_path (mc_cache_str, EDIT_DIR, error)); g_free (mc_config_init_one_config_path (mc_cache_str, EDIT_DIR, mcerror));
g_free (mc_config_init_one_config_path (mc_data_str, EDIT_DIR, error)); g_free (mc_config_init_one_config_path (mc_data_str, EDIT_DIR, mcerror));
#endif /* MC_HOMEDIR_XDG */ #endif /* MC_HOMEDIR_XDG */
if (*error != NULL) mc_return_val_if_error (mcerror, FALSE);
return FALSE;
for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++) for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++)
{ {
@ -474,7 +476,7 @@ mc_config_migrate_from_old_place (GError ** error, char **msg)
const char *filename = mc_config_files_reference[rule_index].new_filename; const char *filename = mc_config_files_reference[rule_index].new_filename;
new_name = g_build_filename (basedir, filename, NULL); new_name = g_build_filename (basedir, filename, NULL);
mc_config_copy (old_name, new_name, error); mc_config_copy (old_name, new_name, mcerror);
g_free (new_name); g_free (new_name);
} }
g_free (old_name); g_free (old_name);

View File

@ -253,19 +253,19 @@ mc_search__regex_found_cond_one (mc_search_t * lc_mc_search, mc_search_regex_t *
GString * search_str) GString * search_str)
{ {
#ifdef SEARCH_TYPE_GLIB #ifdef SEARCH_TYPE_GLIB
GError *error = NULL; GError *mcerror = NULL;
if (!g_regex_match_full (regex, search_str->str, search_str->len, 0, G_REGEX_MATCH_NEWLINE_ANY, if (!g_regex_match_full (regex, search_str->str, search_str->len, 0, G_REGEX_MATCH_NEWLINE_ANY,
&lc_mc_search->regex_match_info, &error)) &lc_mc_search->regex_match_info, &mcerror))
{ {
g_match_info_free (lc_mc_search->regex_match_info); g_match_info_free (lc_mc_search->regex_match_info);
lc_mc_search->regex_match_info = NULL; lc_mc_search->regex_match_info = NULL;
if (error) if (mcerror != NULL)
{ {
lc_mc_search->error = MC_SEARCH_E_REGEX; lc_mc_search->error = MC_SEARCH_E_REGEX;
lc_mc_search->error_str = lc_mc_search->error_str =
str_conv_gerror_message (error, _("Regular expression error")); str_conv_gerror_message (mcerror, _("Regular expression error"));
g_error_free (error); g_error_free (mcerror);
return COND__FOUND_ERROR; return COND__FOUND_ERROR;
} }
return COND__NOT_FOUND; return COND__NOT_FOUND;
@ -712,7 +712,7 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_
mc_search_cond_t * mc_search_cond) mc_search_cond_t * mc_search_cond)
{ {
#ifdef SEARCH_TYPE_GLIB #ifdef SEARCH_TYPE_GLIB
GError *error = NULL; GError *mcerror = NULL;
if (!lc_mc_search->is_case_sensitive) if (!lc_mc_search->is_case_sensitive)
{ {
@ -724,13 +724,13 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_
} }
mc_search_cond->regex_handle = mc_search_cond->regex_handle =
g_regex_new (mc_search_cond->str->str, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_DOTALL, g_regex_new (mc_search_cond->str->str, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_DOTALL,
0, &error); 0, &mcerror);
if (error != NULL) if (mcerror != NULL)
{ {
lc_mc_search->error = MC_SEARCH_E_REGEX_COMPILE; lc_mc_search->error = MC_SEARCH_E_REGEX_COMPILE;
lc_mc_search->error_str = str_conv_gerror_message (error, _("Regular expression error")); lc_mc_search->error_str = str_conv_gerror_message (mcerror, _("Regular expression error"));
g_error_free (error); g_error_free (mcerror);
return; return;
} }
#else /* SEARCH_TYPE_GLIB */ #else /* SEARCH_TYPE_GLIB */

View File

@ -319,7 +319,7 @@ mc_skin_color_parse_ini_file (mc_skin_t * mc_skin)
tty_color_set_defaults (mc_skin_color->fgcolor, mc_skin_color->bgcolor, mc_skin_color->attrs); tty_color_set_defaults (mc_skin_color->fgcolor, mc_skin_color->bgcolor, mc_skin_color->attrs);
mc_skin_color_add_to_hash (mc_skin, "core", "_default_", mc_skin_color); mc_skin_color_add_to_hash (mc_skin, "core", "_default_", mc_skin_color);
for (groups = orig_groups ; *groups != NULL; groups++) for (groups = orig_groups; *groups != NULL; groups++)
{ {
gchar **keys, **orig_keys; gchar **keys, **orig_keys;

View File

@ -29,6 +29,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "internal.h" #include "internal.h"
#include "lib/util.h"
#include "lib/tty/color.h" /* tty_use_256colors(); */ #include "lib/tty/color.h" /* tty_use_256colors(); */
@ -110,10 +111,12 @@ mc_skin_try_to_load_default (void)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
gboolean gboolean
mc_skin_init (const gchar * skin_override, GError ** error) mc_skin_init (const gchar * skin_override, GError ** mcerror)
{ {
gboolean is_good_init = TRUE; gboolean is_good_init = TRUE;
mc_return_val_if_error (mcerror, FALSE);
mc_skin__default.have_256_colors = FALSE; mc_skin__default.have_256_colors = FALSE;
mc_skin__default.name = mc_skin__default.name =
@ -123,10 +126,9 @@ mc_skin_init (const gchar * skin_override, GError ** error)
g_free, mc_skin_hash_destroy_value); g_free, mc_skin_hash_destroy_value);
if (!mc_skin_ini_file_load (&mc_skin__default)) if (!mc_skin_ini_file_load (&mc_skin__default))
{ {
*error = g_error_new (MC_ERROR, 0, mc_propagate_error (mcerror, 0,
_("Unable to load '%s' skin.\nDefault skin has been loaded"), _("Unable to load '%s' skin.\nDefault skin has been loaded"),
mc_skin__default.name); mc_skin__default.name);
mc_skin_try_to_load_default (); mc_skin_try_to_load_default ();
is_good_init = FALSE; is_good_init = FALSE;
} }
@ -134,10 +136,9 @@ mc_skin_init (const gchar * skin_override, GError ** error)
if (!mc_skin_ini_file_parse (&mc_skin__default)) if (!mc_skin_ini_file_parse (&mc_skin__default))
{ {
if (*error == NULL) mc_propagate_error (mcerror, 0,
*error = g_error_new (MC_ERROR, 0, _("Unable to parse '%s' skin.\nDefault skin has been loaded"),
_("Unable to parse '%s' skin.\nDefault skin has been loaded"), mc_skin__default.name);
mc_skin__default.name);
mc_skin_try_to_load_default (); mc_skin_try_to_load_default ();
mc_skin_colors_old_configure (&mc_skin__default); mc_skin_colors_old_configure (&mc_skin__default);
@ -146,12 +147,10 @@ mc_skin_init (const gchar * skin_override, GError ** error)
} }
if (is_good_init && !tty_use_256colors () && mc_skin__default.have_256_colors) if (is_good_init && !tty_use_256colors () && mc_skin__default.have_256_colors)
{ {
if (*error == NULL) mc_propagate_error (mcerror, 0,
*error = g_error_new (MC_ERROR, 0, _
_ ("Unable to use '%s' skin with 256 colors support\non non-256 colors terminal.\nDefault skin has been loaded"),
("Unable to use '%s' skin with 256 colors support\non non-256 colors terminal.\nDefault skin has been loaded"), mc_skin__default.name);
mc_skin__default.name);
mc_skin_try_to_load_default (); mc_skin_try_to_load_default ();
mc_skin_colors_old_configure (&mc_skin__default); mc_skin_colors_old_configure (&mc_skin__default);
(void) mc_skin_ini_file_parse (&mc_skin__default); (void) mc_skin_ini_file_parse (&mc_skin__default);

View File

@ -134,16 +134,16 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
while (left != 0) while (left != 0)
{ {
gchar *tmp_buff; gchar *tmp_buff;
GError *error = NULL; GError *mcerror = NULL;
tmp_buff = g_convert_with_iconv ((const gchar *) string, tmp_buff = g_convert_with_iconv ((const gchar *) string,
left, coder, &bytes_read, &bytes_written, &error); left, coder, &bytes_read, &bytes_written, &mcerror);
if (error != NULL) if (mcerror != NULL)
{ {
int code = error->code; int code = mcerror->code;
g_error_free (error); g_error_free (mcerror);
error = NULL; mcerror = NULL;
switch (code) switch (code)
{ {
@ -234,9 +234,9 @@ str_nconvert (GIConv coder, const char *string, int size, GString * buffer)
} }
gchar * gchar *
str_conv_gerror_message (GError * error, const char *def_msg) str_conv_gerror_message (GError * mcerror, const char *def_msg)
{ {
return used_class.conv_gerror_message (error, def_msg); return used_class.conv_gerror_message (mcerror, def_msg);
} }
estr_t estr_t

View File

@ -198,7 +198,7 @@ str_8bit_length2 (const char *text, int size)
} }
static gchar * static gchar *
str_8bit_conv_gerror_message (GError * error, const char *def_msg) str_8bit_conv_gerror_message (GError * mcerror, const char *def_msg)
{ {
GIConv conv; GIConv conv;
gchar *ret; gchar *ret;
@ -214,7 +214,7 @@ str_8bit_conv_gerror_message (GError * error, const char *def_msg)
buf = g_string_new (""); buf = g_string_new ("");
if (str_convert (conv, error->message, buf) != ESTR_FAILURE) if (str_convert (conv, mcerror->message, buf) != ESTR_FAILURE)
ret = g_string_free (buf, FALSE); ret = g_string_free (buf, FALSE);
else else
{ {

View File

@ -164,11 +164,11 @@ str_ascii_length2 (const char *text, int size)
} }
static gchar * static gchar *
str_ascii_conv_gerror_message (GError * error, const char *def_msg) str_ascii_conv_gerror_message (GError * mcerror, const char *def_msg)
{ {
/* the same as str_utf8_conv_gerror_message() */ /* the same as str_utf8_conv_gerror_message() */
if (error != NULL) if (mcerror != NULL)
return g_strdup (error->message); return g_strdup (mcerror->message);
return g_strdup (def_msg != NULL ? def_msg : ""); return g_strdup (def_msg != NULL ? def_msg : "");
} }

View File

@ -333,10 +333,10 @@ str_utf8_length_noncomb (const char *text)
*/ */
static gchar * static gchar *
str_utf8_conv_gerror_message (GError * error, const char *def_msg) str_utf8_conv_gerror_message (GError * mcerror, const char *def_msg)
{ {
if (error != NULL) if (mcerror != NULL)
return g_strdup (error->message); return g_strdup (mcerror->message);
return g_strdup (def_msg != NULL ? def_msg : ""); return g_strdup (def_msg != NULL ? def_msg : "");
} }

View File

@ -1399,3 +1399,57 @@ guess_message_value (void)
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/**
* Propagate error in simple way.
*
* @param dest error return location
* @param code error code
* @param format printf()-style format for error message
* @param ... parameters for message format
*/
void
mc_propagate_error (GError ** dest, int code, const char *format, ...)
{
if (dest != NULL && *dest == NULL)
{
GError *tmp_error;
va_list args;
va_start (args, format);
tmp_error = g_error_new_valist (MC_ERROR, code, format, args);
va_end (args);
g_propagate_error (dest, tmp_error);
}
}
/* --------------------------------------------------------------------------------------------- */
/**
* Replace existing error in simple way.
*
* @param dest error return location
* @param code error code
* @param format printf()-style format for error message
* @param ... parameters for message format
*/
void
mc_replace_error (GError ** dest, int code, const char *format, ...)
{
if (dest != NULL)
{
GError *tmp_error;
va_list args;
va_start (args, format);
tmp_error = g_error_new_valist (MC_ERROR, code, format, args);
va_end (args);
g_error_free (*dest);
*dest = NULL;
g_propagate_error (dest, tmp_error);
}
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -24,6 +24,10 @@
#define MC_PTR_FREE(ptr) do { g_free (ptr); (ptr) = NULL; } while (0) #define MC_PTR_FREE(ptr) do { g_free (ptr); (ptr) = NULL; } while (0)
#define mc_return_if_error(mcerror) do { if (mcerror != NULL && *mcerror != NULL) return; } while (0)
#define mc_return_val_if_error(mcerror, mcvalue) do { if (mcerror != NULL && *mcerror != NULL) return mcvalue; } while (0)
/*** enums ***************************************************************************************/ /*** enums ***************************************************************************************/
/* Pathname canonicalization */ /* Pathname canonicalization */
@ -200,6 +204,9 @@ char *guess_message_value (void);
char *mc_build_filename (const char *first_element, ...); char *mc_build_filename (const char *first_element, ...);
char *mc_build_filenamev (const char *first_element, va_list args); char *mc_build_filenamev (const char *first_element, va_list args);
void mc_propagate_error (GError ** dest, int code, const char *format, ...);
void mc_replace_error (GError ** dest, int code, const char *format, ...);
/*** inline functions **************************************************/ /*** inline functions **************************************************/
static inline gboolean static inline gboolean

View File

@ -1084,15 +1084,17 @@ vfs_path_change_encoding (vfs_path_t * vpath, const char *encoding)
*/ */
char * char *
vfs_path_serialize (const vfs_path_t * vpath, GError ** error) vfs_path_serialize (const vfs_path_t * vpath, GError ** mcerror)
{ {
mc_config_t *cpath; mc_config_t *cpath;
ssize_t element_index; ssize_t element_index;
char *ret_value; char *ret_value;
mc_return_val_if_error (mcerror, FALSE);
if ((vpath == NULL) || (vfs_path_elements_count (vpath) == 0)) if ((vpath == NULL) || (vfs_path_elements_count (vpath) == 0))
{ {
g_set_error (error, MC_ERROR, -1, "vpath object is empty"); mc_propagate_error (mcerror, -1, "%s", "vpath object is empty");
return NULL; return NULL;
} }
@ -1124,7 +1126,7 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
g_free (groupname); g_free (groupname);
} }
ret_value = mc_serialize_config (cpath, error); ret_value = mc_serialize_config (cpath, mcerror);
mc_config_deinit (cpath); mc_config_deinit (cpath);
return ret_value; return ret_value;
} }
@ -1140,13 +1142,15 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
*/ */
vfs_path_t * vfs_path_t *
vfs_path_deserialize (const char *data, GError ** error) vfs_path_deserialize (const char *data, GError ** mcerror)
{ {
mc_config_t *cpath; mc_config_t *cpath;
size_t element_index = 0; size_t element_index = 0;
vfs_path_t *vpath; vfs_path_t *vpath;
cpath = mc_deserialize_config (data, error); mc_return_val_if_error (mcerror, FALSE);
cpath = mc_deserialize_config (data, mcerror);
if (cpath == NULL) if (cpath == NULL)
return NULL; return NULL;
@ -1173,7 +1177,7 @@ vfs_path_deserialize (const char *data, GError ** error)
{ {
g_free (element); g_free (element);
vfs_path_free (vpath); vfs_path_free (vpath);
g_set_error (error, MC_ERROR, -1, "Unable to find VFS class by name '%s'", cfg_value); g_set_error (mcerror, MC_ERROR, -1, "Unable to find VFS class by name '%s'", cfg_value);
g_free (cfg_value); g_free (cfg_value);
mc_config_deinit (cpath); mc_config_deinit (cpath);
return NULL; return NULL;
@ -1205,7 +1209,7 @@ vfs_path_deserialize (const char *data, GError ** error)
if (vfs_path_elements_count (vpath) == 0) if (vfs_path_elements_count (vpath) == 0)
{ {
vfs_path_free (vpath); vfs_path_free (vpath);
g_set_error (error, MC_ERROR, -1, "No any path elements found"); g_set_error (mcerror, MC_ERROR, -1, "No any path elements found");
return NULL; return NULL;
} }
vpath->str = vfs_path_to_str_flags (vpath, 0, VPF_NONE); vpath->str = vfs_path_to_str_flags (vpath, 0, VPF_NONE);

View File

@ -430,6 +430,22 @@ message (int flags, const char *title, const char *text, ...)
g_free (p); g_free (p);
} }
/* --------------------------------------------------------------------------------------------- */
/** Show error message box */
gboolean
mc_error_message (GError ** mcerror)
{
if (mcerror == NULL || *mcerror == NULL)
return FALSE;
message (D_ERROR, MSG_ERROR, _("%d: %s"), (*mcerror)->code, (*mcerror)->message);
g_error_free (*mcerror);
*mcerror = NULL;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/** /**
* Show input dialog, background safe. * Show input dialog, background safe.

View File

@ -50,6 +50,8 @@ struct WDialog *create_message (int flags, const char *title,
void message (int flags, const char *title, const char *text, ...) void message (int flags, const char *title, const char *text, ...)
__attribute__ ((format (__printf__, 3, 4))); __attribute__ ((format (__printf__, 3, 4)));
gboolean mc_error_message (GError ** mcerror);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/
#endif /* MC__WTOOLS_H */ #endif /* MC__WTOOLS_H */

View File

@ -82,9 +82,9 @@ char *mc_run_param1 = NULL;
/* forward declarations */ /* forward declarations */
static gboolean parse_mc_e_argument (const gchar * option_name, const gchar * value, static gboolean parse_mc_e_argument (const gchar * option_name, const gchar * value,
gpointer data, GError ** error); gpointer data, GError ** mcerror);
static gboolean parse_mc_v_argument (const gchar * option_name, const gchar * value, static gboolean parse_mc_v_argument (const gchar * option_name, const gchar * value,
gpointer data, GError ** error); gpointer data, GError ** mcerror);
static GOptionContext *context; static GOptionContext *context;
@ -418,7 +418,7 @@ mc_args_add_extended_info_to_help (void)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static gchar * static gchar *
mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_message, mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_message_str,
const gchar * help_str) const gchar * help_str)
{ {
GString *buffer; GString *buffer;
@ -427,7 +427,7 @@ mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_
buffer = g_string_new (""); buffer = g_string_new ("");
conv = g_iconv_open (charset, "UTF-8"); conv = g_iconv_open (charset, "UTF-8");
full_help_str = g_strdup_printf ("%s\n\n%s\n", error_message, help_str); full_help_str = g_strdup_printf ("%s\n\n%s\n", error_message_str, help_str);
str_convert (conv, full_help_str, buffer); str_convert (conv, full_help_str, buffer);
@ -440,12 +440,14 @@ mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static gboolean static gboolean
parse_mc_e_argument (const gchar * option_name, const gchar * value, gpointer data, GError ** error) parse_mc_e_argument (const gchar * option_name, const gchar * value, gpointer data,
GError ** mcerror)
{ {
(void) option_name; (void) option_name;
(void) value; (void) value;
(void) data; (void) data;
(void) error;
mc_return_val_if_error (mcerror, FALSE);
mc_global.mc_run_mode = MC_RUN_EDITOR; mc_global.mc_run_mode = MC_RUN_EDITOR;
@ -455,11 +457,13 @@ parse_mc_e_argument (const gchar * option_name, const gchar * value, gpointer da
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static gboolean static gboolean
parse_mc_v_argument (const gchar * option_name, const gchar * value, gpointer data, GError ** error) parse_mc_v_argument (const gchar * option_name, const gchar * value, gpointer data,
GError ** mcerror)
{ {
(void) option_name; (void) option_name;
(void) data; (void) data;
(void) error;
mc_return_val_if_error (mcerror, FALSE);
mc_global.mc_run_mode = MC_RUN_VIEWER; mc_global.mc_run_mode = MC_RUN_VIEWER;
mc_run_param0 = g_strdup (value); mc_run_param0 = g_strdup (value);
@ -576,11 +580,13 @@ parse_mcedit_arguments (int argc, char **argv)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
gboolean gboolean
mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** error) mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** mcerror)
{ {
const gchar *_system_codepage; const gchar *_system_codepage;
gboolean ok = TRUE; gboolean ok = TRUE;
mc_return_val_if_error (mcerror, FALSE);
_system_codepage = str_detect_termencoding (); _system_codepage = str_detect_termencoding ();
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
@ -613,12 +619,11 @@ mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError *
g_option_context_add_group (context, color_group); g_option_context_add_group (context, color_group);
g_option_group_set_translation_domain (color_group, translation_domain); g_option_group_set_translation_domain (color_group, translation_domain);
if (!g_option_context_parse (context, argc, argv, error)) if (!g_option_context_parse (context, argc, argv, mcerror))
{ {
GError *error2 = NULL;
if (*error == NULL) if (*mcerror == NULL)
*error = g_error_new (MC_ERROR, 0, "%s\n", _("Arguments parse error!")); mc_propagate_error (mcerror, 0, "%s\n", _("Arguments parse error!"));
else else
{ {
gchar *help_str; gchar *help_str;
@ -629,22 +634,19 @@ mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError *
help_str = g_strdup (""); help_str = g_strdup ("");
#endif #endif
if (str_isutf8 (_system_codepage)) if (str_isutf8 (_system_codepage))
error2 = g_error_new ((*error)->domain, (*error)->code, "%s\n\n%s\n", mc_replace_error (mcerror, (*mcerror)->code, "%s\n\n%s\n", (*mcerror)->message,
(*error)->message, help_str); help_str);
else else
{ {
gchar *full_help_str; gchar *full_help_str;
full_help_str = full_help_str =
mc_args__convert_help_to_syscharset (_system_codepage, (*error)->message, mc_args__convert_help_to_syscharset (_system_codepage, (*mcerror)->message,
help_str); help_str);
error2 = g_error_new ((*error)->domain, (*error)->code, "%s", full_help_str); mc_replace_error (mcerror, (*mcerror)->code, "%s", full_help_str);
g_free (full_help_str); g_free (full_help_str);
} }
g_free (help_str); g_free (help_str);
g_error_free (*error);
*error = error2;
} }
ok = FALSE; ok = FALSE;
@ -696,11 +698,13 @@ mc_args_show_info (void)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
gboolean gboolean
mc_setup_by_args (int argc, char **argv, GError ** error) mc_setup_by_args (int argc, char **argv, GError ** mcerror)
{ {
const char *base; const char *base;
char *tmp; char *tmp;
mc_return_val_if_error (mcerror, FALSE);
if (mc_args__force_colors) if (mc_args__force_colors)
mc_global.tty.disable_colors = FALSE; mc_global.tty.disable_colors = FALSE;
@ -748,7 +752,7 @@ mc_setup_by_args (int argc, char **argv, GError ** error)
mc_run_param0 = g_strdup (tmp); mc_run_param0 = g_strdup (tmp);
else else
{ {
*error = g_error_new (MC_ERROR, 0, "%s\n", _("No arguments given to the viewer.")); mc_propagate_error (mcerror, 0, "%s\n", _("No arguments given to the viewer."));
return FALSE; return FALSE;
} }
mc_global.mc_run_mode = MC_RUN_VIEWER; mc_global.mc_run_mode = MC_RUN_VIEWER;
@ -760,8 +764,8 @@ mc_setup_by_args (int argc, char **argv, GError ** error)
if (argc < 3) if (argc < 3)
{ {
*error = g_error_new (MC_ERROR, 0, "%s\n", mc_propagate_error (mcerror, 0, "%s\n",
_("Two files are required to evoke the diffviewer.")); _("Two files are required to evoke the diffviewer."));
return FALSE; return FALSE;
} }

View File

@ -44,9 +44,9 @@ extern char *mc_run_param1;
/*** declarations of public functions ************************************************************/ /*** declarations of public functions ************************************************************/
gboolean mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** error); gboolean mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** mcerror);
gboolean mc_args_show_info (void); gboolean mc_args_show_info (void);
gboolean mc_setup_by_args (int argc, char **argv, GError ** error); gboolean mc_setup_by_args (int argc, char **argv, GError ** mcerror);
mcedit_arg_t *mcedit_arg_new (const char *file_name, long line_number); mcedit_arg_t *mcedit_arg_new (const char *file_name, long line_number);
mcedit_arg_t *mcedit_arg_vpath_new (vfs_path_t * file_vpath, long line_number); mcedit_arg_t *mcedit_arg_vpath_new (vfs_path_t * file_vpath, long line_number);

View File

@ -55,7 +55,7 @@
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
gboolean gboolean
events_init (GError ** error) events_init (GError ** mcerror)
{ {
/* *INDENT-OFF* */ /* *INDENT-OFF* */
event_init_t standard_events[] = event_init_t standard_events[] =
@ -77,10 +77,10 @@ events_init (GError ** error)
}; };
/* *INDENT-ON* */ /* *INDENT-ON* */
if (!mc_event_init (error)) if (!mc_event_init (mcerror))
return FALSE; return FALSE;
return mc_event_mass_add (standard_events, error); return mc_event_mass_add (standard_events, mcerror);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -521,10 +521,10 @@ configure_box (void)
static void static void
skin_apply (const gchar * skin_override) skin_apply (const gchar * skin_override)
{ {
GError *error = NULL; GError *mcerror = NULL;
mc_skin_deinit (); mc_skin_deinit ();
mc_skin_init (skin_override, &error); mc_skin_init (skin_override, &mcerror);
mc_fhl_free (&mc_filehighlight); mc_fhl_free (&mc_filehighlight);
mc_filehighlight = mc_fhl_new (TRUE); mc_filehighlight = mc_fhl_new (TRUE);
dlg_set_default_colors (); dlg_set_default_colors ();
@ -535,11 +535,7 @@ skin_apply (const gchar * skin_override)
panel_init (); panel_init ();
repaint_screen (); repaint_screen ();
if (error != NULL) mc_error_message (&mcerror);
{
message (D_ERROR, _("Warning"), "%s", error->message);
g_error_free (error);
}
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -618,7 +618,7 @@ get_file_encoding_local (const vfs_path_t * filename_vpath, char *buf, int bufle
static gboolean static gboolean
regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean case_insense, regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean case_insense,
gboolean * have_type, GError ** error) gboolean * have_type, GError ** mcerror)
{ {
gboolean found = FALSE; gboolean found = FALSE;
@ -627,6 +627,8 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c
static size_t content_shift = 0; static size_t content_shift = 0;
static int got_data = 0; static int got_data = 0;
mc_return_val_if_error (mcerror, FALSE);
if (!use_file_to_check_type) if (!use_file_to_check_type)
return FALSE; return FALSE;
@ -646,10 +648,8 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c
localfile_vpath = mc_getlocalcopy (filename_vpath); localfile_vpath = mc_getlocalcopy (filename_vpath);
if (localfile_vpath == NULL) if (localfile_vpath == NULL)
{ {
g_propagate_error (error, mc_propagate_error (mcerror, -1, _("Cannot fetch a local copy of %s"),
g_error_new (MC_ERROR, -1, vfs_path_as_str (filename_vpath));
_("Cannot fetch a local copy of %s"),
vfs_path_as_str (filename_vpath)));
return FALSE; return FALSE;
} }
@ -715,7 +715,7 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c
if (got_data == -1) if (got_data == -1)
{ {
g_propagate_error (error, g_error_new (MC_ERROR, -1, _("Pipe failed"))); mc_propagate_error (mcerror, -1, "%s", _("Pipe failed"));
return FALSE; return FALSE;
} }
@ -733,7 +733,7 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c
} }
else else
{ {
g_propagate_error (error, g_error_new (MC_ERROR, -1, _("Regular expression error"))); mc_propagate_error (mcerror, -1, "%s", _("Regular expression error"));
} }
} }
@ -958,7 +958,7 @@ regex_command_for (void *target, const vfs_path_t * filename_vpath, const char *
} }
else if (strncmp (p, "type/", 5) == 0) else if (strncmp (p, "type/", 5) == 0)
{ {
GError *error = NULL; GError *mcerror = NULL;
p += 5; p += 5;
@ -966,12 +966,9 @@ regex_command_for (void *target, const vfs_path_t * filename_vpath, const char *
if (case_insense) if (case_insense)
p += 2; p += 2;
found = regex_check_type (filename_vpath, p, case_insense, &have_type, &error); found = regex_check_type (filename_vpath, p, case_insense, &have_type, &mcerror);
if (error != NULL) if (mc_error_message (&mcerror))
{
g_error_free (error);
error_flag = TRUE; /* leave it if file cannot be opened */ error_flag = TRUE; /* leave it if file cannot be opened */
}
} }
else if (strncmp (p, "default/", 8) == 0) else if (strncmp (p, "default/", 8) == 0)
found = TRUE; found = TRUE;

View File

@ -1466,11 +1466,13 @@ load_hotlist (void)
if (remove_old_list) if (remove_old_list)
{ {
GError *error = NULL; GError *mcerror = NULL;
clean_up_hotlist_groups ("Hotlist"); clean_up_hotlist_groups ("Hotlist");
if (!mc_config_save_file (mc_main_config, &error)) if (!mc_config_save_file (mc_main_config, &mcerror))
setup_save_config_show_error (mc_main_config->ini_path, &error); setup_save_config_show_error (mc_main_config->ini_path, &mcerror);
mc_error_message (&mcerror);
} }
stat (hotlist_file_name, &stat_buf); stat (hotlist_file_name, &stat_buf);

View File

@ -2413,7 +2413,7 @@ mark_file_left (WPanel * panel)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static void static void
panel_select_unselect_files (WPanel *panel, const char *title, const char *history_name, panel_select_unselect_files (WPanel * panel, const char *title, const char *history_name,
gboolean do_select) gboolean do_select)
{ {
int files_only = (panels_options.select_flags & SELECT_FILES_ONLY) != 0; int files_only = (panels_options.select_flags & SELECT_FILES_ONLY) != 0;
@ -2485,7 +2485,7 @@ panel_select_unselect_files (WPanel *panel, const char *title, const char *histo
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static void static void
panel_select_files (WPanel *panel) panel_select_files (WPanel * panel)
{ {
panel_select_unselect_files (panel, _("Select"), ":select_cmd: Select ", TRUE); panel_select_unselect_files (panel, _("Select"), ":select_cmd: Select ", TRUE);
} }
@ -2493,7 +2493,7 @@ panel_select_files (WPanel *panel)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static void static void
panel_unselect_files (WPanel *panel) panel_unselect_files (WPanel * panel)
{ {
panel_select_unselect_files (panel, _("Unselect"), ":unselect_cmd: Unselect ", FALSE); panel_select_unselect_files (panel, _("Unselect"), ":unselect_cmd: Unselect ", FALSE);
} }
@ -2501,7 +2501,7 @@ panel_unselect_files (WPanel *panel)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static void static void
panel_select_invert_files (WPanel *panel) panel_select_invert_files (WPanel * panel)
{ {
int i; int i;

View File

@ -233,7 +233,7 @@ init_sigchld (void)
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
GError *error = NULL; GError *mcerror = NULL;
gboolean config_migrated = FALSE; gboolean config_migrated = FALSE;
char *config_migrate_msg; char *config_migrate_msg;
int exit_code = EXIT_FAILURE; int exit_code = EXIT_FAILURE;
@ -248,11 +248,11 @@ main (int argc, char *argv[])
/* do this before args parsing */ /* do this before args parsing */
str_init_strings (NULL); str_init_strings (NULL);
if (!mc_args_parse (&argc, &argv, "mc", &error)) if (!mc_args_parse (&argc, &argv, "mc", &mcerror))
{ {
startup_exit_falure: startup_exit_falure:
fprintf (stderr, _("Failed to run:\n%s\n"), error->message); fprintf (stderr, _("Failed to run:\n%s\n"), mcerror->message);
g_error_free (error); g_error_free (mcerror);
g_free (mc_global.tty.shell); g_free (mc_global.tty.shell);
startup_exit_ok: startup_exit_ok:
str_uninit_strings (); str_uninit_strings ();
@ -264,8 +264,8 @@ main (int argc, char *argv[])
if (!g_path_is_absolute (mc_config_get_home_dir ())) if (!g_path_is_absolute (mc_config_get_home_dir ()))
{ {
error = g_error_new (MC_ERROR, 0, "%s: %s", _("Home directory path is not absolute"), mc_propagate_error (&mcerror, 0, "%s: %s", _("Home directory path is not absolute"),
mc_config_get_home_dir ()); mc_config_get_home_dir ());
mc_event_deinit (NULL); mc_event_deinit (NULL);
goto startup_exit_falure; goto startup_exit_falure;
} }
@ -276,13 +276,12 @@ main (int argc, char *argv[])
goto startup_exit_ok; goto startup_exit_ok;
} }
if (!events_init (&error)) if (!events_init (&mcerror))
goto startup_exit_falure; goto startup_exit_falure;
mc_config_init_config_paths (&error); mc_config_init_config_paths (&mcerror);
if (error == NULL) config_migrated = mc_config_migrate_from_old_place (&mcerror, &config_migrate_msg);
config_migrated = mc_config_migrate_from_old_place (&error, &config_migrate_msg); if (mcerror != NULL)
if (error != NULL)
{ {
mc_event_deinit (NULL); mc_event_deinit (NULL);
goto startup_exit_falure; goto startup_exit_falure;
@ -315,7 +314,7 @@ main (int argc, char *argv[])
/* do this after vfs initialization and vfs working directory setup /* do this after vfs initialization and vfs working directory setup
due to mc_setctl() and mcedit_arg_vpath_new() calls in mc_setup_by_args() */ due to mc_setctl() and mcedit_arg_vpath_new() calls in mc_setup_by_args() */
if (!mc_setup_by_args (argc, argv, &error)) if (!mc_setup_by_args (argc, argv, &mcerror))
{ {
vfs_shut (); vfs_shut ();
done_setup (); done_setup ();
@ -369,17 +368,13 @@ main (int argc, char *argv[])
tty_init_colors (mc_global.tty.disable_colors, mc_args__force_colors); tty_init_colors (mc_global.tty.disable_colors, mc_args__force_colors);
mc_skin_init (NULL, &error); mc_skin_init (NULL, &mcerror);
dlg_set_default_colors (); dlg_set_default_colors ();
input_set_default_colors (); input_set_default_colors ();
if (mc_global.mc_run_mode == MC_RUN_FULL) if (mc_global.mc_run_mode == MC_RUN_FULL)
command_set_default_colors (); command_set_default_colors ();
if (error != NULL)
{ mc_error_message (&mcerror);
message (D_ERROR, _("Warning"), "%s", error->message);
g_error_free (error);
error = NULL;
}
#ifdef ENABLE_SUBSHELL #ifdef ENABLE_SUBSHELL
/* Done here to ensure that the subshell doesn't */ /* Done here to ensure that the subshell doesn't */
@ -494,11 +489,11 @@ main (int argc, char *argv[])
mc_config_deinit_config_paths (); mc_config_deinit_config_paths ();
(void) mc_event_deinit (&error); (void) mc_event_deinit (&mcerror);
if (error != NULL) if (mcerror != NULL)
{ {
fprintf (stderr, _("\nFailed while close:\n%s\n"), error->message); fprintf (stderr, _("\nFailed while close:\n%s\n"), mcerror->message);
g_error_free (error); g_error_free (mcerror);
exit_code = EXIT_FAILURE; exit_code = EXIT_FAILURE;
} }

View File

@ -1166,13 +1166,13 @@ save_config (void)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
void void
setup_save_config_show_error (const char *filename, GError ** error) setup_save_config_show_error (const char *filename, GError ** mcerror)
{ {
if (error != NULL && *error != NULL) if (mcerror != NULL && *mcerror != NULL)
{ {
message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*error)->message); message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*mcerror)->message);
g_error_free (*error); g_error_free (*mcerror);
*error = NULL; *mcerror = NULL;
} }
} }

View File

@ -141,7 +141,7 @@ void load_setup (void);
gboolean save_setup (gboolean save_options, gboolean save_panel_options); gboolean save_setup (gboolean save_options, gboolean save_panel_options);
void done_setup (void); void done_setup (void);
void save_config (void); void save_config (void);
void setup_save_config_show_error (const char *filename, GError ** error); void setup_save_config_show_error (const char *filename, GError ** mcerror);
void save_layout (void); void save_layout (void);

View File

@ -196,20 +196,22 @@ sftpfs_fill_config_entity_from_string (sftpfs_ssh_config_entity_t * config_entit
* @param ssh_config_handler file descriptor for the ssh config file * @param ssh_config_handler file descriptor for the ssh config file
* @param config_entity config entity structure * @param config_entity config entity structure
* @param vpath_element path element with host data (hostname, port) * @param vpath_element path element with host data (hostname, port)
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return TRUE if config entity was filled successfully, FALSE otherwise * @return TRUE if config entity was filled successfully, FALSE otherwise
*/ */
static gboolean static gboolean
sftpfs_fill_config_entity_from_config (FILE * ssh_config_handler, sftpfs_fill_config_entity_from_config (FILE * ssh_config_handler,
sftpfs_ssh_config_entity_t * config_entity, sftpfs_ssh_config_entity_t * config_entity,
const vfs_path_element_t * vpath_element, GError ** error) const vfs_path_element_t * vpath_element, GError ** mcerror)
{ {
char buffer[BUF_MEDIUM]; char buffer[BUF_MEDIUM];
gboolean host_block_hit = FALSE; gboolean host_block_hit = FALSE;
gboolean pattern_block_hit = FALSE; gboolean pattern_block_hit = FALSE;
mc_search_t *host_regexp; mc_search_t *host_regexp;
mc_return_val_if_error (mcerror, FALSE);
host_regexp = mc_search_new ("^\\s*host\\s+(.*)$", -1, DEFAULT_CHARSET); host_regexp = mc_search_new ("^\\s*host\\s+(.*)$", -1, DEFAULT_CHARSET);
host_regexp->search_type = MC_SEARCH_T_REGEX; host_regexp->search_type = MC_SEARCH_T_REGEX;
host_regexp->is_case_sensitive = FALSE; host_regexp->is_case_sensitive = FALSE;
@ -221,9 +223,9 @@ sftpfs_fill_config_entity_from_config (FILE * ssh_config_handler,
{ {
if (errno != 0) if (errno != 0)
{ {
g_set_error (error, MC_ERROR, errno, mc_propagate_error (mcerror, errno,
_("sftp: an error occurred while reading %s: %s"), SFTPFS_SSH_CONFIG, _("sftp: an error occurred while reading %s: %s"),
strerror (errno)); SFTPFS_SSH_CONFIG, strerror (errno));
mc_search_free (host_regexp); mc_search_free (host_regexp);
return FALSE; return FALSE;
} }
@ -277,17 +279,19 @@ sftpfs_fill_config_entity_from_config (FILE * ssh_config_handler,
* Open the ssh config file and fill config entity. * Open the ssh config file and fill config entity.
* *
* @param vpath_element path element with host data (hostname, port) * @param vpath_element path element with host data (hostname, port)
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return newly allocated config entity structure * @return newly allocated config entity structure
*/ */
static sftpfs_ssh_config_entity_t * static sftpfs_ssh_config_entity_t *
sftpfs_get_config_entity (const vfs_path_element_t * vpath_element, GError ** error) sftpfs_get_config_entity (const vfs_path_element_t * vpath_element, GError ** mcerror)
{ {
sftpfs_ssh_config_entity_t *config_entity; sftpfs_ssh_config_entity_t *config_entity;
FILE *ssh_config_handler; FILE *ssh_config_handler;
char *config_filename; char *config_filename;
mc_return_val_if_error (mcerror, FALSE);
config_entity = g_new0 (sftpfs_ssh_config_entity_t, 1); config_entity = g_new0 (sftpfs_ssh_config_entity_t, 1);
config_entity->password_auth = TRUE; config_entity->password_auth = TRUE;
config_entity->identities_only = FALSE; config_entity->identities_only = FALSE;
@ -303,7 +307,7 @@ sftpfs_get_config_entity (const vfs_path_element_t * vpath_element, GError ** er
gboolean ok; gboolean ok;
ok = sftpfs_fill_config_entity_from_config ok = sftpfs_fill_config_entity_from_config
(ssh_config_handler, config_entity, vpath_element, error); (ssh_config_handler, config_entity, vpath_element, mcerror);
fclose (ssh_config_handler); fclose (ssh_config_handler);
if (!ok) if (!ok)
@ -320,7 +324,7 @@ sftpfs_get_config_entity (const vfs_path_element_t * vpath_element, GError ** er
{ {
sftpfs_ssh_config_entity_free (config_entity); sftpfs_ssh_config_entity_free (config_entity);
config_entity = NULL; config_entity = NULL;
g_set_error (error, MC_ERROR, EPERM, _("sftp: Unable to get current user name.")); mc_propagate_error (mcerror, EPERM, "%s", _("sftp: Unable to get current user name."));
} }
} }
return config_entity; return config_entity;
@ -337,14 +341,16 @@ sftpfs_get_config_entity (const vfs_path_element_t * vpath_element, GError ** er
*/ */
void void
sftpfs_fill_connection_data_from_config (struct vfs_s_super *super, GError ** error) sftpfs_fill_connection_data_from_config (struct vfs_s_super *super, GError ** mcerror)
{ {
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
sftpfs_ssh_config_entity_t *config_entity; sftpfs_ssh_config_entity_t *config_entity;
mc_return_if_error (mcerror);
super_data = (sftpfs_super_data_t *) super->data; super_data = (sftpfs_super_data_t *) super->data;
config_entity = sftpfs_get_config_entity (super->path_element, error); config_entity = sftpfs_get_config_entity (super->path_element, mcerror);
if (config_entity == NULL) if (config_entity == NULL)
return; return;

View File

@ -58,28 +58,30 @@
/** /**
* Create socket to host. * Create socket to host.
* *
* @param super connection data * @param super connection data
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return socket descriptor number, -1 if any error was occurred * @return socket descriptor number, -1 if any error was occurred
*/ */
static int static int
sftpfs_open_socket (struct vfs_s_super *super, GError ** error) sftpfs_open_socket (struct vfs_s_super *super, GError ** mcerror)
{ {
struct addrinfo hints, *res = NULL, *curr_res; struct addrinfo hints, *res = NULL, *curr_res;
int my_socket = 0; int my_socket = 0;
char port[BUF_TINY]; char port[BUF_TINY];
int e; int e;
mc_return_val_if_error (mcerror, -1);
if (super->path_element->host == NULL || *super->path_element->host == '\0') if (super->path_element->host == NULL || *super->path_element->host == '\0')
{ {
g_set_error (error, MC_ERROR, -1, _("sftp: Invalid host name.")); mc_propagate_error (mcerror, -1, "%s", _("sftp: Invalid host name."));
return -1; return -1;
} }
if (sprintf (port, "%hu", (unsigned short) super->path_element->port) < 0) if (sprintf (port, "%hu", (unsigned short) super->path_element->port) < 0)
{ {
g_set_error (error, MC_ERROR, -1, _("sftp: Invalid port value.")); mc_propagate_error (mcerror, -1, "%s", _("sftp: Invalid port value."));
return -1; return -1;
} }
@ -109,7 +111,7 @@ sftpfs_open_socket (struct vfs_s_super *super, GError ** error)
if (e != 0) if (e != 0)
{ {
g_set_error (error, MC_ERROR, -1, _("sftp: %s"), gai_strerror (e)); mc_propagate_error (mcerror, -1, _("sftp: %s"), gai_strerror (e));
my_socket = -1; my_socket = -1;
goto ret; goto ret;
} }
@ -136,10 +138,10 @@ sftpfs_open_socket (struct vfs_s_super *super, GError ** error)
close (my_socket); close (my_socket);
if (errno == EINTR && tty_got_interrupt ()) if (errno == EINTR && tty_got_interrupt ())
g_set_error (error, MC_ERROR, -1, _("sftp: connection interrupted by user")); mc_propagate_error (mcerror, -1, "%s", _("sftp: connection interrupted by user"));
else if (res->ai_next == NULL) else if (res->ai_next == NULL)
g_set_error (error, MC_ERROR, -1, _("sftp: connection to server failed: %s"), mc_propagate_error (mcerror, -1, _("sftp: connection to server failed: %s"),
unix_error_string (errno)); unix_error_string (errno));
else else
continue; continue;
@ -193,19 +195,19 @@ sftpfs_recognize_auth_types (struct vfs_s_super *super)
/** /**
* Open connection to host using SSH-agent helper. * Open connection to host using SSH-agent helper.
* *
* @param super connection data * @param super connection data
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return TRUE if connection was successfully opened, FALSE otherwise * @return TRUE if connection was successfully opened, FALSE otherwise
*/ */
static gboolean static gboolean
sftpfs_open_connection_ssh_agent (struct vfs_s_super *super, GError ** error) sftpfs_open_connection_ssh_agent (struct vfs_s_super *super, GError ** mcerror)
{ {
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
struct libssh2_agent_publickey *identity, *prev_identity = NULL; struct libssh2_agent_publickey *identity, *prev_identity = NULL;
int rc; int rc;
(void) error; mc_return_val_if_error (mcerror, FALSE);
super_data = (sftpfs_super_data_t *) super->data; super_data = (sftpfs_super_data_t *) super->data;
super_data->agent = NULL; super_data->agent = NULL;
@ -246,18 +248,20 @@ sftpfs_open_connection_ssh_agent (struct vfs_s_super *super, GError ** error)
/** /**
* Open connection to host using SSH-keypair. * Open connection to host using SSH-keypair.
* *
* @param super connection data * @param super connection data
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return TRUE if connection was successfully opened, FALSE otherwise * @return TRUE if connection was successfully opened, FALSE otherwise
*/ */
static gboolean static gboolean
sftpfs_open_connection_ssh_key (struct vfs_s_super *super, GError ** error) sftpfs_open_connection_ssh_key (struct vfs_s_super *super, GError ** mcerror)
{ {
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
char *p, *passwd; char *p, *passwd;
gboolean ret_value = FALSE; gboolean ret_value = FALSE;
mc_return_val_if_error (mcerror, FALSE);
super_data = (sftpfs_super_data_t *) super->data; super_data = (sftpfs_super_data_t *) super->data;
if ((super_data->auth_type & PUBKEY) == 0) if ((super_data->auth_type & PUBKEY) == 0)
@ -276,7 +280,7 @@ sftpfs_open_connection_ssh_key (struct vfs_s_super *super, GError ** error)
g_free (p); g_free (p);
if (passwd == NULL) if (passwd == NULL)
g_set_error (error, MC_ERROR, -1, _("sftp: Passphrase is empty.")); mc_propagate_error (mcerror, -1, "%s", _("sftp: Passphrase is empty."));
else else
{ {
ret_value = (libssh2_userauth_publickey_fromfile (super_data->session, ret_value = (libssh2_userauth_publickey_fromfile (super_data->session,
@ -293,19 +297,21 @@ sftpfs_open_connection_ssh_key (struct vfs_s_super *super, GError ** error)
/** /**
* Open connection to host using password. * Open connection to host using password.
* *
* @param super connection data * @param super connection data
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return TRUE if connection was successfully opened, FALSE otherwise * @return TRUE if connection was successfully opened, FALSE otherwise
*/ */
static gboolean static gboolean
sftpfs_open_connection_ssh_password (struct vfs_s_super *super, GError ** error) sftpfs_open_connection_ssh_password (struct vfs_s_super *super, GError ** mcerror)
{ {
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
char *p, *passwd; char *p, *passwd;
gboolean ret_value = FALSE; gboolean ret_value = FALSE;
int rc; int rc;
mc_return_val_if_error (mcerror, FALSE);
super_data = (sftpfs_super_data_t *) super->data; super_data = (sftpfs_super_data_t *) super->data;
if ((super_data->auth_type & PASSWORD) == 0) if ((super_data->auth_type & PASSWORD) == 0)
@ -325,7 +331,7 @@ sftpfs_open_connection_ssh_password (struct vfs_s_super *super, GError ** error)
g_free (p); g_free (p);
if (passwd == NULL) if (passwd == NULL)
g_set_error (error, MC_ERROR, -1, _("sftp: Password is empty.")); mc_propagate_error (mcerror, -1, "%s", _("sftp: Password is empty."));
else else
{ {
while ((rc = libssh2_userauth_password (super_data->session, super->path_element->user, while ((rc = libssh2_userauth_password (super_data->session, super->path_element->user,
@ -351,29 +357,31 @@ sftpfs_open_connection_ssh_password (struct vfs_s_super *super, GError ** error)
/** /**
* Open new connection. * Open new connection.
* *
* @param super connection data * @param super connection data
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return 0 if success, -1 otherwise * @return 0 if success, -1 otherwise
*/ */
int int
sftpfs_open_connection (struct vfs_s_super *super, GError ** error) sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror)
{ {
int rc; int rc;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
mc_return_val_if_error (mcerror, -1);
super_data = (sftpfs_super_data_t *) super->data; super_data = (sftpfs_super_data_t *) super->data;
/* Create a session instance */ /* Create a session instance */
super_data->session = libssh2_session_init (); super_data->session = libssh2_session_init ();
if (super_data->session == NULL) if (super_data->session == NULL)
return -1; return (-1);
/* /*
* The application code is responsible for creating the socket * The application code is responsible for creating the socket
* and establishing the connection * and establishing the connection
*/ */
super_data->socket_handle = sftpfs_open_socket (super, error); super_data->socket_handle = sftpfs_open_socket (super, mcerror);
if (super_data->socket_handle == -1) if (super_data->socket_handle == -1)
return (-1); return (-1);
@ -383,7 +391,7 @@ sftpfs_open_connection (struct vfs_s_super *super, GError ** error)
rc = libssh2_session_startup (super_data->session, super_data->socket_handle); rc = libssh2_session_startup (super_data->session, super_data->socket_handle);
if (rc != 0) if (rc != 0)
{ {
g_set_error (error, MC_ERROR, -1, _("sftp: Failure establishing SSH session: (%d)"), rc); mc_propagate_error (mcerror, -1, _("sftp: Failure establishing SSH session: (%d)"), rc);
return (-1); return (-1);
} }
@ -396,9 +404,9 @@ sftpfs_open_connection (struct vfs_s_super *super, GError ** error)
sftpfs_recognize_auth_types (super); sftpfs_recognize_auth_types (super);
if (!sftpfs_open_connection_ssh_agent (super, error) if (!sftpfs_open_connection_ssh_agent (super, mcerror)
&& !sftpfs_open_connection_ssh_key (super, error) && !sftpfs_open_connection_ssh_key (super, mcerror)
&& !sftpfs_open_connection_ssh_password (super, error)) && !sftpfs_open_connection_ssh_password (super, mcerror))
return (-1); return (-1);
super_data->sftp_session = libssh2_sftp_init (super_data->session); super_data->sftp_session = libssh2_sftp_init (super_data->session);
@ -418,15 +426,15 @@ sftpfs_open_connection (struct vfs_s_super *super, GError ** error)
* *
* @param super connection data * @param super connection data
* @param shutdown_message message for shutdown functions * @param shutdown_message message for shutdown functions
* @param error pointer to the error handler * @param mcerror pointer to the error handler
*/ */
void void
sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message, GError ** error) sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message, GError ** mcerror)
{ {
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
(void) error; mc_return_if_error (mcerror);
super_data = (sftpfs_super_data_t *) super->data; super_data = (sftpfs_super_data_t *) super->data;
if (super_data == NULL) if (super_data == NULL)

View File

@ -30,6 +30,7 @@
#include <libssh2_sftp.h> #include <libssh2_sftp.h>
#include "lib/global.h" #include "lib/global.h"
#include "lib/util.h"
#include "internal.h" #include "internal.h"
@ -56,13 +57,13 @@ typedef struct
/** /**
* Open a directory stream corresponding to the directory name. * Open a directory stream corresponding to the directory name.
* *
* @param vpath path to directory * @param vpath path to directory
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return directory data handler if success, NULL otherwise * @return directory data handler if success, NULL otherwise
*/ */
void * void *
sftpfs_opendir (const vfs_path_t * vpath, GError ** error) sftpfs_opendir (const vfs_path_t * vpath, GError ** mcerror)
{ {
sftpfs_dir_data_t *sftpfs_dir; sftpfs_dir_data_t *sftpfs_dir;
struct vfs_s_super *super; struct vfs_s_super *super;
@ -70,6 +71,8 @@ sftpfs_opendir (const vfs_path_t * vpath, GError ** error)
const vfs_path_element_t *path_element; const vfs_path_element_t *path_element;
LIBSSH2_SFTP_HANDLE *handle; LIBSSH2_SFTP_HANDLE *handle;
mc_return_val_if_error (mcerror, NULL);
path_element = vfs_path_get_by_index (vpath, -1); path_element = vfs_path_get_by_index (vpath, -1);
if (vfs_s_get_path (vpath, &super, 0) == NULL) if (vfs_s_get_path (vpath, &super, 0) == NULL)
@ -90,12 +93,12 @@ sftpfs_opendir (const vfs_path_t * vpath, GError ** error)
libssh_errno = libssh2_session_last_errno (super_data->session); libssh_errno = libssh2_session_last_errno (super_data->session);
if (libssh_errno != LIBSSH2_ERROR_EAGAIN) if (libssh_errno != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, libssh_errno, error); sftpfs_ssherror_to_gliberror (super_data, libssh_errno, mcerror);
return NULL; return NULL;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL)
return NULL; mc_return_val_if_error (mcerror, NULL);
} }
sftpfs_dir = g_new0 (sftpfs_dir_data_t, 1); sftpfs_dir = g_new0 (sftpfs_dir_data_t, 1);
@ -109,13 +112,13 @@ sftpfs_opendir (const vfs_path_t * vpath, GError ** error)
/** /**
* Get a pointer to a structure representing the next directory entry. * Get a pointer to a structure representing the next directory entry.
* *
* @param data directory data handler * @param data directory data handler
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return information about direntry if success, NULL otherwise * @return information about direntry if success, NULL otherwise
*/ */
void * void *
sftpfs_readdir (void *data, GError ** error) sftpfs_readdir (void *data, GError ** mcerror)
{ {
char mem[BUF_MEDIUM]; char mem[BUF_MEDIUM];
LIBSSH2_SFTP_ATTRIBUTES attrs; LIBSSH2_SFTP_ATTRIBUTES attrs;
@ -123,6 +126,8 @@ sftpfs_readdir (void *data, GError ** error)
static union vfs_dirent sftpfs_dirent; static union vfs_dirent sftpfs_dirent;
int rc; int rc;
mc_return_val_if_error (mcerror, NULL);
do do
{ {
rc = libssh2_sftp_readdir (sftpfs_dir->handle, mem, sizeof (mem), &attrs); rc = libssh2_sftp_readdir (sftpfs_dir->handle, mem, sizeof (mem), &attrs);
@ -131,13 +136,12 @@ sftpfs_readdir (void *data, GError ** error)
if (rc != LIBSSH2_ERROR_EAGAIN) if (rc != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (sftpfs_dir->super_data, rc, error); sftpfs_ssherror_to_gliberror (sftpfs_dir->super_data, rc, mcerror);
return NULL; return NULL;
} }
sftpfs_waitsocket (sftpfs_dir->super_data, error); sftpfs_waitsocket (sftpfs_dir->super_data, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, NULL);
return NULL;
} }
while (rc == LIBSSH2_ERROR_EAGAIN); while (rc == LIBSSH2_ERROR_EAGAIN);
@ -153,18 +157,18 @@ sftpfs_readdir (void *data, GError ** error)
/** /**
* Close the directory stream. * Close the directory stream.
* *
* @param data directory data handler * @param data directory data handler
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return 0 if success, negative value otherwise * @return 0 if success, negative value otherwise
*/ */
int int
sftpfs_closedir (void *data, GError ** error) sftpfs_closedir (void *data, GError ** mcerror)
{ {
int rc; int rc;
sftpfs_dir_data_t *sftpfs_dir = (sftpfs_dir_data_t *) data; sftpfs_dir_data_t *sftpfs_dir = (sftpfs_dir_data_t *) data;
(void) error; mc_return_val_if_error (mcerror, -1);
rc = libssh2_sftp_closedir (sftpfs_dir->handle); rc = libssh2_sftp_closedir (sftpfs_dir->handle);
g_free (sftpfs_dir); g_free (sftpfs_dir);
@ -175,20 +179,22 @@ sftpfs_closedir (void *data, GError ** error)
/** /**
* Create a new directory. * Create a new directory.
* *
* @param vpath path directory * @param vpath path directory
* @param mode mode (see man 2 open) * @param mode mode (see man 2 open)
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return 0 if success, negative value otherwise * @return 0 if success, negative value otherwise
*/ */
int int
sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** error) sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** mcerror)
{ {
int res; int res;
struct vfs_s_super *super; struct vfs_s_super *super;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
const vfs_path_element_t *path_element; const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1); path_element = vfs_path_get_by_index (vpath, -1);
if (vfs_s_get_path (vpath, &super, 0) == NULL) if (vfs_s_get_path (vpath, &super, 0) == NULL)
@ -215,13 +221,12 @@ sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** error)
if (res != LIBSSH2_ERROR_EAGAIN) if (res != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, res, error); sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, -1);
return -1;
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -232,19 +237,21 @@ sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** error)
/** /**
* Remove a directory. * Remove a directory.
* *
* @param vpath path directory * @param vpath path directory
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return 0 if success, negative value otherwise * @return 0 if success, negative value otherwise
*/ */
int int
sftpfs_rmdir (const vfs_path_t * vpath, GError ** error) sftpfs_rmdir (const vfs_path_t * vpath, GError ** mcerror)
{ {
int res; int res;
struct vfs_s_super *super; struct vfs_s_super *super;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
const vfs_path_element_t *path_element; const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1); path_element = vfs_path_get_by_index (vpath, -1);
if (vfs_s_get_path (vpath, &super, 0) == NULL) if (vfs_s_get_path (vpath, &super, 0) == NULL)
@ -270,13 +277,12 @@ sftpfs_rmdir (const vfs_path_t * vpath, GError ** error)
if (res != LIBSSH2_ERROR_EAGAIN) if (res != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, res, error); sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, -1);
return -1;
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);

View File

@ -30,6 +30,7 @@
#include <libssh2_sftp.h> #include <libssh2_sftp.h>
#include "lib/global.h" #include "lib/global.h"
#include "lib/util.h"
#include "internal.h" #include "internal.h"
@ -54,22 +55,23 @@ typedef struct
* Reopen file by file handle. * Reopen file by file handle.
* *
* @param file_handler the file handler data * @param file_handler the file handler data
* @param error pointer to the error handler * @param mcerror pointer to the error handler
*/ */
static void static void
sftpfs_reopen (vfs_file_handler_t * file_handler, GError ** error) sftpfs_reopen (vfs_file_handler_t * file_handler, GError ** mcerror)
{ {
sftpfs_file_handler_data_t *file_handler_data; sftpfs_file_handler_data_t *file_handler_data;
int flags; int flags;
mode_t mode; mode_t mode;
g_return_if_fail (mcerror == NULL || *mcerror == NULL);
file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data; file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data;
flags = file_handler_data->flags; flags = file_handler_data->flags;
mode = file_handler_data->mode; mode = file_handler_data->mode;
sftpfs_close_file (file_handler, error); sftpfs_close_file (file_handler, mcerror);
if (error == NULL || *error == NULL) sftpfs_open_file (file_handler, flags, mode, mcerror);
sftpfs_open_file (file_handler, flags, mode, error);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -81,12 +83,12 @@ sftpfs_reopen (vfs_file_handler_t * file_handler, GError ** error)
* @param file_handler the file handler data * @param file_handler the file handler data
* @param flags flags (see man 2 open) * @param flags flags (see man 2 open)
* @param mode mode (see man 2 open) * @param mode mode (see man 2 open)
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return TRUE if connection was created successfully, FALSE otherwise * @return TRUE if connection was created successfully, FALSE otherwise
*/ */
gboolean gboolean
sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode, GError ** error) sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode, GError ** mcerror)
{ {
unsigned long sftp_open_flags = 0; unsigned long sftp_open_flags = 0;
int sftp_open_mode = 0; int sftp_open_mode = 0;
@ -96,6 +98,7 @@ sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode, GEr
char *name; char *name;
(void) mode; (void) mode;
mc_return_val_if_error (mcerror, FALSE);
name = vfs_s_fullpath (&sftpfs_class, file_handler->ino); name = vfs_s_fullpath (&sftpfs_class, file_handler->ino);
if (name == NULL) if (name == NULL)
@ -135,7 +138,7 @@ sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode, GEr
libssh_errno = libssh2_session_last_errno (super_data->session); libssh_errno = libssh2_session_last_errno (super_data->session);
if (libssh_errno != LIBSSH2_ERROR_EAGAIN) if (libssh_errno != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, libssh_errno, error); sftpfs_ssherror_to_gliberror (super_data, libssh_errno, mcerror);
g_free (name); g_free (name);
g_free (file_handler_data); g_free (file_handler_data);
return FALSE; return FALSE;
@ -152,7 +155,7 @@ sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode, GEr
{ {
struct stat file_info; struct stat file_info;
if (sftpfs_fstat (file_handler, &file_info, error) == 0) if (sftpfs_fstat (file_handler, &file_info, mcerror) == 0)
libssh2_sftp_seek64 (file_handler_data->handle, file_info.st_size); libssh2_sftp_seek64 (file_handler_data->handle, file_info.st_size);
} }
return TRUE; return TRUE;
@ -162,14 +165,14 @@ sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode, GEr
/** /**
* Stats the file specified by the file descriptor. * Stats the file specified by the file descriptor.
* *
* @param data file data handler * @param data file data handler
* @param buf buffer for store stat-info * @param buf buffer for store stat-info
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* @return 0 if success, negative value otherwise * @return 0 if success, negative value otherwise
*/ */
int int
sftpfs_fstat (void *data, struct stat *buf, GError ** error) sftpfs_fstat (void *data, struct stat *buf, GError ** mcerror)
{ {
int res; int res;
LIBSSH2_SFTP_ATTRIBUTES attrs; LIBSSH2_SFTP_ATTRIBUTES attrs;
@ -178,6 +181,8 @@ sftpfs_fstat (void *data, struct stat *buf, GError ** error)
struct vfs_s_super *super = fh->ino->super; struct vfs_s_super *super = fh->ino->super;
sftpfs_super_data_t *super_data = (sftpfs_super_data_t *) super->data; sftpfs_super_data_t *super_data = (sftpfs_super_data_t *) super->data;
mc_return_val_if_error (mcerror, -1);
if (sftpfs_fh->handle == NULL) if (sftpfs_fh->handle == NULL)
return -1; return -1;
@ -189,13 +194,12 @@ sftpfs_fstat (void *data, struct stat *buf, GError ** error)
if (res != LIBSSH2_ERROR_EAGAIN) if (res != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, res, error); sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, -1);
return -1;
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -226,23 +230,26 @@ sftpfs_fstat (void *data, struct stat *buf, GError ** error)
* Read up to 'count' bytes from the file descriptor 'file_handler' to the buffer starting at 'buffer'. * Read up to 'count' bytes from the file descriptor 'file_handler' to the buffer starting at 'buffer'.
* *
* @param file_handler file data handler * @param file_handler file data handler
* @param buffer buffer for data * @param buffer buffer for data
* @param count data size * @param count data size
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* *
* @return 0 on success, negative value otherwise * @return 0 on success, negative value otherwise
*/ */
ssize_t ssize_t
sftpfs_read_file (vfs_file_handler_t * file_handler, char *buffer, size_t count, GError ** error) sftpfs_read_file (vfs_file_handler_t * file_handler, char *buffer, size_t count, GError ** mcerror)
{ {
ssize_t rc; ssize_t rc;
sftpfs_file_handler_data_t *file_handler_data; sftpfs_file_handler_data_t *file_handler_data;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
mc_return_val_if_error (mcerror, -1);
if (file_handler == NULL || file_handler->data == NULL) if (file_handler == NULL || file_handler->data == NULL)
{ {
g_set_error (error, MC_ERROR, -1, _("sftp: No file handler data present for reading file")); mc_propagate_error (mcerror, -1, "%s",
_("sftp: No file handler data present for reading file"));
return -1; return -1;
} }
@ -257,13 +264,12 @@ sftpfs_read_file (vfs_file_handler_t * file_handler, char *buffer, size_t count,
if (rc != LIBSSH2_ERROR_EAGAIN) if (rc != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, rc, error); sftpfs_ssherror_to_gliberror (super_data, rc, mcerror);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, -1);
return -1;
} }
while (rc == LIBSSH2_ERROR_EAGAIN); while (rc == LIBSSH2_ERROR_EAGAIN);
@ -280,19 +286,21 @@ sftpfs_read_file (vfs_file_handler_t * file_handler, char *buffer, size_t count,
* @param file_handler file data handler * @param file_handler file data handler
* @param buffer buffer for data * @param buffer buffer for data
* @param count data size * @param count data size
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* *
* @return 0 on success, negative value otherwise * @return 0 on success, negative value otherwise
*/ */
ssize_t ssize_t
sftpfs_write_file (vfs_file_handler_t * file_handler, const char *buffer, size_t count, sftpfs_write_file (vfs_file_handler_t * file_handler, const char *buffer, size_t count,
GError ** error) GError ** mcerror)
{ {
ssize_t rc; ssize_t rc;
sftpfs_file_handler_data_t *file_handler_data; sftpfs_file_handler_data_t *file_handler_data;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
mc_return_val_if_error (mcerror, -1);
file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data; file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data;
super_data = (sftpfs_super_data_t *) file_handler->ino->super->data; super_data = (sftpfs_super_data_t *) file_handler->ino->super->data;
@ -306,13 +314,12 @@ sftpfs_write_file (vfs_file_handler_t * file_handler, const char *buffer, size_t
if (rc != LIBSSH2_ERROR_EAGAIN) if (rc != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, rc, error); sftpfs_ssherror_to_gliberror (super_data, rc, mcerror);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, -1);
return -1;
} }
while (rc == LIBSSH2_ERROR_EAGAIN); while (rc == LIBSSH2_ERROR_EAGAIN);
@ -325,17 +332,17 @@ sftpfs_write_file (vfs_file_handler_t * file_handler, const char *buffer, size_t
* Close a file descriptor. * Close a file descriptor.
* *
* @param file_handler file data handler * @param file_handler file data handler
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* *
* @return 0 on success, negative value otherwise * @return 0 on success, negative value otherwise
*/ */
int int
sftpfs_close_file (vfs_file_handler_t * file_handler, GError ** error) sftpfs_close_file (vfs_file_handler_t * file_handler, GError ** mcerror)
{ {
sftpfs_file_handler_data_t *file_handler_data; sftpfs_file_handler_data_t *file_handler_data;
(void) error; mc_return_val_if_error (mcerror, -1);
file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data; file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data;
if (file_handler_data == NULL) if (file_handler_data == NULL)
@ -355,16 +362,18 @@ sftpfs_close_file (vfs_file_handler_t * file_handler, GError ** error)
* @param file_handler file data handler * @param file_handler file data handler
* @param offset file offset * @param offset file offset
* @param whence method of seek (at begin, at current, at end) * @param whence method of seek (at begin, at current, at end)
* @param error pointer to the error handler * @param mcerror pointer to the error handler
* *
* @return 0 on success, negative value otherwise * @return 0 on success, negative value otherwise
*/ */
off_t off_t
sftpfs_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GError ** error) sftpfs_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GError ** mcerror)
{ {
sftpfs_file_handler_data_t *file_handler_data; sftpfs_file_handler_data_t *file_handler_data;
mc_return_val_if_error (mcerror, 0);
switch (whence) switch (whence)
{ {
case SEEK_SET: case SEEK_SET:
@ -374,9 +383,8 @@ sftpfs_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GErro
badness." */ badness." */
if (file_handler->pos > offset || offset == 0) if (file_handler->pos > offset || offset == 0)
{ {
sftpfs_reopen (file_handler, error); sftpfs_reopen (file_handler, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, 0);
return 0;
} }
file_handler->pos = offset; file_handler->pos = offset;
break; break;
@ -386,9 +394,8 @@ sftpfs_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GErro
case SEEK_END: case SEEK_END:
if (file_handler->pos > file_handler->ino->st.st_size - offset) if (file_handler->pos > file_handler->ino->st.st_size - offset)
{ {
sftpfs_reopen (file_handler, error); sftpfs_reopen (file_handler, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, 0);
return 0;
} }
file_handler->pos = file_handler->ino->st.st_size - offset; file_handler->pos = file_handler->ino->st.st_size - offset;
break; break;

View File

@ -28,6 +28,7 @@
#include <errno.h> #include <errno.h>
#include "lib/global.h" #include "lib/global.h"
#include "lib/util.h"
#include "internal.h" #include "internal.h"
@ -46,45 +47,25 @@ GString *sftpfs_filename_buffer = NULL;
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/ /*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/**
* Show error message (if error have raised) and cleanup GError object.
*
* @param error pointer to object contains error message
* @return TRUE if error message was printed, FALSE otherwise
*/
gboolean
sftpfs_show_error (GError ** error)
{
if (error == NULL || *error == NULL)
return FALSE;
vfs_print_message ("(%d) %s", (*error)->code, (*error)->message);
g_error_free (*error);
*error = NULL;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/** /**
* Convert libssh error to GError object. * Convert libssh error to GError object.
* *
* @param super_data extra data for SFTP connection * @param super_data extra data for SFTP connection
* @param libssh_errno errno from libssh * @param libssh_errno errno from libssh
* @param error pointer to the error object * @param mcerror pointer to the error object
*/ */
void void
sftpfs_ssherror_to_gliberror (sftpfs_super_data_t * super_data, int libssh_errno, GError ** error) sftpfs_ssherror_to_gliberror (sftpfs_super_data_t * super_data, int libssh_errno, GError ** mcerror)
{ {
char *err = NULL; char *err = NULL;
int err_len; int err_len;
g_return_if_fail (error == NULL || *error == NULL); mc_return_if_error (mcerror);
libssh2_session_last_error (super_data->session, &err, &err_len, 1); libssh2_session_last_error (super_data->session, &err, &err_len, 1);
g_set_error (error, MC_ERROR, libssh_errno, "%s", err); mc_propagate_error (mcerror, libssh_errno, "%s", err);
g_free (err); g_free (err);
} }
@ -108,12 +89,12 @@ sftpfs_fix_filename (const char *file_name)
* Awaiting for any activity on socket. * Awaiting for any activity on socket.
* *
* @param super_data extra data for SFTP connection * @param super_data extra data for SFTP connection
* @param error unused * @param mcerror pointer to the error object
* @return 0 if success, negative value otherwise * @return 0 if success, negative value otherwise
*/ */
int int
sftpfs_waitsocket (sftpfs_super_data_t * super_data, GError ** error) sftpfs_waitsocket (sftpfs_super_data_t * super_data, GError ** mcerror)
{ {
struct timeval timeout = { 10, 0 }; struct timeval timeout = { 10, 0 };
fd_set fd; fd_set fd;
@ -121,7 +102,7 @@ sftpfs_waitsocket (sftpfs_super_data_t * super_data, GError ** error)
fd_set *readfd = NULL; fd_set *readfd = NULL;
int dir; int dir;
(void) error; mc_return_val_if_error (mcerror, -1);
FD_ZERO (&fd); FD_ZERO (&fd);
FD_SET (super_data->socket_handle, &fd); FD_SET (super_data->socket_handle, &fd);
@ -142,14 +123,14 @@ sftpfs_waitsocket (sftpfs_super_data_t * super_data, GError ** error)
/** /**
* Getting information about a symbolic link. * Getting information about a symbolic link.
* *
* @param vpath path to file, directory or symbolic link * @param vpath path to file, directory or symbolic link
* @param buf buffer for store stat-info * @param buf buffer for store stat-info
* @param error pointer to error object * @param mcerror pointer to error object
* @return 0 if success, negative value otherwise * @return 0 if success, negative value otherwise
*/ */
int int
sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** error) sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror)
{ {
struct vfs_s_super *super; struct vfs_s_super *super;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
@ -157,6 +138,8 @@ sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** error)
int res; int res;
const vfs_path_element_t *path_element; const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1); path_element = vfs_path_get_by_index (vpath, -1);
if (vfs_s_get_path (vpath, &super, 0) == NULL) if (vfs_s_get_path (vpath, &super, 0) == NULL)
@ -182,13 +165,12 @@ sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** error)
if (res != LIBSSH2_ERROR_EAGAIN) if (res != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, res, error); sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, -1);
return -1;
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -218,14 +200,14 @@ sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** error)
/** /**
* Getting information about a file or directory. * Getting information about a file or directory.
* *
* @param vpath path to file or directory * @param vpath path to file or directory
* @param buf buffer for store stat-info * @param buf buffer for store stat-info
* @param error pointer to error object * @param mcerror pointer to error object
* @return 0 if success, negative value otherwise * @return 0 if success, negative value otherwise
*/ */
int int
sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** error) sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror)
{ {
struct vfs_s_super *super; struct vfs_s_super *super;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
@ -233,6 +215,8 @@ sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** error)
int res; int res;
const vfs_path_element_t *path_element; const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1); path_element = vfs_path_get_by_index (vpath, -1);
if (vfs_s_get_path (vpath, &super, 0) == NULL) if (vfs_s_get_path (vpath, &super, 0) == NULL)
@ -259,13 +243,12 @@ sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** error)
if (res != LIBSSH2_ERROR_EAGAIN) if (res != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, res, error); sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, -1);
return -1;
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -296,21 +279,23 @@ sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** error)
/** /**
* Read value of a symbolic link. * Read value of a symbolic link.
* *
* @param vpath path to file or directory * @param vpath path to file or directory
* @param buf buffer for store stat-info * @param buf buffer for store stat-info
* @param size buffer size * @param size buffer size
* @param error pointer to error object * @param mcerror pointer to error object
* @return 0 if success, negative value otherwise * @return 0 if success, negative value otherwise
*/ */
int int
sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** error) sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** mcerror)
{ {
struct vfs_s_super *super; struct vfs_s_super *super;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
int res; int res;
const vfs_path_element_t *path_element; const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1); path_element = vfs_path_get_by_index (vpath, -1);
if (vfs_s_get_path (vpath, &super, 0) == NULL) if (vfs_s_get_path (vpath, &super, 0) == NULL)
@ -335,13 +320,12 @@ sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** err
if (res != LIBSSH2_ERROR_EAGAIN) if (res != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, res, error); sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, -1);
return -1;
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -352,14 +336,14 @@ sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** err
/** /**
* Create symlink to file or directory * Create symlink to file or directory
* *
* @param vpath1 path to file or directory * @param vpath1 path to file or directory
* @param vpath2 path to symlink * @param vpath2 path to symlink
* @param error pointer to error object * @param mcerror pointer to error object
* @return 0 if success, negative value otherwise * @return 0 if success, negative value otherwise
*/ */
int int
sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** error) sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** mcerror)
{ {
struct vfs_s_super *super; struct vfs_s_super *super;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
@ -368,6 +352,8 @@ sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError **
char *tmp_path; char *tmp_path;
int res; int res;
mc_return_val_if_error (mcerror, -1);
path_element2 = vfs_path_get_by_index (vpath2, -1); path_element2 = vfs_path_get_by_index (vpath2, -1);
if (vfs_s_get_path (vpath2, &super, 0) == NULL) if (vfs_s_get_path (vpath2, &super, 0) == NULL)
@ -399,13 +385,13 @@ sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError **
if (res != LIBSSH2_ERROR_EAGAIN) if (res != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, res, error); sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
g_free (tmp_path); g_free (tmp_path);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) if (mcerror != NULL && *mcerror != NULL)
{ {
g_free (tmp_path); g_free (tmp_path);
return -1; return -1;
@ -421,14 +407,14 @@ sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError **
/** /**
* Changes the permissions of the file. * Changes the permissions of the file.
* *
* @param vpath path to file or directory * @param vpath path to file or directory
* @param mode mode (see man 2 open) * @param mode mode (see man 2 open)
* @param error pointer to error object * @param mcerror pointer to error object
* @return 0 if success, negative value otherwise * @return 0 if success, negative value otherwise
*/ */
int int
sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** error) sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** mcerror)
{ {
struct vfs_s_super *super; struct vfs_s_super *super;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
@ -436,6 +422,8 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** error)
int res; int res;
const vfs_path_element_t *path_element; const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1); path_element = vfs_path_get_by_index (vpath, -1);
if (vfs_s_get_path (vpath, &super, 0) == NULL) if (vfs_s_get_path (vpath, &super, 0) == NULL)
@ -461,13 +449,12 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** error)
if (res != LIBSSH2_ERROR_EAGAIN) if (res != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, res, error); sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, -1);
return -1;
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -485,13 +472,12 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** error)
break; break;
else if (res != LIBSSH2_ERROR_EAGAIN) else if (res != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, res, error); sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, -1);
return -1;
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
return res; return res;
@ -501,19 +487,21 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** error)
/** /**
* Delete a name from the file system. * Delete a name from the file system.
* *
* @param vpath path to file or directory * @param vpath path to file or directory
* @param error pointer to error object * @param mcerror pointer to error object
* @return 0 if success, negative value otherwise * @return 0 if success, negative value otherwise
*/ */
int int
sftpfs_unlink (const vfs_path_t * vpath, GError ** error) sftpfs_unlink (const vfs_path_t * vpath, GError ** mcerror)
{ {
struct vfs_s_super *super; struct vfs_s_super *super;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
int res; int res;
const vfs_path_element_t *path_element; const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1); path_element = vfs_path_get_by_index (vpath, -1);
if (vfs_s_get_path (vpath, &super, 0) == NULL) if (vfs_s_get_path (vpath, &super, 0) == NULL)
@ -540,13 +528,12 @@ sftpfs_unlink (const vfs_path_t * vpath, GError ** error)
if (res != LIBSSH2_ERROR_EAGAIN) if (res != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, res, error); sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) mc_return_val_if_error (mcerror, -1);
return -1;
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -557,14 +544,14 @@ sftpfs_unlink (const vfs_path_t * vpath, GError ** error)
/** /**
* Rename a file, moving it between directories if required. * Rename a file, moving it between directories if required.
* *
* @param vpath1 path to source file or directory * @param vpath1 path to source file or directory
* @param vpath2 path to destination file or directory * @param vpath2 path to destination file or directory
* @param error pointer to error object * @param mcerror pointer to error object
* @return 0 if success, negative value otherwise * @return 0 if success, negative value otherwise
*/ */
int int
sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** error) sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** mcerror)
{ {
struct vfs_s_super *super; struct vfs_s_super *super;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
@ -573,6 +560,7 @@ sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** e
char *tmp_path; char *tmp_path;
int res; int res;
mc_return_val_if_error (mcerror, -1);
path_element2 = vfs_path_get_by_index (vpath2, -1); path_element2 = vfs_path_get_by_index (vpath2, -1);
if (vfs_s_get_path (vpath2, &super, 0) == NULL) if (vfs_s_get_path (vpath2, &super, 0) == NULL)
@ -603,13 +591,13 @@ sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** e
if (res != LIBSSH2_ERROR_EAGAIN) if (res != LIBSSH2_ERROR_EAGAIN)
{ {
sftpfs_ssherror_to_gliberror (super_data, res, error); sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
g_free (tmp_path); g_free (tmp_path);
return -1; return -1;
} }
sftpfs_waitsocket (super_data, error); sftpfs_waitsocket (super_data, mcerror);
if (error != NULL && *error != NULL) if (mcerror != NULL && *mcerror != NULL)
{ {
g_free (tmp_path); g_free (tmp_path);
return -1; return -1;

View File

@ -61,40 +61,39 @@ void sftpfs_init_subclass_callbacks (void);
void sftpfs_init_config_variables_patterns (void); void sftpfs_init_config_variables_patterns (void);
void sftpfs_deinit_config_variables_patterns (void); void sftpfs_deinit_config_variables_patterns (void);
gboolean sftpfs_show_error (GError ** error);
void sftpfs_ssherror_to_gliberror (sftpfs_super_data_t * super_data, int libssh_errno, void sftpfs_ssherror_to_gliberror (sftpfs_super_data_t * super_data, int libssh_errno,
GError ** error); GError ** mcerror);
int sftpfs_waitsocket (sftpfs_super_data_t * super_data, GError ** error); int sftpfs_waitsocket (sftpfs_super_data_t * super_data, GError ** mcerror);
const char *sftpfs_fix_filename (const char *file_name); const char *sftpfs_fix_filename (const char *file_name);
int sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** error); int sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror);
int sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** error); int sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror);
int sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** error); int sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** mcerror);
int sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** error); int sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** mcerror);
int sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** error); int sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** mcerror);
int sftpfs_unlink (const vfs_path_t * vpath, GError ** error); int sftpfs_unlink (const vfs_path_t * vpath, GError ** mcerror);
int sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** error); int sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** mcerror);
void sftpfs_fill_connection_data_from_config (struct vfs_s_super *super, GError ** error); void sftpfs_fill_connection_data_from_config (struct vfs_s_super *super, GError ** mcerror);
int sftpfs_open_connection (struct vfs_s_super *super, GError ** error); int sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror);
void sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message, void sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message,
GError ** error); GError ** mcerror);
void *sftpfs_opendir (const vfs_path_t * vpath, GError ** error); void *sftpfs_opendir (const vfs_path_t * vpath, GError ** mcerror);
void *sftpfs_readdir (void *data, GError ** error); void *sftpfs_readdir (void *data, GError ** mcerror);
int sftpfs_closedir (void *data, GError ** error); int sftpfs_closedir (void *data, GError ** mcerror);
int sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** error); int sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** mcerror);
int sftpfs_rmdir (const vfs_path_t * vpath, GError ** error); int sftpfs_rmdir (const vfs_path_t * vpath, GError ** mcerror);
gboolean sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode, gboolean sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode,
GError ** error); GError ** mcerror);
ssize_t sftpfs_read_file (vfs_file_handler_t * file_handler, char *buffer, size_t count, ssize_t sftpfs_read_file (vfs_file_handler_t * file_handler, char *buffer, size_t count,
GError ** error); GError ** mcerror);
ssize_t sftpfs_write_file (vfs_file_handler_t * file_handler, const char *buffer, size_t count, ssize_t sftpfs_write_file (vfs_file_handler_t * file_handler, const char *buffer, size_t count,
GError ** error); GError ** mcerror);
int sftpfs_close_file (vfs_file_handler_t * file_handler, GError ** error); int sftpfs_close_file (vfs_file_handler_t * file_handler, GError ** mcerror);
int sftpfs_fstat (void *data, struct stat *buf, GError ** error); int sftpfs_fstat (void *data, struct stat *buf, GError ** mcerror);
off_t sftpfs_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GError ** error); off_t sftpfs_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GError ** mcerror);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/

View File

@ -28,6 +28,7 @@
#include <errno.h> #include <errno.h>
#include "lib/global.h" #include "lib/global.h"
#include "lib/widget.h"
#include "lib/vfs/gc.h" #include "lib/vfs/gc.h"
#include "lib/tty/tty.h" /* tty_enable_interrupt_key () */ #include "lib/tty/tty.h" /* tty_enable_interrupt_key () */
@ -99,7 +100,7 @@ sftpfs_cb_open (const vfs_path_t * vpath, int flags, mode_t mode)
struct vfs_s_super *super; struct vfs_s_super *super;
const char *path_super; const char *path_super;
struct vfs_s_inode *path_inode; struct vfs_s_inode *path_inode;
GError *error = NULL; GError *mcerror = NULL;
gboolean is_changed = FALSE; gboolean is_changed = FALSE;
path_element = vfs_path_get_by_index (vpath, -1); path_element = vfs_path_get_by_index (vpath, -1);
@ -152,9 +153,9 @@ sftpfs_cb_open (const vfs_path_t * vpath, int flags, mode_t mode)
file_handler->linear = 0; file_handler->linear = 0;
file_handler->data = NULL; file_handler->data = NULL;
if (!sftpfs_open_file (file_handler, flags, mode, &error)) if (!sftpfs_open_file (file_handler, flags, mode, &mcerror))
{ {
sftpfs_show_error (&error); mc_error_message (&mcerror);
g_free (file_handler); g_free (file_handler);
return NULL; return NULL;
} }
@ -176,14 +177,14 @@ sftpfs_cb_open (const vfs_path_t * vpath, int flags, mode_t mode)
static void * static void *
sftpfs_cb_opendir (const vfs_path_t * vpath) sftpfs_cb_opendir (const vfs_path_t * vpath)
{ {
GError *error = NULL; GError *mcerror = NULL;
void *ret_value; void *ret_value;
/* reset interrupt flag */ /* reset interrupt flag */
tty_got_interrupt (); tty_got_interrupt ();
ret_value = sftpfs_opendir (vpath, &error); ret_value = sftpfs_opendir (vpath, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return ret_value; return ret_value;
} }
@ -198,7 +199,7 @@ sftpfs_cb_opendir (const vfs_path_t * vpath)
static void * static void *
sftpfs_cb_readdir (void *data) sftpfs_cb_readdir (void *data)
{ {
GError *error = NULL; GError *mcerror = NULL;
union vfs_dirent *sftpfs_dirent; union vfs_dirent *sftpfs_dirent;
if (tty_got_interrupt ()) if (tty_got_interrupt ())
@ -207,8 +208,8 @@ sftpfs_cb_readdir (void *data)
return NULL; return NULL;
} }
sftpfs_dirent = sftpfs_readdir (data, &error); sftpfs_dirent = sftpfs_readdir (data, &mcerror);
if (!sftpfs_show_error (&error)) if (!mc_error_message (&mcerror))
{ {
if (sftpfs_dirent != NULL) if (sftpfs_dirent != NULL)
vfs_print_message (_("sftp: (Ctrl-G break) Listing... %s"), sftpfs_dirent->dent.d_name); vfs_print_message (_("sftp: (Ctrl-G break) Listing... %s"), sftpfs_dirent->dent.d_name);
@ -231,10 +232,10 @@ static int
sftpfs_cb_closedir (void *data) sftpfs_cb_closedir (void *data)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
rc = sftpfs_closedir (data, &error); rc = sftpfs_closedir (data, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }
@ -251,10 +252,10 @@ static int
sftpfs_cb_lstat (const vfs_path_t * vpath, struct stat *buf) sftpfs_cb_lstat (const vfs_path_t * vpath, struct stat *buf)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
rc = sftpfs_lstat (vpath, buf, &error); rc = sftpfs_lstat (vpath, buf, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }
@ -271,10 +272,10 @@ static int
sftpfs_cb_stat (const vfs_path_t * vpath, struct stat *buf) sftpfs_cb_stat (const vfs_path_t * vpath, struct stat *buf)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
rc = sftpfs_stat (vpath, buf, &error); rc = sftpfs_stat (vpath, buf, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }
@ -291,10 +292,10 @@ static int
sftpfs_cb_fstat (void *data, struct stat *buf) sftpfs_cb_fstat (void *data, struct stat *buf)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
rc = sftpfs_fstat (data, buf, &error); rc = sftpfs_fstat (data, buf, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }
@ -312,10 +313,10 @@ static int
sftpfs_cb_readlink (const vfs_path_t * vpath, char *buf, size_t size) sftpfs_cb_readlink (const vfs_path_t * vpath, char *buf, size_t size)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
rc = sftpfs_readlink (vpath, buf, size, &error); rc = sftpfs_readlink (vpath, buf, size, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }
@ -350,10 +351,10 @@ static int
sftpfs_cb_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2) sftpfs_cb_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
rc = sftpfs_symlink (vpath1, vpath2, &error); rc = sftpfs_symlink (vpath1, vpath2, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }
@ -429,7 +430,7 @@ static ssize_t
sftpfs_cb_read (void *data, char *buffer, size_t count) sftpfs_cb_read (void *data, char *buffer, size_t count)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
vfs_file_handler_t *fh = (vfs_file_handler_t *) data; vfs_file_handler_t *fh = (vfs_file_handler_t *) data;
if (tty_got_interrupt ()) if (tty_got_interrupt ())
@ -438,8 +439,8 @@ sftpfs_cb_read (void *data, char *buffer, size_t count)
return 0; return 0;
} }
rc = sftpfs_read_file (fh, buffer, count, &error); rc = sftpfs_read_file (fh, buffer, count, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }
@ -457,11 +458,11 @@ static ssize_t
sftpfs_cb_write (void *data, const char *buf, size_t nbyte) sftpfs_cb_write (void *data, const char *buf, size_t nbyte)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
vfs_file_handler_t *fh = (vfs_file_handler_t *) data; vfs_file_handler_t *fh = (vfs_file_handler_t *) data;
rc = sftpfs_write_file (fh, buf, nbyte, &error); rc = sftpfs_write_file (fh, buf, nbyte, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }
@ -477,7 +478,7 @@ static int
sftpfs_cb_close (void *data) sftpfs_cb_close (void *data)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
struct vfs_s_super *super; struct vfs_s_super *super;
vfs_file_handler_t *file_handler = (vfs_file_handler_t *) data; vfs_file_handler_t *file_handler = (vfs_file_handler_t *) data;
@ -487,8 +488,8 @@ sftpfs_cb_close (void *data)
if (super->fd_usage == 0) if (super->fd_usage == 0)
vfs_stamp_create (&sftpfs_class, super); vfs_stamp_create (&sftpfs_class, super);
rc = sftpfs_close_file (file_handler, &error); rc = sftpfs_close_file (file_handler, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
if (file_handler->handle != -1) if (file_handler->handle != -1)
close (file_handler->handle); close (file_handler->handle);
@ -512,10 +513,10 @@ static int
sftpfs_cb_chmod (const vfs_path_t * vpath, mode_t mode) sftpfs_cb_chmod (const vfs_path_t * vpath, mode_t mode)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
rc = sftpfs_chmod (vpath, mode, &error); rc = sftpfs_chmod (vpath, mode, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }
@ -532,10 +533,10 @@ static int
sftpfs_cb_mkdir (const vfs_path_t * vpath, mode_t mode) sftpfs_cb_mkdir (const vfs_path_t * vpath, mode_t mode)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
rc = sftpfs_mkdir (vpath, mode, &error); rc = sftpfs_mkdir (vpath, mode, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }
@ -551,10 +552,10 @@ static int
sftpfs_cb_rmdir (const vfs_path_t * vpath) sftpfs_cb_rmdir (const vfs_path_t * vpath)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
rc = sftpfs_rmdir (vpath, &error); rc = sftpfs_rmdir (vpath, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }
@ -573,10 +574,10 @@ sftpfs_cb_lseek (void *data, off_t offset, int whence)
{ {
off_t ret_offset; off_t ret_offset;
vfs_file_handler_t *file_handler = (vfs_file_handler_t *) data; vfs_file_handler_t *file_handler = (vfs_file_handler_t *) data;
GError *error = NULL; GError *mcerror = NULL;
ret_offset = sftpfs_lseek (file_handler, offset, whence, &error); ret_offset = sftpfs_lseek (file_handler, offset, whence, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return ret_offset; return ret_offset;
} }
@ -592,10 +593,10 @@ static int
sftpfs_cb_unlink (const vfs_path_t * vpath) sftpfs_cb_unlink (const vfs_path_t * vpath)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
rc = sftpfs_unlink (vpath, &error); rc = sftpfs_unlink (vpath, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }
@ -612,10 +613,10 @@ static int
sftpfs_cb_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2) sftpfs_cb_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
{ {
int rc; int rc;
GError *error = NULL; GError *mcerror = NULL;
rc = sftpfs_rename (vpath1, vpath2, &error); rc = sftpfs_rename (vpath1, vpath2, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return rc; return rc;
} }

View File

@ -30,6 +30,7 @@
#include <string.h> /* memset() */ #include <string.h> /* memset() */
#include "lib/global.h" #include "lib/global.h"
#include "lib/widget.h"
#include "lib/vfs/utilvfs.h" #include "lib/vfs/utilvfs.h"
#include "internal.h" #include "internal.h"
@ -89,7 +90,7 @@ static int
sftpfs_cb_open_connection (struct vfs_s_super *super, sftpfs_cb_open_connection (struct vfs_s_super *super,
const vfs_path_t * vpath, const vfs_path_element_t * vpath_element) const vfs_path_t * vpath, const vfs_path_element_t * vpath_element)
{ {
GError *error = NULL; GError *mcerror = NULL;
sftpfs_super_data_t *sftpfs_super_data; sftpfs_super_data_t *sftpfs_super_data;
int ret_value; int ret_value;
@ -107,11 +108,10 @@ sftpfs_cb_open_connection (struct vfs_s_super *super,
super->data = sftpfs_super_data; super->data = sftpfs_super_data;
super->path_element = vfs_path_element_clone (vpath_element); super->path_element = vfs_path_element_clone (vpath_element);
sftpfs_fill_connection_data_from_config (super, &error); sftpfs_fill_connection_data_from_config (super, &mcerror);
if (error != NULL) if (mc_error_message (&mcerror))
{ {
vpath_element->class->verrno = error->code; vpath_element->class->verrno = mcerror->code;
sftpfs_show_error (&error);
return -1; return -1;
} }
@ -120,8 +120,8 @@ sftpfs_cb_open_connection (struct vfs_s_super *super,
vfs_s_new_inode (vpath_element->class, super, vfs_s_new_inode (vpath_element->class, super,
vfs_s_default_stat (vpath_element->class, S_IFDIR | 0755)); vfs_s_default_stat (vpath_element->class, S_IFDIR | 0755));
ret_value = sftpfs_open_connection (super, &error); ret_value = sftpfs_open_connection (super, &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
return ret_value; return ret_value;
} }
@ -136,11 +136,11 @@ sftpfs_cb_open_connection (struct vfs_s_super *super,
static void static void
sftpfs_cb_close_connection (struct vfs_class *me, struct vfs_s_super *super) sftpfs_cb_close_connection (struct vfs_class *me, struct vfs_s_super *super)
{ {
GError *error = NULL; GError *mcerror = NULL;
(void) me; (void) me;
sftpfs_close_connection (super, "Normal Shutdown", &error); sftpfs_close_connection (super, "Normal Shutdown", &mcerror);
sftpfs_show_error (&error); mc_error_message (&mcerror);
g_free (super->data); g_free (super->data);
} }