gnucash maint: Bug 755920 - Crash (Freeze) when using File Save As.. in Windows OS
John Ralls
jralls at code.gnucash.org
Fri Oct 2 12:18:52 EDT 2015
Updated via https://github.com/Gnucash/gnucash/commit/8f8143b4 (commit)
from https://github.com/Gnucash/gnucash/commit/2b895aa7 (commit)
commit 8f8143b42381dc140464e1ab964539cefca2a76e
Author: John Ralls <jralls at 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));
}
/* Check to see if the user specified the same file as the current
Summary of changes:
src/gnome-utils/gnc-file.c | 61 ++++++++++++++++++++++++++++------------------
1 file changed, 37 insertions(+), 24 deletions(-)
More information about the gnucash-changes
mailing list