mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
Remove obsolete compatibility code in the state file processing.
No version GnuCash 2.2.x version will produce state files with spaces in their key names, and we don't need to worry about older compatibility (migrating from 2.0.x should always happen via 2.2.x). git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20096 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
d87afa65b4
commit
20860fba9f
@ -177,69 +177,6 @@ gnc_getline (gchar **line, FILE *file)
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
/* Update one state file file to fit the new constraints introduced by
|
||||
* glib 2.12.5. Supposedly its always been illegal to use spaces in
|
||||
* key names, but it was never a problem with earlier releases of
|
||||
* glib. Glib 2.12.5 added hard enforcement of this rule, completely
|
||||
* ignoring any key/value pair where the key name contained an
|
||||
* "illegal" character. Glib 2.12.7 relented and changed the hard
|
||||
* failure to a warning, but the point has been made. Spaces in key
|
||||
* names must go.
|
||||
*/
|
||||
static gboolean
|
||||
gnc_update_state_file_keys(const gchar *filename)
|
||||
{
|
||||
gchar *contents, **lines, *line, **kv, **parts, *part, *newkey;
|
||||
GError *error = NULL;
|
||||
int i, j;
|
||||
|
||||
if (!g_file_get_contents(filename, &contents, NULL, &error))
|
||||
{
|
||||
DEBUG("Error reading state file: %s", error->message);
|
||||
g_error_free(error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
lines = g_strsplit_set(contents, "\r\n", -1);
|
||||
g_free(contents);
|
||||
|
||||
/* Strip spaces from non-comment lines, and rewrite the new text
|
||||
* over top of the old text. The new line is guaranteed to be at
|
||||
* most the same number of characters as the old. */
|
||||
for (i = 0, line = lines[i++]; line; line = lines[i++])
|
||||
{
|
||||
if ((*line == '\0') || (*line == '#') || (*line == '['))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
kv = g_strsplit(line, "=", 2);
|
||||
parts = g_strsplit(kv[0], " ", -1);
|
||||
for (j = 0, part = parts[j++]; part; part = parts[j++])
|
||||
part[0] = g_ascii_toupper(part[0]);
|
||||
newkey = g_strjoinv("", parts);
|
||||
g_sprintf(line, "%s=%s", newkey, kv[1] ? kv[1] : "");
|
||||
g_free(newkey);
|
||||
g_strfreev(parts);
|
||||
g_strfreev(kv);
|
||||
}
|
||||
}
|
||||
|
||||
contents = g_strjoinv("\n", lines);
|
||||
if (!g_file_set_contents(filename, contents, -1, &error))
|
||||
{
|
||||
DEBUG("Error writing state file: %s", error->message);
|
||||
g_error_free(error);
|
||||
g_free(contents);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_free(contents);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Find the state file that corresponds to this URL and guid. The
|
||||
* URL is used to compute the base name of the file (which will be in
|
||||
* ~/.gnucash/books) and the guid is used to differentiate when the
|
||||
@ -251,8 +188,7 @@ gnc_find_state_file (const gchar *url,
|
||||
{
|
||||
gchar *basename, *original = NULL, *filename, *tmp, *file_guid;
|
||||
GKeyFile *key_file = NULL;
|
||||
GError *error = NULL;
|
||||
gboolean do_increment;
|
||||
gboolean do_increment = FALSE;
|
||||
gint i;
|
||||
|
||||
ENTER("url %s, guid %s", url, guid);
|
||||
@ -297,27 +233,9 @@ gnc_find_state_file (const gchar *url,
|
||||
else
|
||||
filename = g_strdup_printf("%s_%d", original, i);
|
||||
DEBUG("Trying %s", filename);
|
||||
key_file = gnc_key_file_load_from_file(filename, FALSE, FALSE, &error);
|
||||
key_file = gnc_key_file_load_from_file(filename, FALSE, FALSE, NULL);
|
||||
DEBUG("Result %p", key_file);
|
||||
|
||||
if (error &&
|
||||
(error->domain == G_KEY_FILE_ERROR) &&
|
||||
(error->code == G_KEY_FILE_ERROR_PARSE))
|
||||
{
|
||||
/* Handle the case where glib was updated first, and is refusing
|
||||
* to read old state files. */
|
||||
if (gnc_update_state_file_keys(filename))
|
||||
{
|
||||
DEBUG("Trying %s again", filename);
|
||||
key_file = gnc_key_file_load_from_file(filename, FALSE, FALSE, NULL);
|
||||
DEBUG("Result %p", key_file);
|
||||
}
|
||||
}
|
||||
if (error)
|
||||
{
|
||||
g_error_free(error);
|
||||
error = NULL;
|
||||
}
|
||||
if (!key_file)
|
||||
{
|
||||
DEBUG("No key file by that name");
|
||||
@ -334,25 +252,12 @@ gnc_find_state_file (const gchar *url,
|
||||
g_free(file_guid);
|
||||
break;
|
||||
}
|
||||
g_free(file_guid);
|
||||
|
||||
/* Handle the case where gnucash was updated first, and is trying
|
||||
* to find new key names in an old state files. */
|
||||
file_guid = g_key_file_get_string(key_file,
|
||||
STATE_FILE_TOP, STATE_FILE_BOOK_GUID_OLD,
|
||||
NULL);
|
||||
DEBUG("%s is %s", STATE_FILE_BOOK_GUID,
|
||||
file_guid ? file_guid : "<not found>");
|
||||
if (safe_strcmp(guid, file_guid) == 0)
|
||||
{
|
||||
DEBUG("Matched !!!");
|
||||
do_increment = !gnc_update_state_file_keys(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_increment = TRUE;
|
||||
}
|
||||
|
||||
|
||||
DEBUG("Clean up this pass");
|
||||
g_free(file_guid);
|
||||
g_key_file_free(key_file);
|
||||
|
@ -95,7 +95,6 @@ gint64 gnc_getline (gchar **line, FILE *file);
|
||||
/* Definitions shared by file-utils.c and gnc-main-window.c */
|
||||
#define STATE_FILE_TOP "Top"
|
||||
#define STATE_FILE_BOOK_GUID "BookGuid"
|
||||
#define STATE_FILE_BOOK_GUID_OLD "Book Guid"
|
||||
|
||||
/** Find the state file that corresponds to this URL and guid.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user