mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
Rewrite gfec_eval_file to avoid opening the file itself in guile
This is a continuation of Bug 711567 - Cannot save a custom report if a path contain diacritic chars However this commit deals with reading the file
This commit is contained in:
parent
db6c83cdb6
commit
2e4021978d
@ -151,41 +151,28 @@ gfec_eval_string(const char *str, gfec_error_handler error_handler)
|
||||
return result;
|
||||
}
|
||||
|
||||
static SCM
|
||||
gfec_file_helper(void *data)
|
||||
{
|
||||
char *string = data;
|
||||
|
||||
return scm_c_primitive_load(file);
|
||||
}
|
||||
|
||||
SCM
|
||||
gfec_eval_file(const char *file, gfec_error_handler error_handler)
|
||||
{
|
||||
char *err_msg = NULL;
|
||||
gchar *contents = NULL;
|
||||
GError *save_error = NULL;
|
||||
SCM result;
|
||||
|
||||
result = scm_internal_stack_catch(SCM_BOOL_T,
|
||||
gfec_file_helper,
|
||||
(void *) file,
|
||||
gfec_catcher,
|
||||
&err_msg);
|
||||
|
||||
if (err_msg != NULL)
|
||||
if (!g_file_get_contents (file, &contents, NULL, &save_error))
|
||||
{
|
||||
if (error_handler)
|
||||
{
|
||||
gchar *full_msg = g_strdup_printf("Could not load file %s: %s",
|
||||
file, err_msg);
|
||||
error_handler(full_msg);
|
||||
g_free(full_msg);
|
||||
}
|
||||
gchar *full_msg = g_strdup_printf ("Couldn't read contents of %s.\nReason: %s", file, save_error->message);
|
||||
error_handler(full_msg);
|
||||
|
||||
free(err_msg);
|
||||
g_error_free (save_error);
|
||||
g_free(full_msg);
|
||||
|
||||
return SCM_UNDEFINED;
|
||||
}
|
||||
|
||||
result = gfec_eval_string (contents, error_handler);
|
||||
g_free (contents);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user