r20400 - gnucash/trunk/src - Bug #642739 - Translog files being created in Gnucash program
Geert Janssens
gjanssens at code.gnucash.org
Sat Mar 12 10:44:39 EST 2011
Author: gjanssens
Date: 2011-03-12 10:44:39 -0500 (Sat, 12 Mar 2011)
New Revision: 20400
Trac: http://svn.gnucash.org/trac/changeset/20400
Modified:
gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
gnucash/trunk/src/core-utils/gnc-filepath-utils.c
gnucash/trunk/src/core-utils/gnc-filepath-utils.h
Log:
Bug #642739 - Translog files being created in Gnucash program
installation directory
Translog files for databases are now created in a directory "translog"
inside the .gnucash dir. The files will be named following this
scheme:
<dbtype>_<hostname>_<user>_<dbname>.<timestamp>.log
Modified: gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c 2011-03-12 09:36:38 UTC (rev 20399)
+++ gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c 2011-03-12 15:44:39 UTC (rev 20400)
@@ -29,6 +29,7 @@
#include "config.h"
#include <errno.h>
+#include <glib.h>
#include <glib/gstdio.h>
#if !HAVE_GMTIME_R
#include "gmtime_r.h"
@@ -47,6 +48,7 @@
#include "gnc-gconf-utils.h"
#include "gnc-uri-utils.h"
+#include "gnc-filepath-utils.h"
#include "gnc-locale-utils.h"
#include "gnc-backend-dbi.h"
@@ -339,6 +341,12 @@
}
be->sql_be.conn = create_dbi_connection( GNC_DBI_PROVIDER_SQLITE, qbe, be->conn );
be->sql_be.timespec_format = SQLITE3_TIMESPEC_STR_FORMAT;
+
+ /* We should now have a proper session set up.
+ * Let's start logging */
+ xaccLogSetBaseName (filepath);
+ PINFO ("logpath=%s", filepath ? filepath : "(null)");
+
exit:
if ( filepath != NULL ) g_free ( filepath );
if ( basename != NULL ) g_free( basename );
@@ -620,9 +628,7 @@
result = NULL;
}
return FALSE;
-}
-
-static void
+}static void
gnc_dbi_unlock( QofBackend *qbe )
{
GncDbiBackend *qe = (GncDbiBackend*)qbe;
@@ -722,6 +728,8 @@
gchar* dbname = NULL;
gchar* username = NULL;
gchar* password = NULL;
+ gchar* basename = NULL;
+ gchar* translog_path = NULL;
gint portnum = 0;
gint result;
gboolean success = FALSE;
@@ -872,11 +880,20 @@
}
be->sql_be.timespec_format = MYSQL_TIMESPEC_STR_FORMAT;
+ /* We should now have a proper session set up.
+ * Let's start logging */
+ basename = g_strjoin("_", protocol, host, username, dbname, NULL);
+ translog_path = gnc_build_translog_path (basename);
+ xaccLogSetBaseName (translog_path);
+ PINFO ("logpath=%s", translog_path ? translog_path : "(null)");
+
exit:
g_free( protocol );
g_free( host );
g_free( username );
g_free( password );
+ g_free( basename );
+ g_free( translog_path );
g_free( dbname );
LEAVE (" ");
@@ -984,6 +1001,8 @@
gchar *dbname = NULL, *dbnamelc = NULL;
gchar* username = NULL;
gchar* password = NULL;
+ gchar* basename = NULL;
+ gchar* translog_path = NULL;
gboolean success = FALSE;
gint portnum = 0;
@@ -1129,11 +1148,21 @@
be->sql_be.conn = create_dbi_connection( GNC_DBI_PROVIDER_PGSQL, qbe, be->conn );
}
be->sql_be.timespec_format = PGSQL_TIMESPEC_STR_FORMAT;
+
+ /* We should now have a proper session set up.
+ * Let's start logging */
+ basename = g_strjoin("_", protocol, host, username, dbname, NULL);
+ translog_path = gnc_build_translog_path (basename);
+ xaccLogSetBaseName (translog_path);
+ PINFO ("logpath=%s", translog_path ? translog_path : "(null)");
+
exit:
g_free( protocol );
g_free( host );
g_free( username );
g_free( password );
+ g_free( basename );
+ g_free( translog_path );
g_free( dbname );
g_free( dbnamelc );
@@ -1197,6 +1226,9 @@
{
g_return_if_fail( be != NULL );
+ /* Stop transaction logging */
+ xaccLogSetBaseName (NULL);
+
qof_backend_destroy( be );
g_free( be );
Modified: gnucash/trunk/src/core-utils/gnc-filepath-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-filepath-utils.c 2011-03-12 09:36:38 UTC (rev 20399)
+++ gnucash/trunk/src/core-utils/gnc-filepath-utils.c 2011-03-12 15:44:39 UTC (rev 20400)
@@ -310,6 +310,9 @@
tmp_dir = g_build_filename(dotgnucash, "checks", (gchar *)NULL);
gnc_validate_directory(tmp_dir);
g_free(tmp_dir);
+ tmp_dir = g_build_filename(dotgnucash, "translog", (gchar *)NULL);
+ gnc_validate_directory(tmp_dir);
+ g_free(tmp_dir);
return dotgnucash;
}
@@ -349,6 +352,27 @@
return result;
}
+/** @fn gchar * gnc_build_translog_path (const gchar *filename)
+ * @brief Make a path to filename in the translog subdirectory of the user's configuration directory.
+ *
+ * @param filename The name of the file
+ *
+ * @return An absolute path.
+ */
+
+gchar *
+gnc_build_translog_path (const gchar *filename)
+{
+ gchar* filename_dup = g_strdup(filename);
+ gchar* result = NULL;
+
+ scrub_filename(filename_dup);
+ result = g_build_filename(gnc_dotgnucash_dir(), "translog",
+ filename_dup, (gchar *)NULL);
+ g_free(filename_dup);
+ return result;
+}
+
/** @fn gchar * gnc_build_data_path (const gchar *filename)
* @brief Make a path to filename in the data subdirectory of the user's configuration directory.
*
Modified: gnucash/trunk/src/core-utils/gnc-filepath-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-filepath-utils.h 2011-03-12 09:36:38 UTC (rev 20399)
+++ gnucash/trunk/src/core-utils/gnc-filepath-utils.h 2011-03-12 15:44:39 UTC (rev 20400)
@@ -44,6 +44,7 @@
const gchar *gnc_dotgnucash_dir (void);
gchar *gnc_build_dotgnucash_path (const gchar *filename);
gchar *gnc_build_book_path (const gchar *filename);
+gchar *gnc_build_translog_path (const gchar *filename);
gchar *gnc_build_data_path (const gchar *filename);
gchar *gnc_build_report_path (const gchar *filename);
gchar *gnc_build_stdreports_path (const gchar *filename);
More information about the gnucash-changes
mailing list