Thanks for the quick fix John. A remark that's completely unrelated to this particular bug, but triggered because it happened in this part of the code:
It occurs to me that check_file_path as function name is not totally congruent with what the function does - or better, only covers part of what it does. The current function does two things: 1. save the chosen path as default path for future save actions 2. prevent users from accidentally saving their data file in (a subdirectory of) the dotgnucash path. For starters it would make sense to me to do both actions in reverse order. That is if the user tries to save to (a subdirectory of) the dotgnucash path, we prevent this AND shouldn't store the user chosen path as the last used one or should we ? Secondly for the double role vs the function name, can we come up with a name that better covers this ? Or is it better to split up the function in two smaller ones ? Geert On Friday 02 October 2015 12:18:52 John Ralls wrote: > Updated via https://github.com/Gnucash/gnucash/commit/8f8143b4 > (commit) from https://github.com/Gnucash/gnucash/commit/2b895aa7 > (commit) > > > > commit 8f8143b42381dc140464e1ab964539cefca2a76e > Author: John Ralls <jra...@ceridwen.us> > Date: Thu Oct 1 17:15:26 2015 -0700 > > Bug 755920 - Crash (Freeze) when using File Save As.. in Windows > OS > > Fix termination of the loop so that it's not dependent upon Linux > paths. > > diff --git a/src/gnome-utils/gnc-file.c b/src/gnome-utils/gnc-file.c > index 4150fcc..d47821a 100644 > --- a/src/gnome-utils/gnc-file.c > +++ b/src/gnome-utils/gnc-file.c > @@ -1091,31 +1091,34 @@ gnc_file_export (void) > LEAVE (" "); > } > > +/* Prevent the user from storing or exporting data files into the > settings + * directory. > + */ > static gboolean > check_file_path (const char *path) > { > - /* Remember the directory as the default. */ > - gchar *default_dir = g_path_get_dirname(path); > + /* Remember the directory as the default. */ > + gchar *dir = g_path_get_dirname(path); > const gchar *dotgnucash = gnc_dotgnucash_dir(); > - gnc_set_default_directory (GNC_PREFS_GROUP_OPEN_SAVE, > default_dir); + char *dirpath = dir; > + gnc_set_default_directory (GNC_PREFS_GROUP_OPEN_SAVE, dir); > > - /* Prevent user to store file in GnuCash' private configuration > + /* Prevent user from storing file in GnuCash' private > configuration * directory (~/.gnucash by default in linux, but can be > overridden) */ > - DEBUG("User path: %s, dotgnucash_dir: %s", path, > - gnc_dotgnucash_dir()); > - while (strcmp (default_dir, "/") != 0 && strcmp(default_dir, > ".") != 0) + while (strcmp(dir = g_path_get_dirname(dirpath), > dirpath) != 0) { > - char *dirpath = default_dir; > - if (strcmp(default_dir, dotgnucash) == 0) > - { > - g_free (dirpath); > - return TRUE; > - } > - default_dir = g_path_get_dirname (dirpath); > - g_free (dirpath); > + if (strcmp(dirpath, dotgnucash) == 0) > + { > + g_free (dir); > + g_free (dirpath); > + return TRUE; > + } > + g_free (dirpath); > + dirpath = dir; > } > - g_free(default_dir); > + g_free (dirpath); > + g_free(dir); > return FALSE; > } > > @@ -1168,11 +1171,16 @@ gnc_file_do_export(const char * filename) > } > > /* Some extra steps for file based uri's only */ > - if (gnc_uri_is_file_protocol(protocol) && check_file_path (path)) > + if (gnc_uri_is_file_protocol(protocol)) > { > - show_session_error (ERR_FILEIO_RESERVED_WRITE, newfile, > - GNC_FILE_DIALOG_SAVE); > - return; > + if (check_file_path (path)) > + { > + show_session_error (ERR_FILEIO_RESERVED_WRITE, newfile, > + GNC_FILE_DIALOG_SAVE); > + return; > + } > + gnc_set_default_directory (GNC_PREFS_GROUP_OPEN_SAVE, > + g_path_get_dirname(path)); > } > /* Check to see if the user specified the same file as the > current * file. If so, prevent the export from happening to avoid > killing this file */ @@ -1394,11 +1402,16 @@ gnc_file_do_save_as > (const char* filename) } > > /* Some extra steps for file based uri's only */ > - if (gnc_uri_is_file_protocol(protocol) && check_file_path (path)) > + if (gnc_uri_is_file_protocol(protocol)) > { > - show_session_error (ERR_FILEIO_RESERVED_WRITE, newfile, > - GNC_FILE_DIALOG_SAVE); > - return; > + if (check_file_path (path)) > + { > + show_session_error (ERR_FILEIO_RESERVED_WRITE, newfile, > + GNC_FILE_DIALOG_SAVE); > + return; > + } > + gnc_set_default_directory (GNC_PREFS_GROUP_OPEN_SAVE, > + g_path_get_dirname (path)); > } _______________________________________________ gnucash-devel mailing list gnucash-devel@gnucash.org https://lists.gnucash.org/mailman/listinfo/gnucash-devel