mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Don't allow the user to open the current log file. Fixes #337211.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13824 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
3b9d56fe93
commit
a25c54896e
@ -1,5 +1,11 @@
|
||||
2006-04-21 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/import-export/log-replay/gnc-log-replay.c:
|
||||
* src/engine/TransLog.[ch]: Don't allow the user to open the
|
||||
current log file. This only produces a debug message because of
|
||||
the string freeze. Fixes #337211. Also add a filter for '*.log'
|
||||
to the file selection dialog.
|
||||
|
||||
* src/report/report-gnome/gnc-plugin-page-report.c:
|
||||
* src/gnome-utils/gnc-main-window.c: Don't allow a report page to
|
||||
be closed of it is in the process of reloading. Make the close
|
||||
|
@ -80,7 +80,8 @@
|
||||
|
||||
|
||||
static int gen_logs = 1;
|
||||
static FILE * trans_log = NULL;
|
||||
static FILE * trans_log = NULL; /**< current log file handle */
|
||||
static char * trans_log_name = NULL; /**< current log file name */
|
||||
static char * log_base_name = NULL;
|
||||
|
||||
/********************************************************************\
|
||||
@ -106,6 +107,28 @@ xaccLogSetBaseName (const char *basepath)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* See if the provided file name is that of the current log file.
|
||||
* Since the filename is generated with a time-stamp we can ignore the
|
||||
* directory path and avoid problems with worrying about any ".."
|
||||
* components in the path.
|
||||
*/
|
||||
gboolean
|
||||
xaccFileIsCurrentLog (const gchar *name)
|
||||
{
|
||||
gchar *base;
|
||||
gint result;
|
||||
|
||||
if (!name || !trans_log_name)
|
||||
return FALSE;
|
||||
|
||||
base = g_path_get_basename(name);
|
||||
result = (strcmp(base, trans_log_name) == 0);
|
||||
g_free(base);
|
||||
return result;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
@ -136,6 +159,11 @@ xaccOpenLog (void)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Save the log file name */
|
||||
if (trans_log_name)
|
||||
g_free (trans_log_name);
|
||||
trans_log_name = g_path_get_basename(filename);
|
||||
|
||||
g_free (filename);
|
||||
g_free (timestamp);
|
||||
|
||||
|
@ -76,6 +76,9 @@ void xaccLogDisable (void);
|
||||
*/
|
||||
void xaccLogSetBaseName (const char *);
|
||||
|
||||
/** Test a filename to see if it is the name of the current logfile */
|
||||
gboolean xaccFileIsCurrentLog (const gchar *name);
|
||||
|
||||
#endif /* XACC_TRANS_LOG_H */
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "Account.h"
|
||||
#include "Transaction.h"
|
||||
#include "TransactionP.h"
|
||||
#include "TransLog.h"
|
||||
#include "Scrub.h"
|
||||
#include "gnc-log-replay.h"
|
||||
#include "gnc-file.h"
|
||||
@ -519,7 +520,7 @@ void gnc_file_log_replay (void)
|
||||
if (default_dir == NULL)
|
||||
gnc_init_default_directory(&default_dir);
|
||||
selected_filename = gnc_file_dialog(_("Select a .log file to replay"),
|
||||
NULL,
|
||||
"*.log",
|
||||
default_dir,
|
||||
GNC_FILE_DIALOG_OPEN);
|
||||
|
||||
@ -531,11 +532,17 @@ void gnc_file_log_replay (void)
|
||||
|
||||
/*strncpy(file,selected_filename, 255);*/
|
||||
DEBUG("Filename found: %s",selected_filename);
|
||||
|
||||
DEBUG("Opening selected file");
|
||||
log_file = fopen(selected_filename, "r");
|
||||
if(!log_file || ferror(log_file)!=0)
|
||||
{
|
||||
if (xaccFileIsCurrentLog(selected_filename)) {
|
||||
g_warning("Cannot open the current log file: %s", selected_filename);
|
||||
#ifdef STRING_FREEZE_ENDS
|
||||
gnc_error_dialog(NULL,
|
||||
_("Cannot open the current log file: %s"),
|
||||
selected_filename);
|
||||
#endif
|
||||
} else {
|
||||
DEBUG("Opening selected file");
|
||||
log_file = fopen(selected_filename, "r");
|
||||
if(!log_file || ferror(log_file)!=0) {
|
||||
int err = errno;
|
||||
perror("File open failed");
|
||||
gnc_error_dialog(NULL,
|
||||
@ -546,40 +553,31 @@ void gnc_file_log_replay (void)
|
||||
_("Failed to open log file: %s: %s"),
|
||||
selected_filename,
|
||||
strerror(err));
|
||||
}
|
||||
else
|
||||
{
|
||||
if((read_retval = fgets(read_buf,sizeof(read_buf),log_file)) == NULL)
|
||||
{
|
||||
} else {
|
||||
if((read_retval = fgets(read_buf,sizeof(read_buf),log_file)) == NULL) {
|
||||
DEBUG("Read error or EOF");
|
||||
gnc_info_dialog(NULL, "%s",
|
||||
_("The log file you selected was empty."));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strncmp(expected_header,read_buf,strlen(expected_header))!=0)
|
||||
{
|
||||
PERR("File header not recognised:\n%s",read_buf);
|
||||
PERR("Expected:\n%s",expected_header);
|
||||
gnc_error_dialog(NULL, "%s",
|
||||
_("The log file you selected cannot be read. "
|
||||
"The file header was not recognized."));
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
read_retval = fgets(read_buf,sizeof(read_buf),log_file);
|
||||
/*DEBUG("Chunk read: %s",read_retval);*/
|
||||
if(strncmp(record_start_str,read_buf,strlen(record_start_str))==0)/* If a record started */
|
||||
{
|
||||
process_trans_record(log_file);
|
||||
}
|
||||
}while(feof(log_file)==0);
|
||||
} else {
|
||||
if(strncmp(expected_header,read_buf,strlen(expected_header))!=0) {
|
||||
PERR("File header not recognised:\n%s",read_buf);
|
||||
PERR("Expected:\n%s",expected_header);
|
||||
gnc_error_dialog(NULL, "%s",
|
||||
_("The log file you selected cannot be read. "
|
||||
"The file header was not recognized."));
|
||||
} else {
|
||||
do {
|
||||
read_retval = fgets(read_buf,sizeof(read_buf),log_file);
|
||||
/*DEBUG("Chunk read: %s",read_retval);*/
|
||||
if(strncmp(record_start_str,read_buf,strlen(record_start_str))==0) {/* If a record started */
|
||||
process_trans_record(log_file);
|
||||
}
|
||||
}while(feof(log_file)==0);
|
||||
}
|
||||
}
|
||||
fclose(log_file);
|
||||
}
|
||||
}
|
||||
g_free(selected_filename);
|
||||
}
|
||||
g_free(default_dir);
|
||||
|
Loading…
Reference in New Issue
Block a user