r18440 - gnucash/trunk/src/engine - Fix bug 602603 - State file cannot be saved with MySQL because of colon in filename
Phil Longstaff
plongstaff at code.gnucash.org
Mon Nov 23 19:07:45 EST 2009
Author: plongstaff
Date: 2009-11-23 19:07:45 -0500 (Mon, 23 Nov 2009)
New Revision: 18440
Trac: http://svn.gnucash.org/trac/changeset/18440
Modified:
gnucash/trunk/src/engine/gnc-filepath-utils.c
Log:
Fix bug 602603 - State file cannot be saved with MySQL because of colon in filename
When creating file names for the "books" or "data" directory under ".gnucash", convert
'/' and ':' to '_'. This may mean state is lost for cases with a full url including
type (since the previous conversion was '/' to ','), but this will only happen once.
Modified: gnucash/trunk/src/engine/gnc-filepath-utils.c
===================================================================
--- gnucash/trunk/src/engine/gnc-filepath-utils.c 2009-11-23 19:58:22 UTC (rev 18439)
+++ gnucash/trunk/src/engine/gnc-filepath-utils.c 2009-11-24 00:07:45 UTC (rev 18440)
@@ -173,6 +173,25 @@
/* ====================================================================== */
+/**
+ * Scrubs a filename by changing "strange" chars (e.g. those that are not
+ * valid in a win32 file name) to "_".
+ *
+ * @param filename File name - updated in place
+ */
+static void
+scrub_filename(char* filename)
+{
+ char* p;
+
+#define STRANGE_CHARS "/:"
+ p = strpbrk(filename, STRANGE_CHARS);
+ while (p) {
+ *p = '_';
+ p = strpbrk(filename, STRANGE_CHARS);
+ }
+}
+
char *
xaccResolveFilePath (const char * filefrag)
{
@@ -247,16 +266,10 @@
filefrag_dup = g_strdup (filefrag);
- /* Replace '/' with ',' for non file backends */
+ /* Replace "strange" chars with "_" for non-file backends. */
if (strstr (filefrag, "://"))
{
- char *p;
-
- p = strchr (filefrag_dup, '/');
- while (p) {
- *p = ',';
- p = strchr (filefrag_dup, '/');
- }
+ scrub_filename(filefrag_dup);
}
/* Lets try creating a new file in $HOME/.gnucash/data */
@@ -454,7 +467,13 @@
gchar *
gnc_build_book_path (const gchar *filename)
{
- return g_build_filename(gnc_dotgnucash_dir(), "books", filename, (gchar *)NULL);
+ char* filename_dup = g_strdup(filename);
+ char* result;
+
+ scrub_filename(filename_dup);
+ result = g_build_filename(gnc_dotgnucash_dir(), "books", filename_dup, (gchar *)NULL);
+ g_free(filename_dup);
+ return result;
}
/* =============================== END OF FILE ========================== */
More information about the gnucash-changes
mailing list