Fix overall and ".log"-specific file-retention issues: Bug#329670 (++).

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13084 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Joshua Sled 2006-02-03 02:09:29 +00:00
parent b9724e3063
commit 0324351b44
3 changed files with 67 additions and 51 deletions

View File

@ -1,3 +1,12 @@
2006-02-02 Joshua Sled <jsled@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@employees.org> 2006-02-02 David Hampton <hampton@employees.org>
* src/register/register-core/numcell.c: Don't call g_utf8_strlen * src/register/register-core/numcell.c: Don't call g_utf8_strlen

View File

@ -889,6 +889,12 @@ qof_session_load_backend(QofSession * session, char * access_method)
} }
/* Use the providers creation callback */ /* 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; session->backend->provider = prov;
/* Tell the books about the backend that they'll be using. */ /* Tell the books about the backend that they'll be using. */
for (node=session->books; node; node=node->next) for (node=session->books; node; node=node->next)

View File

@ -57,6 +57,7 @@
#include "io-gncxml-v2.h" #include "io-gncxml-v2.h"
#include "gnc-backend-api.h" #include "gnc-backend-api.h"
#include "gnc-backend-file.h" #include "gnc-backend-file.h"
#include "gnc-gconf-utils.h"
#define GNC_BE_DAYS "file_retention_days" #define GNC_BE_DAYS "file_retention_days"
#define GNC_BE_ZIP "file_compression" #define GNC_BE_ZIP "file_compression"
@ -66,27 +67,24 @@ static QofLogModule log_module = GNC_MOD_BACKEND;
static gint file_retention_days = 0; static gint file_retention_days = 0;
static gboolean file_compression = FALSE; 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 */ /* lookup the options and modify the frame */
static void static void
gnc_file_be_set_config(QofBackend *be, KvpFrame *config) 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* static KvpFrame*
gnc_file_be_get_config(QofBackend *be) gnc_file_be_get_config(QofBackend *be)
{ {
QofBackendOption *option; QofBackendOption *option;
gboolean compression;
qof_backend_prepare_frame(be); qof_backend_prepare_frame(be);
option = g_new0(QofBackendOption, 1); option = g_new0(QofBackendOption, 1);
@ -95,19 +93,21 @@ gnc_file_be_get_config(QofBackend *be)
option->tooltip = _("GnuCash keeps backups of old files. " option->tooltip = _("GnuCash keeps backups of old files. "
"This setting specifies how long each is kept."); "This setting specifies how long each is kept.");
option->type = KVP_TYPE_GINT64; option->type = KVP_TYPE_GINT64;
option->value = (gpointer)&file_retention_days; option->value = GINT_TO_POINTER((int)gnc_gconf_get_float("general", "retain_days", NULL));
qof_backend_prepare_option(be, option); qof_backend_prepare_option(be, option);
g_free(option); g_free(option);
option = g_new0(QofBackendOption, 1); option = g_new0(QofBackendOption, 1);
option->option_name = GNC_BE_ZIP; option->option_name = GNC_BE_ZIP;
option->description = _("Compress output files?"); option->description = _("Compress output files?");
option->tooltip = _("GnuCash can save data files with compression." option->tooltip = _("GnuCash can save data files with compression."
" Enable this option to compress your data file. "); " Enable this option to compress your data file.");
option->type = KVP_TYPE_STRING; option->type = KVP_TYPE_GINT64;
if(file_compression) { option->value = (gpointer)"TRUE"; } compression = gnc_gconf_get_bool("general", "file_compression", NULL);
else { option->value = (gpointer)"FALSE"; } option->value = GINT_TO_POINTER(file_compression ? TRUE : FALSE);
qof_backend_prepare_option(be, option); qof_backend_prepare_option(be, option);
g_free(option); g_free(option);
return qof_backend_complete_frame(be); return qof_backend_complete_frame(be);
} }
@ -425,14 +425,15 @@ is_gzipped_file(const gchar *name)
static QofBookFileType static QofBookFileType
gnc_file_be_determine_file_type(const char *path) gnc_file_be_determine_file_type(const char *path)
{ {
if(gnc_is_xml_data_file_v2(path)) { if (gnc_is_xml_data_file_v2(path)) {
return GNC_BOOK_XML2_FILE; return GNC_BOOK_XML2_FILE;
} else if(gnc_is_xml_data_file(path)) { } else if (gnc_is_xml_data_file(path)) {
return GNC_BOOK_XML1_FILE; return GNC_BOOK_XML1_FILE;
} else if(is_gzipped_file(path)) { } else if (is_gzipped_file(path)) {
return GNC_BOOK_XML2_FILE; return GNC_BOOK_XML2_FILE;
} else if (gnc_is_bin_file(path)) {
return GNC_BOOK_BIN_FILE;
} }
else if(gnc_is_bin_file(path)) { return GNC_BOOK_BIN_FILE; }
return GNC_BOOK_NOT_OURS; return GNC_BOOK_NOT_OURS;
} }
@ -728,13 +729,13 @@ gnc_file_be_remove_old_files(FileBackend *be)
file_time = mktime(&file_tm); file_time = mktime(&file_tm);
days = (int)(difftime(now, file_time) / 86400); days = (int)(difftime(now, file_time) / 86400);
/* Make sure this file actually has a date before unlinking */
if (res && res != name+pathlen+1 && if (res
/* We consumed some but not all of the filename */ && res != name+pathlen+1
!strcmp(res, ".xac") && && (strcmp(res, ".xac") == 0
file_time > 0 && || strcmp(res, ".log") == 0)
/* we actually have a reasonable time and it is old enough */ && file_time > 0
days > file_retention_days) && days > file_retention_days)
{ {
PINFO ("unlink stale (%d days old) file: %s", days, name); PINFO ("unlink stale (%d days old) file: %s", days, name);
unlink(name); unlink(name);