mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
parent
b9724e3063
commit
0324351b44
@ -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
|
||||||
|
@ -888,7 +888,13 @@ qof_session_load_backend(QofSession * session, char * access_method)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* 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)
|
||||||
|
@ -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,49 +67,48 @@ 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);
|
||||||
option->option_name = GNC_BE_DAYS;
|
option->option_name = GNC_BE_DAYS;
|
||||||
option->description = _("Number of days to retain old files");
|
option->description = _("Number of days to retain old files");
|
||||||
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->option_name = GNC_BE_ZIP;
|
option = g_new0(QofBackendOption, 1);
|
||||||
option->description = _("Compress output files?");
|
option->option_name = GNC_BE_ZIP;
|
||||||
option->tooltip = _("GnuCash can save data files with compression."
|
option->description = _("Compress output files?");
|
||||||
" Enable this option to compress your data file. ");
|
option->tooltip = _("GnuCash can save data files with compression."
|
||||||
option->type = KVP_TYPE_STRING;
|
" Enable this option to compress your data file.");
|
||||||
if(file_compression) { option->value = (gpointer)"TRUE"; }
|
option->type = KVP_TYPE_GINT64;
|
||||||
else { option->value = (gpointer)"FALSE"; }
|
compression = gnc_gconf_get_bool("general", "file_compression", NULL);
|
||||||
qof_backend_prepare_option(be, option);
|
option->value = GINT_TO_POINTER(file_compression ? TRUE : FALSE);
|
||||||
g_free(option);
|
qof_backend_prepare_option(be, option);
|
||||||
return qof_backend_complete_frame(be);
|
g_free(option);
|
||||||
|
|
||||||
|
return qof_backend_complete_frame(be);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================================= */
|
/* ================================================================= */
|
||||||
@ -425,15 +425,16 @@ 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)) {
|
||||||
else if(gnc_is_bin_file(path)) { return GNC_BOOK_BIN_FILE; }
|
return GNC_BOOK_BIN_FILE;
|
||||||
return GNC_BOOK_NOT_OURS;
|
}
|
||||||
|
return GNC_BOOK_NOT_OURS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -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);
|
||||||
@ -877,7 +878,7 @@ gnc_file_be_load_from_file (QofBackend *bend, QofBook *book)
|
|||||||
gboolean rc;
|
gboolean rc;
|
||||||
FileBackend *be = (FileBackend *) bend;
|
FileBackend *be = (FileBackend *) bend;
|
||||||
|
|
||||||
error = ERR_BACKEND_NO_ERR;
|
error = ERR_BACKEND_NO_ERR;
|
||||||
be->primary_book = book;
|
be->primary_book = book;
|
||||||
|
|
||||||
switch (gnc_file_be_determine_file_type(be->fullpath))
|
switch (gnc_file_be_determine_file_type(be->fullpath))
|
||||||
|
Loading…
Reference in New Issue
Block a user