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.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18440 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff
2009-11-24 00:07:45 +00:00
parent 4cd8d17259
commit c30ad8789b
+28 -9
View File
@@ -173,6 +173,25 @@ xaccUserPathPathGenerator(char *pathbuf, int which)
/* ====================================================================== */
/**
* 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 @@ xaccResolveFilePath (const char * filefrag)
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 @@ gnc_build_dotgnucash_path (const gchar *filename)
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 ========================== */