[Gnucash-changes] r13084 - gnucash/trunk - Fix overall and
".log"-specific file-retention issues: Bug#329670 (++).
Joshua Sled
jsled at cvs.gnucash.org
Thu Feb 2 21:09:29 EST 2006
Author: jsled
Date: 2006-02-02 21:09:29 -0500 (Thu, 02 Feb 2006)
New Revision: 13084
Trac: http://svn.gnucash.org/trac/changeset/13084
Modified:
gnucash/trunk/ChangeLog
gnucash/trunk/lib/libqof/qof/qofsession.c
gnucash/trunk/src/backend/file/gnc-backend-file.c
Log:
Fix overall and ".log"-specific file-retention issues: Bug#329670 (++).
Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog 2006-02-03 00:47:40 UTC (rev 13083)
+++ gnucash/trunk/ChangeLog 2006-02-03 02:09:29 UTC (rev 13084)
@@ -1,3 +1,12 @@
+2006-02-02 Joshua Sled <jsled at asynchronous.org>
+
+ * lib/libqof/qof/qofsession.c (qof_session_load_backend): get+load
+ backend configuration after creation.
+ * src/backend/file/gnc-backend-file.c (gnc_file_be_get_config):
+ fix configuration.
+ (gnc_file_be_remove_old_files): Add ".log" suffix to the
+ check for to-remove files. Bug#329670. Reformat.
+
2006-02-02 David Hampton <hampton at employees.org>
* src/register/register-core/numcell.c: Don't call g_utf8_strlen
Modified: gnucash/trunk/lib/libqof/qof/qofsession.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofsession.c 2006-02-03 00:47:40 UTC (rev 13083)
+++ gnucash/trunk/lib/libqof/qof/qofsession.c 2006-02-03 02:09:29 UTC (rev 13084)
@@ -888,7 +888,13 @@
continue;
}
/* Use the providers creation callback */
- session->backend = (*(prov->backend_new))();
+ session->backend = (*(prov->backend_new))();
+ /* Initialize be configuration. */
+ {
+ KvpFrame *config;
+ config = qof_backend_get_config(session->backend);
+ qof_backend_load_config(session->backend, config);
+ }
session->backend->provider = prov;
/* Tell the books about the backend that they'll be using. */
for (node=session->books; node; node=node->next)
Modified: gnucash/trunk/src/backend/file/gnc-backend-file.c
===================================================================
--- gnucash/trunk/src/backend/file/gnc-backend-file.c 2006-02-03 00:47:40 UTC (rev 13083)
+++ gnucash/trunk/src/backend/file/gnc-backend-file.c 2006-02-03 02:09:29 UTC (rev 13084)
@@ -57,6 +57,7 @@
#include "io-gncxml-v2.h"
#include "gnc-backend-api.h"
#include "gnc-backend-file.h"
+#include "gnc-gconf-utils.h"
#define GNC_BE_DAYS "file_retention_days"
#define GNC_BE_ZIP "file_compression"
@@ -66,49 +67,48 @@
static gint file_retention_days = 0;
static gboolean file_compression = FALSE;
-static void option_cb (QofBackendOption *option, gpointer data)
-{
- if(0 == safe_strcmp(GNC_BE_DAYS, option->option_name)) {
- file_retention_days = *(gint*)option->value;
- }
- if(0 == safe_strcmp(GNC_BE_ZIP, option->option_name)) {
- file_compression = (gboolean)qof_util_bool_to_int(option->value);
- }
-}
-
/* lookup the options and modify the frame */
static void
gnc_file_be_set_config(QofBackend *be, KvpFrame *config)
{
- qof_backend_option_foreach(config, option_cb, NULL);
+ gchar *temp;
+ g_return_if_fail(be != NULL);
+ g_return_if_fail(config != NULL);
+
+ file_retention_days = (gint)kvp_frame_get_gint64(config, GNC_BE_DAYS);
+ temp = kvp_frame_get_string(config, GNC_BE_ZIP);
+ file_compression = (gboolean)qof_util_bool_to_int(temp);
}
static KvpFrame*
gnc_file_be_get_config(QofBackend *be)
{
- QofBackendOption *option;
+ QofBackendOption *option;
+ gboolean compression;
- qof_backend_prepare_frame(be);
- option = g_new0(QofBackendOption, 1);
- option->option_name = GNC_BE_DAYS;
- option->description = _("Number of days to retain old files");
- option->tooltip = _("GnuCash keeps backups of old files. "
- "This setting specifies how long each is kept.");
- option->type = KVP_TYPE_GINT64;
- option->value = (gpointer)&file_retention_days;
- qof_backend_prepare_option(be, option);
- g_free(option);
- option = g_new0(QofBackendOption, 1);
- option->option_name = GNC_BE_ZIP;
- option->description = _("Compress output files?");
- option->tooltip = _("GnuCash can save data files with compression."
- " Enable this option to compress your data file. ");
- option->type = KVP_TYPE_STRING;
- if(file_compression) { option->value = (gpointer)"TRUE"; }
- else { option->value = (gpointer)"FALSE"; }
- qof_backend_prepare_option(be, option);
- g_free(option);
- return qof_backend_complete_frame(be);
+ qof_backend_prepare_frame(be);
+ option = g_new0(QofBackendOption, 1);
+ option->option_name = GNC_BE_DAYS;
+ option->description = _("Number of days to retain old files");
+ option->tooltip = _("GnuCash keeps backups of old files. "
+ "This setting specifies how long each is kept.");
+ option->type = KVP_TYPE_GINT64;
+ option->value = GINT_TO_POINTER((int)gnc_gconf_get_float("general", "retain_days", NULL));
+ qof_backend_prepare_option(be, option);
+ g_free(option);
+
+ option = g_new0(QofBackendOption, 1);
+ option->option_name = GNC_BE_ZIP;
+ option->description = _("Compress output files?");
+ option->tooltip = _("GnuCash can save data files with compression."
+ " Enable this option to compress your data file.");
+ option->type = KVP_TYPE_GINT64;
+ compression = gnc_gconf_get_bool("general", "file_compression", NULL);
+ option->value = GINT_TO_POINTER(file_compression ? TRUE : FALSE);
+ qof_backend_prepare_option(be, option);
+ g_free(option);
+
+ return qof_backend_complete_frame(be);
}
/* ================================================================= */
@@ -425,15 +425,16 @@
static QofBookFileType
gnc_file_be_determine_file_type(const char *path)
{
- if(gnc_is_xml_data_file_v2(path)) {
- return GNC_BOOK_XML2_FILE;
- } else if(gnc_is_xml_data_file(path)) {
- return GNC_BOOK_XML1_FILE;
- } else if(is_gzipped_file(path)) {
- return GNC_BOOK_XML2_FILE;
- }
- else if(gnc_is_bin_file(path)) { return GNC_BOOK_BIN_FILE; }
- return GNC_BOOK_NOT_OURS;
+ if (gnc_is_xml_data_file_v2(path)) {
+ return GNC_BOOK_XML2_FILE;
+ } else if (gnc_is_xml_data_file(path)) {
+ return GNC_BOOK_XML1_FILE;
+ } else if (is_gzipped_file(path)) {
+ return GNC_BOOK_XML2_FILE;
+ } else if (gnc_is_bin_file(path)) {
+ return GNC_BOOK_BIN_FILE;
+ }
+ return GNC_BOOK_NOT_OURS;
}
static gboolean
@@ -728,13 +729,13 @@
file_time = mktime(&file_tm);
days = (int)(difftime(now, file_time) / 86400);
- /* Make sure this file actually has a date before unlinking */
- if (res && res != name+pathlen+1 &&
- /* We consumed some but not all of the filename */
- !strcmp(res, ".xac") &&
- file_time > 0 &&
- /* we actually have a reasonable time and it is old enough */
- days > file_retention_days)
+
+ if (res
+ && res != name+pathlen+1
+ && (strcmp(res, ".xac") == 0
+ || strcmp(res, ".log") == 0)
+ && file_time > 0
+ && days > file_retention_days)
{
PINFO ("unlink stale (%d days old) file: %s", days, name);
unlink(name);
@@ -877,7 +878,7 @@
gboolean rc;
FileBackend *be = (FileBackend *) bend;
- error = ERR_BACKEND_NO_ERR;
+ error = ERR_BACKEND_NO_ERR;
be->primary_book = book;
switch (gnc_file_be_determine_file_type(be->fullpath))
More information about the gnucash-changes
mailing list