[Gnucash-changes] r13824 - gnucash/trunk - Don't allow the user to open the current log file. Fixes #337211.

David Hampton hampton at cvs.gnucash.org
Fri Apr 21 20:57:03 EDT 2006


Author: hampton
Date: 2006-04-21 20:57:03 -0400 (Fri, 21 Apr 2006)
New Revision: 13824
Trac: http://svn.gnucash.org/trac/changeset/13824

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/engine/TransLog.c
   gnucash/trunk/src/engine/TransLog.h
   gnucash/trunk/src/import-export/log-replay/gnc-log-replay.c
Log:
Don't allow the user to open the current log file.  Fixes #337211.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-04-21 22:55:05 UTC (rev 13823)
+++ gnucash/trunk/ChangeLog	2006-04-22 00:57:03 UTC (rev 13824)
@@ -1,5 +1,11 @@
 2006-04-21  David Hampton  <hampton at 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

Modified: gnucash/trunk/src/engine/TransLog.c
===================================================================
--- gnucash/trunk/src/engine/TransLog.c	2006-04-21 22:55:05 UTC (rev 13823)
+++ gnucash/trunk/src/engine/TransLog.c	2006-04-22 00:57:03 UTC (rev 13824)
@@ -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 @@
    }
 }
 
+
+/*
+ * 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 @@
       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);
 

Modified: gnucash/trunk/src/engine/TransLog.h
===================================================================
--- gnucash/trunk/src/engine/TransLog.h	2006-04-21 22:55:05 UTC (rev 13823)
+++ gnucash/trunk/src/engine/TransLog.h	2006-04-22 00:57:03 UTC (rev 13824)
@@ -76,6 +76,9 @@
  */
 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 */
 /** @} */
 /** @} */

Modified: gnucash/trunk/src/import-export/log-replay/gnc-log-replay.c
===================================================================
--- gnucash/trunk/src/import-export/log-replay/gnc-log-replay.c	2006-04-21 22:55:05 UTC (rev 13823)
+++ gnucash/trunk/src/import-export/log-replay/gnc-log-replay.c	2006-04-22 00:57:03 UTC (rev 13824)
@@ -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 @@
   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 @@
 
       /*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 @@
 			   _("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 {
+	    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);
 		}
-	      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);
-		}
+	      }while(feof(log_file)==0);
 	    }
+	  }
 	  fclose(log_file);
 	}
+      }
       g_free(selected_filename);
     }
   g_free(default_dir);



More information about the gnucash-changes mailing list