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

View File

@ -27,6 +27,7 @@
#include <config.h>
#include "lib/global.h"
#include "lib/util.h"
#include "lib/event.h"
#include "internal.h"
@ -68,12 +69,12 @@ mc_event_add (const gchar * event_group_name, const gchar * event_name,
GPtrArray *callbacks;
mc_event_callback_t *cb;
mc_return_val_if_error (mcerror, FALSE);
if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL
|| event_callback == NULL)
{
g_propagate_error (mcerror,
g_error_new (MC_ERROR, 1,
_("Check input data! Some of parameters are NULL!")));
mc_propagate_error (mcerror, 1, "%s", _("Check input data! Some of parameters are NULL!"));
return FALSE;
}
@ -159,6 +160,8 @@ mc_event_get_event_group_by_name (const gchar * event_group_name, gboolean creat
{
GTree *event_group;
mc_return_val_if_error (mcerror, FALSE);
event_group = (GTree *) g_tree_lookup (mc_event_grouplist, (gconstpointer) event_group_name);
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);
if (event_group == NULL)
{
g_propagate_error (mcerror,
g_error_new (MC_ERROR, 1,
_("Unable to create group '%s' for events!"),
event_group_name));
mc_propagate_error (mcerror, 1, _("Unable to create group '%s' for events!"),
event_group_name);
return NULL;
}
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;
mc_return_val_if_error (mcerror, FALSE);
callbacks = (GPtrArray *) g_tree_lookup (event_group, (gconstpointer) event_name);
if (callbacks == NULL && create_new)
{
callbacks = g_ptr_array_new ();
if (callbacks == NULL)
{
g_propagate_error (mcerror,
g_error_new (MC_ERROR, 1,
_("Unable to create event '%s'!"), event_name));
mc_propagate_error (mcerror, 1, _("Unable to create event '%s'!"), event_name);
return NULL;
}
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) */
/* --------------------------------------------------------------------------------------------- */
#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
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;
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;
vfs_path_t *ini_vpath;
mc_return_val_if_error (mcerror, FALSE);
data = g_key_file_to_data (mc_config->handle, &len, NULL);
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);
return ret;
}
@ -73,7 +75,7 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path,
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);
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)
{
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;
}
@ -261,25 +263,27 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean r
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
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)
{
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
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)
{
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
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)) &&
(g_mkdir_with_parents (directory_name, 0700) != 0))
{
g_propagate_error (error,
g_error_new (MC_ERROR, 0, _("Cannot create %s directory"),
directory_name));
}
mc_propagate_error (mcerror, 0, _("Cannot create %s directory"), directory_name);
}
/* --------------------------------------------------------------------------------------------- */
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;
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_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);
if (error != NULL && *error != NULL)
mc_config_mkdir (full_path, mcerror);
if (mcerror != NULL && *mcerror != NULL)
{
g_free (full_path);
full_path = NULL;
@ -187,15 +186,17 @@ mc_config_get_deprecated_path (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))
{
char *contents = NULL;
size_t length;
if (g_file_get_contents (old_name, &contents, &length, error))
g_file_set_contents (new_name, contents, length, error);
if (g_file_get_contents (old_name, &contents, &length, mcerror))
g_file_set_contents (new_name, contents, length, mcerror);
g_free (contents);
return;
@ -207,18 +208,16 @@ mc_config_copy (const char *old_name, const char *new_name, GError ** error)
GDir *dir;
const char *dir_name;
dir = g_dir_open (old_name, 0, error);
dir = g_dir_open (old_name, 0, mcerror);
if (dir == NULL)
return;
if (g_mkdir_with_parents (new_name, 0700) == -1)
{
g_dir_close (dir);
g_propagate_error (error,
g_error_new (MC_ERROR, 0,
_
("An error occurred while migrating user settings: %s"),
unix_error_string (errno)));
mc_propagate_error (mcerror, 0,
_("An error occurred while migrating user settings: %s"),
unix_error_string (errno));
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);
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 (old_name2);
}
@ -286,10 +285,12 @@ mc_config_deprecated_dir_present (void)
/* --------------------------------------------------------------------------------------------- */
void
mc_config_init_config_paths (GError ** error)
mc_config_init_config_paths (GError ** mcerror)
{
char *dir;
mc_return_if_error (mcerror);
if (xdg_vars_initialized)
return;
@ -300,46 +301,46 @@ mc_config_init_config_paths (GError ** error)
if (mc_home != 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);
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);
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);
}
else
{
dir = (char *) g_get_user_config_dir ();
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
{
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);
}
dir = (char *) g_get_user_cache_dir ();
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
{
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);
}
dir = (char *) g_get_user_data_dir ();
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
{
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);
}
}
@ -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);
}
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);
#endif /* MC_HOMEDIR_XDG */
@ -439,24 +440,25 @@ mc_config_get_path (void)
/* --------------------------------------------------------------------------------------------- */
gboolean
mc_config_migrate_from_old_place (GError ** error, char **msg)
mc_config_migrate_from_old_place (GError ** mcerror, char **msg)
{
char *old_dir;
size_t rule_index;
mc_return_val_if_error (mcerror, FALSE);
if (!mc_config_deprecated_dir_present ())
return FALSE;
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
g_free (mc_config_init_one_config_path (mc_cache_str, EDIT_DIR, error));
g_free (mc_config_init_one_config_path (mc_data_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, mcerror));
#endif /* MC_HOMEDIR_XDG */
if (*error != NULL)
return FALSE;
mc_return_val_if_error (mcerror, FALSE);
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;
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 (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)
{
#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,
&lc_mc_search->regex_match_info, &error))
&lc_mc_search->regex_match_info, &mcerror))
{
g_match_info_free (lc_mc_search->regex_match_info);
lc_mc_search->regex_match_info = NULL;
if (error)
if (mcerror != NULL)
{
lc_mc_search->error = MC_SEARCH_E_REGEX;
lc_mc_search->error_str =
str_conv_gerror_message (error, _("Regular expression error"));
g_error_free (error);
str_conv_gerror_message (mcerror, _("Regular expression error"));
g_error_free (mcerror);
return COND__FOUND_ERROR;
}
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)
{
#ifdef SEARCH_TYPE_GLIB
GError *error = NULL;
GError *mcerror = NULL;
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 =
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_str = str_conv_gerror_message (error, _("Regular expression error"));
g_error_free (error);
lc_mc_search->error_str = str_conv_gerror_message (mcerror, _("Regular expression error"));
g_error_free (mcerror);
return;
}
#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);
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;

View File

@ -29,6 +29,7 @@
#include <stdlib.h>
#include "internal.h"
#include "lib/util.h"
#include "lib/tty/color.h" /* tty_use_256colors(); */
@ -110,10 +111,12 @@ mc_skin_try_to_load_default (void)
/* --------------------------------------------------------------------------------------------- */
gboolean
mc_skin_init (const gchar * skin_override, GError ** error)
mc_skin_init (const gchar * skin_override, GError ** mcerror)
{
gboolean is_good_init = TRUE;
mc_return_val_if_error (mcerror, FALSE);
mc_skin__default.have_256_colors = FALSE;
mc_skin__default.name =
@ -123,10 +126,9 @@ mc_skin_init (const gchar * skin_override, GError ** error)
g_free, mc_skin_hash_destroy_value);
if (!mc_skin_ini_file_load (&mc_skin__default))
{
*error = g_error_new (MC_ERROR, 0,
_("Unable to load '%s' skin.\nDefault skin has been loaded"),
mc_skin__default.name);
mc_propagate_error (mcerror, 0,
_("Unable to load '%s' skin.\nDefault skin has been loaded"),
mc_skin__default.name);
mc_skin_try_to_load_default ();
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 (*error == NULL)
*error = g_error_new (MC_ERROR, 0,
_("Unable to parse '%s' skin.\nDefault skin has been loaded"),
mc_skin__default.name);
mc_propagate_error (mcerror, 0,
_("Unable to parse '%s' skin.\nDefault skin has been loaded"),
mc_skin__default.name);
mc_skin_try_to_load_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 (*error == NULL)
*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"),
mc_skin__default.name);
mc_propagate_error (mcerror, 0,
_
("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_try_to_load_default ();
mc_skin_colors_old_configure (&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)
{
gchar *tmp_buff;
GError *error = NULL;
GError *mcerror = NULL;
tmp_buff = g_convert_with_iconv ((const gchar *) string,
left, coder, &bytes_read, &bytes_written, &error);
if (error != NULL)
left, coder, &bytes_read, &bytes_written, &mcerror);
if (mcerror != NULL)
{
int code = error->code;
int code = mcerror->code;
g_error_free (error);
error = NULL;
g_error_free (mcerror);
mcerror = NULL;
switch (code)
{
@ -234,9 +234,9 @@ str_nconvert (GIConv coder, const char *string, int size, GString * buffer)
}
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

View File

@ -198,7 +198,7 @@ str_8bit_length2 (const char *text, int size)
}
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;
gchar *ret;
@ -214,7 +214,7 @@ str_8bit_conv_gerror_message (GError * error, const char *def_msg)
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);
else
{

View File

@ -164,11 +164,11 @@ str_ascii_length2 (const char *text, int size)
}
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() */
if (error != NULL)
return g_strdup (error->message);
if (mcerror != NULL)
return g_strdup (mcerror->message);
return g_strdup (def_msg != NULL ? def_msg : "");
}

View File

@ -333,10 +333,10 @@ str_utf8_length_noncomb (const char *text)
*/
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)
return g_strdup (error->message);
if (mcerror != NULL)
return g_strdup (mcerror->message);
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_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 ***************************************************************************************/
/* Pathname canonicalization */
@ -200,6 +204,9 @@ char *guess_message_value (void);
char *mc_build_filename (const char *first_element, ...);
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 **************************************************/
static inline gboolean

View File

@ -1084,15 +1084,17 @@ vfs_path_change_encoding (vfs_path_t * vpath, const char *encoding)
*/
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;
ssize_t element_index;
char *ret_value;
mc_return_val_if_error (mcerror, FALSE);
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;
}
@ -1124,7 +1126,7 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
g_free (groupname);
}
ret_value = mc_serialize_config (cpath, error);
ret_value = mc_serialize_config (cpath, mcerror);
mc_config_deinit (cpath);
return ret_value;
}
@ -1140,13 +1142,15 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
*/
vfs_path_t *
vfs_path_deserialize (const char *data, GError ** error)
vfs_path_deserialize (const char *data, GError ** mcerror)
{
mc_config_t *cpath;
size_t element_index = 0;
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)
return NULL;
@ -1173,7 +1177,7 @@ vfs_path_deserialize (const char *data, GError ** error)
{
g_free (element);
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);
mc_config_deinit (cpath);
return NULL;
@ -1205,7 +1209,7 @@ vfs_path_deserialize (const char *data, GError ** error)
if (vfs_path_elements_count (vpath) == 0)
{
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;
}
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);
}
/* --------------------------------------------------------------------------------------------- */
/** 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.

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, ...)
__attribute__ ((format (__printf__, 3, 4)));
gboolean mc_error_message (GError ** mcerror);
/*** inline functions ****************************************************************************/
#endif /* MC__WTOOLS_H */

View File

@ -82,9 +82,9 @@ char *mc_run_param1 = NULL;
/* forward declarations */
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,
gpointer data, GError ** error);
gpointer data, GError ** mcerror);
static GOptionContext *context;
@ -418,7 +418,7 @@ mc_args_add_extended_info_to_help (void)
/* --------------------------------------------------------------------------------------------- */
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)
{
GString *buffer;
@ -427,7 +427,7 @@ mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_
buffer = g_string_new ("");
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);
@ -440,12 +440,14 @@ mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_
/* --------------------------------------------------------------------------------------------- */
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) value;
(void) data;
(void) error;
mc_return_val_if_error (mcerror, FALSE);
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
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) data;
(void) error;
mc_return_val_if_error (mcerror, FALSE);
mc_global.mc_run_mode = MC_RUN_VIEWER;
mc_run_param0 = g_strdup (value);
@ -576,11 +580,13 @@ parse_mcedit_arguments (int argc, char **argv)
/* --------------------------------------------------------------------------------------------- */
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;
gboolean ok = TRUE;
mc_return_val_if_error (mcerror, FALSE);
_system_codepage = str_detect_termencoding ();
#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_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)
*error = g_error_new (MC_ERROR, 0, "%s\n", _("Arguments parse error!"));
if (*mcerror == NULL)
mc_propagate_error (mcerror, 0, "%s\n", _("Arguments parse error!"));
else
{
gchar *help_str;
@ -629,22 +634,19 @@ mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError *
help_str = g_strdup ("");
#endif
if (str_isutf8 (_system_codepage))
error2 = g_error_new ((*error)->domain, (*error)->code, "%s\n\n%s\n",
(*error)->message, help_str);
mc_replace_error (mcerror, (*mcerror)->code, "%s\n\n%s\n", (*mcerror)->message,
help_str);
else
{
gchar *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);
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 (help_str);
g_error_free (*error);
*error = error2;
}
ok = FALSE;
@ -696,11 +698,13 @@ mc_args_show_info (void)
/* --------------------------------------------------------------------------------------------- */
gboolean
mc_setup_by_args (int argc, char **argv, GError ** error)
mc_setup_by_args (int argc, char **argv, GError ** mcerror)
{
const char *base;
char *tmp;
mc_return_val_if_error (mcerror, FALSE);
if (mc_args__force_colors)
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);
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;
}
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)
{
*error = g_error_new (MC_ERROR, 0, "%s\n",
_("Two files are required to evoke the diffviewer."));
mc_propagate_error (mcerror, 0, "%s\n",
_("Two files are required to evoke the diffviewer."));
return FALSE;
}

View File

@ -44,9 +44,9 @@ extern char *mc_run_param1;
/*** 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_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_vpath_new (vfs_path_t * file_vpath, long line_number);

View File

@ -55,7 +55,7 @@
/* --------------------------------------------------------------------------------------------- */
gboolean
events_init (GError ** error)
events_init (GError ** mcerror)
{
/* *INDENT-OFF* */
event_init_t standard_events[] =
@ -77,10 +77,10 @@ events_init (GError ** error)
};
/* *INDENT-ON* */
if (!mc_event_init (error))
if (!mc_event_init (mcerror))
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
skin_apply (const gchar * skin_override)
{
GError *error = NULL;
GError *mcerror = NULL;
mc_skin_deinit ();
mc_skin_init (skin_override, &error);
mc_skin_init (skin_override, &mcerror);
mc_fhl_free (&mc_filehighlight);
mc_filehighlight = mc_fhl_new (TRUE);
dlg_set_default_colors ();
@ -535,11 +535,7 @@ skin_apply (const gchar * skin_override)
panel_init ();
repaint_screen ();
if (error != NULL)
{
message (D_ERROR, _("Warning"), "%s", error->message);
g_error_free (error);
}
mc_error_message (&mcerror);
}
/* --------------------------------------------------------------------------------------------- */

View File

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

View File

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

View File

@ -2413,7 +2413,7 @@ mark_file_left (WPanel * panel)
/* --------------------------------------------------------------------------------------------- */
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)
{
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
panel_select_files (WPanel *panel)
panel_select_files (WPanel * panel)
{
panel_select_unselect_files (panel, _("Select"), ":select_cmd: Select ", TRUE);
}
@ -2493,7 +2493,7 @@ panel_select_files (WPanel *panel)
/* --------------------------------------------------------------------------------------------- */
static void
panel_unselect_files (WPanel *panel)
panel_unselect_files (WPanel * panel)
{
panel_select_unselect_files (panel, _("Unselect"), ":unselect_cmd: Unselect ", FALSE);
}
@ -2501,7 +2501,7 @@ panel_unselect_files (WPanel *panel)
/* --------------------------------------------------------------------------------------------- */
static void
panel_select_invert_files (WPanel *panel)
panel_select_invert_files (WPanel * panel)
{
int i;

View File

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

View File

@ -1166,13 +1166,13 @@ save_config (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);
g_error_free (*error);
*error = NULL;
message (D_ERROR, MSG_ERROR, _("Cannot save file %s:\n%s"), filename, (*mcerror)->message);
g_error_free (*mcerror);
*mcerror = NULL;
}
}

View File

@ -141,7 +141,7 @@ void load_setup (void);
gboolean save_setup (gboolean save_options, gboolean save_panel_options);
void done_setup (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);

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 config_entity config entity structure
* @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
*/
static gboolean
sftpfs_fill_config_entity_from_config (FILE * ssh_config_handler,
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];
gboolean host_block_hit = FALSE;
gboolean pattern_block_hit = FALSE;
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->search_type = MC_SEARCH_T_REGEX;
host_regexp->is_case_sensitive = FALSE;
@ -221,9 +223,9 @@ sftpfs_fill_config_entity_from_config (FILE * ssh_config_handler,
{
if (errno != 0)
{
g_set_error (error, MC_ERROR, errno,
_("sftp: an error occurred while reading %s: %s"), SFTPFS_SSH_CONFIG,
strerror (errno));
mc_propagate_error (mcerror, errno,
_("sftp: an error occurred while reading %s: %s"),
SFTPFS_SSH_CONFIG, strerror (errno));
mc_search_free (host_regexp);
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.
*
* @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
*/
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;
FILE *ssh_config_handler;
char *config_filename;
mc_return_val_if_error (mcerror, FALSE);
config_entity = g_new0 (sftpfs_ssh_config_entity_t, 1);
config_entity->password_auth = TRUE;
config_entity->identities_only = FALSE;
@ -303,7 +307,7 @@ sftpfs_get_config_entity (const vfs_path_element_t * vpath_element, GError ** er
gboolean ok;
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);
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);
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;
@ -337,14 +341,16 @@ sftpfs_get_config_entity (const vfs_path_element_t * vpath_element, GError ** er
*/
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_ssh_config_entity_t *config_entity;
mc_return_if_error (mcerror);
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)
return;

View File

@ -58,28 +58,30 @@
/**
* Create socket to host.
*
* @param super connection data
* @param error pointer to the error handler
* @param super connection data
* @param mcerror pointer to the error handler
* @return socket descriptor number, -1 if any error was occurred
*/
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;
int my_socket = 0;
char port[BUF_TINY];
int e;
mc_return_val_if_error (mcerror, -1);
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;
}
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;
}
@ -109,7 +111,7 @@ sftpfs_open_socket (struct vfs_s_super *super, GError ** error)
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;
goto ret;
}
@ -136,10 +138,10 @@ sftpfs_open_socket (struct vfs_s_super *super, GError ** error)
close (my_socket);
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)
g_set_error (error, MC_ERROR, -1, _("sftp: connection to server failed: %s"),
unix_error_string (errno));
mc_propagate_error (mcerror, -1, _("sftp: connection to server failed: %s"),
unix_error_string (errno));
else
continue;
@ -193,19 +195,19 @@ sftpfs_recognize_auth_types (struct vfs_s_super *super)
/**
* Open connection to host using SSH-agent helper.
*
* @param super connection data
* @param error pointer to the error handler
* @param super connection data
* @param mcerror pointer to the error handler
* @return TRUE if connection was successfully opened, FALSE otherwise
*/
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;
struct libssh2_agent_publickey *identity, *prev_identity = NULL;
int rc;
(void) error;
mc_return_val_if_error (mcerror, FALSE);
super_data = (sftpfs_super_data_t *) super->data;
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.
*
* @param super connection data
* @param error pointer to the error handler
* @param super connection data
* @param mcerror pointer to the error handler
* @return TRUE if connection was successfully opened, FALSE otherwise
*/
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;
char *p, *passwd;
gboolean ret_value = FALSE;
mc_return_val_if_error (mcerror, FALSE);
super_data = (sftpfs_super_data_t *) super->data;
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);
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
{
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.
*
* @param super connection data
* @param error pointer to the error handler
* @param super connection data
* @param mcerror pointer to the error handler
* @return TRUE if connection was successfully opened, FALSE otherwise
*/
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;
char *p, *passwd;
gboolean ret_value = FALSE;
int rc;
mc_return_val_if_error (mcerror, FALSE);
super_data = (sftpfs_super_data_t *) super->data;
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);
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
{
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.
*
* @param super connection data
* @param error pointer to the error handler
* @param super connection data
* @param mcerror pointer to the error handler
* @return 0 if success, -1 otherwise
*/
int
sftpfs_open_connection (struct vfs_s_super *super, GError ** error)
sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror)
{
int rc;
sftpfs_super_data_t *super_data;
mc_return_val_if_error (mcerror, -1);
super_data = (sftpfs_super_data_t *) super->data;
/* Create a session instance */
super_data->session = libssh2_session_init ();
if (super_data->session == NULL)
return -1;
return (-1);
/*
* The application code is responsible for creating the socket
* 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)
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);
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);
}
@ -396,9 +404,9 @@ sftpfs_open_connection (struct vfs_s_super *super, GError ** error)
sftpfs_recognize_auth_types (super);
if (!sftpfs_open_connection_ssh_agent (super, error)
&& !sftpfs_open_connection_ssh_key (super, error)
&& !sftpfs_open_connection_ssh_password (super, error))
if (!sftpfs_open_connection_ssh_agent (super, mcerror)
&& !sftpfs_open_connection_ssh_key (super, mcerror)
&& !sftpfs_open_connection_ssh_password (super, mcerror))
return (-1);
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 shutdown_message message for shutdown functions
* @param error pointer to the error handler
* @param mcerror pointer to the error handler
*/
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;
(void) error;
mc_return_if_error (mcerror);
super_data = (sftpfs_super_data_t *) super->data;
if (super_data == NULL)

View File

@ -30,6 +30,7 @@
#include <libssh2_sftp.h>
#include "lib/global.h"
#include "lib/util.h"
#include "internal.h"
@ -56,13 +57,13 @@ typedef struct
/**
* Open a directory stream corresponding to the directory name.
*
* @param vpath path to directory
* @param error pointer to the error handler
* @param vpath path to directory
* @param mcerror pointer to the error handler
* @return directory data handler if success, NULL otherwise
*/
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;
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;
LIBSSH2_SFTP_HANDLE *handle;
mc_return_val_if_error (mcerror, NULL);
path_element = vfs_path_get_by_index (vpath, -1);
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);
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;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
return NULL;
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, NULL);
}
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.
*
* @param data directory data handler
* @param error pointer to the error handler
* @param data directory data handler
* @param mcerror pointer to the error handler
* @return information about direntry if success, NULL otherwise
*/
void *
sftpfs_readdir (void *data, GError ** error)
sftpfs_readdir (void *data, GError ** mcerror)
{
char mem[BUF_MEDIUM];
LIBSSH2_SFTP_ATTRIBUTES attrs;
@ -123,6 +126,8 @@ sftpfs_readdir (void *data, GError ** error)
static union vfs_dirent sftpfs_dirent;
int rc;
mc_return_val_if_error (mcerror, NULL);
do
{
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)
{
sftpfs_ssherror_to_gliberror (sftpfs_dir->super_data, rc, error);
sftpfs_ssherror_to_gliberror (sftpfs_dir->super_data, rc, mcerror);
return NULL;
}
sftpfs_waitsocket (sftpfs_dir->super_data, error);
if (error != NULL && *error != NULL)
return NULL;
sftpfs_waitsocket (sftpfs_dir->super_data, mcerror);
mc_return_val_if_error (mcerror, NULL);
}
while (rc == LIBSSH2_ERROR_EAGAIN);
@ -153,18 +157,18 @@ sftpfs_readdir (void *data, GError ** error)
/**
* Close the directory stream.
*
* @param data directory data handler
* @param error pointer to the error handler
* @param data directory data handler
* @param mcerror pointer to the error handler
* @return 0 if success, negative value otherwise
*/
int
sftpfs_closedir (void *data, GError ** error)
sftpfs_closedir (void *data, GError ** mcerror)
{
int rc;
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);
g_free (sftpfs_dir);
@ -175,20 +179,22 @@ sftpfs_closedir (void *data, GError ** error)
/**
* Create a new directory.
*
* @param vpath path directory
* @param mode mode (see man 2 open)
* @param error pointer to the error handler
* @param vpath path directory
* @param mode mode (see man 2 open)
* @param mcerror pointer to the error handler
* @return 0 if success, negative value otherwise
*/
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;
struct vfs_s_super *super;
sftpfs_super_data_t *super_data;
const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1);
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)
{
sftpfs_ssherror_to_gliberror (super_data, res, error);
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
return -1;
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
while (res == LIBSSH2_ERROR_EAGAIN);
@ -232,19 +237,21 @@ sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** error)
/**
* Remove a directory.
*
* @param vpath path directory
* @param error pointer to the error handler
* @param vpath path directory
* @param mcerror pointer to the error handler
* @return 0 if success, negative value otherwise
*/
int
sftpfs_rmdir (const vfs_path_t * vpath, GError ** error)
sftpfs_rmdir (const vfs_path_t * vpath, GError ** mcerror)
{
int res;
struct vfs_s_super *super;
sftpfs_super_data_t *super_data;
const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1);
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)
{
sftpfs_ssherror_to_gliberror (super_data, res, error);
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
return -1;
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
while (res == LIBSSH2_ERROR_EAGAIN);

View File

@ -30,6 +30,7 @@
#include <libssh2_sftp.h>
#include "lib/global.h"
#include "lib/util.h"
#include "internal.h"
@ -54,22 +55,23 @@ typedef struct
* Reopen file by file handle.
*
* @param file_handler the file handler data
* @param error pointer to the error handler
* @param mcerror pointer to the error handler
*/
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;
int flags;
mode_t mode;
g_return_if_fail (mcerror == NULL || *mcerror == NULL);
file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data;
flags = file_handler_data->flags;
mode = file_handler_data->mode;
sftpfs_close_file (file_handler, error);
if (error == NULL || *error == NULL)
sftpfs_open_file (file_handler, flags, mode, error);
sftpfs_close_file (file_handler, mcerror);
sftpfs_open_file (file_handler, flags, mode, mcerror);
}
/* --------------------------------------------------------------------------------------------- */
@ -81,12 +83,12 @@ sftpfs_reopen (vfs_file_handler_t * file_handler, GError ** error)
* @param file_handler the file handler data
* @param flags flags (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
*/
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;
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;
(void) mode;
mc_return_val_if_error (mcerror, FALSE);
name = vfs_s_fullpath (&sftpfs_class, file_handler->ino);
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);
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 (file_handler_data);
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;
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);
}
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.
*
* @param data file data handler
* @param buf buffer for store stat-info
* @param error pointer to the error handler
* @param data file data handler
* @param buf buffer for store stat-info
* @param mcerror pointer to the error handler
* @return 0 if success, negative value otherwise
*/
int
sftpfs_fstat (void *data, struct stat *buf, GError ** error)
sftpfs_fstat (void *data, struct stat *buf, GError ** mcerror)
{
int res;
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;
sftpfs_super_data_t *super_data = (sftpfs_super_data_t *) super->data;
mc_return_val_if_error (mcerror, -1);
if (sftpfs_fh->handle == NULL)
return -1;
@ -189,13 +194,12 @@ sftpfs_fstat (void *data, struct stat *buf, GError ** error)
if (res != LIBSSH2_ERROR_EAGAIN)
{
sftpfs_ssherror_to_gliberror (super_data, res, error);
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
return -1;
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
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'.
*
* @param file_handler file data handler
* @param buffer buffer for data
* @param count data size
* @param error pointer to the error handler
* @param buffer buffer for data
* @param count data size
* @param mcerror pointer to the error handler
*
* @return 0 on success, negative value otherwise
*/
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;
sftpfs_file_handler_data_t *file_handler_data;
sftpfs_super_data_t *super_data;
mc_return_val_if_error (mcerror, -1);
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;
}
@ -257,13 +264,12 @@ sftpfs_read_file (vfs_file_handler_t * file_handler, char *buffer, size_t count,
if (rc != LIBSSH2_ERROR_EAGAIN)
{
sftpfs_ssherror_to_gliberror (super_data, rc, error);
sftpfs_ssherror_to_gliberror (super_data, rc, mcerror);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
return -1;
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
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 buffer buffer for data
* @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
*/
ssize_t
sftpfs_write_file (vfs_file_handler_t * file_handler, const char *buffer, size_t count,
GError ** error)
GError ** mcerror)
{
ssize_t rc;
sftpfs_file_handler_data_t *file_handler_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;
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)
{
sftpfs_ssherror_to_gliberror (super_data, rc, error);
sftpfs_ssherror_to_gliberror (super_data, rc, mcerror);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
return -1;
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
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.
*
* @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
*/
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;
(void) error;
mc_return_val_if_error (mcerror, -1);
file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data;
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 offset file offset
* @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
*/
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;
mc_return_val_if_error (mcerror, 0);
switch (whence)
{
case SEEK_SET:
@ -374,9 +383,8 @@ sftpfs_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GErro
badness." */
if (file_handler->pos > offset || offset == 0)
{
sftpfs_reopen (file_handler, error);
if (error != NULL && *error != NULL)
return 0;
sftpfs_reopen (file_handler, mcerror);
mc_return_val_if_error (mcerror, 0);
}
file_handler->pos = offset;
break;
@ -386,9 +394,8 @@ sftpfs_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GErro
case SEEK_END:
if (file_handler->pos > file_handler->ino->st.st_size - offset)
{
sftpfs_reopen (file_handler, error);
if (error != NULL && *error != NULL)
return 0;
sftpfs_reopen (file_handler, mcerror);
mc_return_val_if_error (mcerror, 0);
}
file_handler->pos = file_handler->ino->st.st_size - offset;
break;

View File

@ -28,6 +28,7 @@
#include <errno.h>
#include "lib/global.h"
#include "lib/util.h"
#include "internal.h"
@ -46,45 +47,25 @@ GString *sftpfs_filename_buffer = NULL;
/* --------------------------------------------------------------------------------------------- */
/*** 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.
*
* @param super_data extra data for SFTP connection
* @param libssh_errno errno from libssh
* @param error pointer to the error object
* @param mcerror pointer to the error object
*/
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;
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);
g_set_error (error, MC_ERROR, libssh_errno, "%s", err);
mc_propagate_error (mcerror, libssh_errno, "%s", err);
g_free (err);
}
@ -108,12 +89,12 @@ sftpfs_fix_filename (const char *file_name)
* Awaiting for any activity on socket.
*
* @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
*/
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 };
fd_set fd;
@ -121,7 +102,7 @@ sftpfs_waitsocket (sftpfs_super_data_t * super_data, GError ** error)
fd_set *readfd = NULL;
int dir;
(void) error;
mc_return_val_if_error (mcerror, -1);
FD_ZERO (&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.
*
* @param vpath path to file, directory or symbolic link
* @param buf buffer for store stat-info
* @param error pointer to error object
* @param vpath path to file, directory or symbolic link
* @param buf buffer for store stat-info
* @param mcerror pointer to error object
* @return 0 if success, negative value otherwise
*/
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;
sftpfs_super_data_t *super_data;
@ -157,6 +138,8 @@ sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** error)
int res;
const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1);
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)
{
sftpfs_ssherror_to_gliberror (super_data, res, error);
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
return -1;
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
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.
*
* @param vpath path to file or directory
* @param buf buffer for store stat-info
* @param error pointer to error object
* @param vpath path to file or directory
* @param buf buffer for store stat-info
* @param mcerror pointer to error object
* @return 0 if success, negative value otherwise
*/
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;
sftpfs_super_data_t *super_data;
@ -233,6 +215,8 @@ sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** error)
int res;
const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1);
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)
{
sftpfs_ssherror_to_gliberror (super_data, res, error);
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
return -1;
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
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.
*
* @param vpath path to file or directory
* @param buf buffer for store stat-info
* @param size buffer size
* @param error pointer to error object
* @param vpath path to file or directory
* @param buf buffer for store stat-info
* @param size buffer size
* @param mcerror pointer to error object
* @return 0 if success, negative value otherwise
*/
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;
sftpfs_super_data_t *super_data;
int res;
const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1);
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)
{
sftpfs_ssherror_to_gliberror (super_data, res, error);
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
return -1;
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
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
*
* @param vpath1 path to file or directory
* @param vpath2 path to symlink
* @param error pointer to error object
* @param vpath1 path to file or directory
* @param vpath2 path to symlink
* @param mcerror pointer to error object
* @return 0 if success, negative value otherwise
*/
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;
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;
int res;
mc_return_val_if_error (mcerror, -1);
path_element2 = vfs_path_get_by_index (vpath2, -1);
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)
{
sftpfs_ssherror_to_gliberror (super_data, res, error);
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
g_free (tmp_path);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
sftpfs_waitsocket (super_data, mcerror);
if (mcerror != NULL && *mcerror != NULL)
{
g_free (tmp_path);
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.
*
* @param vpath path to file or directory
* @param mode mode (see man 2 open)
* @param error pointer to error object
* @param vpath path to file or directory
* @param mode mode (see man 2 open)
* @param mcerror pointer to error object
* @return 0 if success, negative value otherwise
*/
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;
sftpfs_super_data_t *super_data;
@ -436,6 +422,8 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** error)
int res;
const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1);
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)
{
sftpfs_ssherror_to_gliberror (super_data, res, error);
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
return -1;
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
while (res == LIBSSH2_ERROR_EAGAIN);
@ -485,13 +472,12 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** error)
break;
else if (res != LIBSSH2_ERROR_EAGAIN)
{
sftpfs_ssherror_to_gliberror (super_data, res, error);
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
return -1;
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
while (res == LIBSSH2_ERROR_EAGAIN);
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.
*
* @param vpath path to file or directory
* @param error pointer to error object
* @param vpath path to file or directory
* @param mcerror pointer to error object
* @return 0 if success, negative value otherwise
*/
int
sftpfs_unlink (const vfs_path_t * vpath, GError ** error)
sftpfs_unlink (const vfs_path_t * vpath, GError ** mcerror)
{
struct vfs_s_super *super;
sftpfs_super_data_t *super_data;
int res;
const vfs_path_element_t *path_element;
mc_return_val_if_error (mcerror, -1);
path_element = vfs_path_get_by_index (vpath, -1);
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)
{
sftpfs_ssherror_to_gliberror (super_data, res, error);
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
return -1;
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
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.
*
* @param vpath1 path to source file or directory
* @param vpath2 path to destination file or directory
* @param error pointer to error object
* @param vpath1 path to source file or directory
* @param vpath2 path to destination file or directory
* @param mcerror pointer to error object
* @return 0 if success, negative value otherwise
*/
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;
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;
int res;
mc_return_val_if_error (mcerror, -1);
path_element2 = vfs_path_get_by_index (vpath2, -1);
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)
{
sftpfs_ssherror_to_gliberror (super_data, res, error);
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
g_free (tmp_path);
return -1;
}
sftpfs_waitsocket (super_data, error);
if (error != NULL && *error != NULL)
sftpfs_waitsocket (super_data, mcerror);
if (mcerror != NULL && *mcerror != NULL)
{
g_free (tmp_path);
return -1;

View File

@ -61,40 +61,39 @@ void sftpfs_init_subclass_callbacks (void);
void sftpfs_init_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,
GError ** error);
int sftpfs_waitsocket (sftpfs_super_data_t * super_data, GError ** error);
GError ** mcerror);
int sftpfs_waitsocket (sftpfs_super_data_t * super_data, GError ** mcerror);
const char *sftpfs_fix_filename (const char *file_name);
int sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** error);
int sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** error);
int sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** error);
int sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** error);
int sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** error);
int sftpfs_unlink (const vfs_path_t * vpath, GError ** error);
int sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, 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 ** mcerror);
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 ** mcerror);
int sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** mcerror);
int sftpfs_unlink (const vfs_path_t * vpath, GError ** mcerror);
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);
int sftpfs_open_connection (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 ** mcerror);
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_readdir (void *data, GError ** error);
int sftpfs_closedir (void *data, GError ** error);
int sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** error);
int sftpfs_rmdir (const vfs_path_t * vpath, GError ** error);
void *sftpfs_opendir (const vfs_path_t * vpath, GError ** mcerror);
void *sftpfs_readdir (void *data, GError ** mcerror);
int sftpfs_closedir (void *data, GError ** mcerror);
int sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** mcerror);
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,
GError ** error);
GError ** mcerror);
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,
GError ** error);
int sftpfs_close_file (vfs_file_handler_t * file_handler, GError ** error);
int sftpfs_fstat (void *data, struct stat *buf, GError ** error);
off_t sftpfs_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GError ** error);
GError ** mcerror);
int sftpfs_close_file (vfs_file_handler_t * file_handler, GError ** mcerror);
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 ** mcerror);
/*** inline functions ****************************************************************************/

View File

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

View File

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