AUDIT: r17477 - gnucash/trunk/src/import-export/qif-import - Bug #548891: QIF Import: Prevent crashing when the mapping preferences can't be saved.

Charles Day cedayiv at cvs.gnucash.org
Thu Aug 21 13:47:10 EDT 2008


Author: cedayiv
Date: 2008-08-21 13:47:10 -0400 (Thu, 21 Aug 2008)
New Revision: 17477
Trac: http://svn.gnucash.org/trac/changeset/17477

Modified:
   gnucash/trunk/src/import-export/qif-import/druid-qif-import.c
   gnucash/trunk/src/import-export/qif-import/qif-guess-map.scm
Log:
Bug #548891: QIF Import: Prevent crashing when the mapping preferences can't be saved.
BP


Modified: gnucash/trunk/src/import-export/qif-import/druid-qif-import.c
===================================================================
--- gnucash/trunk/src/import-export/qif-import/druid-qif-import.c	2008-08-21 00:13:36 UTC (rev 17476)
+++ gnucash/trunk/src/import-export/qif-import/druid-qif-import.c	2008-08-21 17:47:10 UTC (rev 17477)
@@ -2997,9 +2997,10 @@
                             gpointer arg1,
                             gpointer user_data)
 {
-  SCM   save_map_prefs = scm_c_eval_string("qif-import:save-map-prefs");
-  SCM   cat_and_merge = scm_c_eval_string("gnc:account-tree-catenate-and-merge");
-  SCM   prune_xtns = scm_c_eval_string("gnc:prune-matching-transactions");
+  SCM save_map_prefs = scm_c_eval_string("qif-import:save-map-prefs");
+  SCM cat_and_merge = scm_c_eval_string("gnc:account-tree-catenate-and-merge");
+  SCM prune_xtns = scm_c_eval_string("gnc:prune-matching-transactions");
+  SCM scm_result;
 
   QIFImportWindow * wind = user_data;
   GncPluginPage *page;
@@ -3020,11 +3021,14 @@
   gnc_resume_gui_refresh();
 
   /* Save the user's mapping preferences. */
-  scm_apply(save_map_prefs,
-            SCM_LIST5(wind->acct_map_info, wind->cat_map_info,
-                      wind->memo_map_info, wind->security_hash,
-                      wind->security_prefs),
-            SCM_EOL);
+  scm_result = scm_apply(save_map_prefs,
+                         SCM_LIST5(wind->acct_map_info, wind->cat_map_info,
+                                   wind->memo_map_info, wind->security_hash,
+                                   wind->security_prefs),
+                         SCM_EOL);
+  if (scm_result == SCM_BOOL_F)
+    gnc_warning_dialog(wind->window,
+            _("GnuCash was unable to save your mapping preferences."));
 
   /* Open an account tab in the main window if one doesn't exist already. */
   gnc_main_window_foreach_page(gnc_ui_qif_import_check_acct_tree,

Modified: gnucash/trunk/src/import-export/qif-import/qif-guess-map.scm
===================================================================
--- gnucash/trunk/src/import-export/qif-import/qif-guess-map.scm	2008-08-21 00:13:36 UTC (rev 17476)
+++ gnucash/trunk/src/import-export/qif-import/qif-guess-map.scm	2008-08-21 17:47:10 UTC (rev 17477)
@@ -265,46 +265,53 @@
 ;;  file.  This only gets called when the user clicks the Apply
 ;;  button in the druid, so any new mappings will be lost if the
 ;;  user cancels the import instead.
+;;
+;;  Returns #t upon success or #f on failure.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (define (qif-import:save-map-prefs acct-map cat-map memo-map
                                    security-map security-prefs)
-  (let* ((pref-filename (gnc-build-dotgnucash-path "qif-accounts-map")))
-    ;; does the file exist? if not, create it; in either case,
-    ;; make sure it's a directory and we have write and execute
-    ;; permission.
-        (with-output-to-file pref-filename
-          (lambda ()
-            (display ";;; qif-accounts-map\n")
-            (display ";;; Automatically generated by GnuCash.  DO NOT EDIT.\n")
-            (display ";;; (Unless you really, really want to.)\n")
 
-            (display ";;; Map QIF accounts to GnuCash accounts")
-            (newline)
-            (qif-import:write-map acct-map)
-            (newline)
+  ;; This procedure does all the work. We'll define it, then call it safely.
+  (define (private-save)
+    (with-output-to-file (gnc-build-dotgnucash-path "qif-accounts-map")
+      (lambda ()
+        (display ";;; qif-accounts-map")
+        (newline)
+        (display ";;; Automatically generated by GnuCash. DO NOT EDIT.")
+        (newline)
+        (display ";;; (Unless you really, really want to.)")
+        (newline)
+        (display ";;; Map QIF accounts to GnuCash accounts")
+        (newline)
+        (qif-import:write-map acct-map)
+        (newline)
 
-            (display ";;; Map QIF categories to GnuCash accounts")
-            (newline)
-            (qif-import:write-map cat-map)
-            (newline)
+        (display ";;; Map QIF categories to GnuCash accounts")
+        (newline)
+        (qif-import:write-map cat-map)
+        (newline)
 
-            (display ";;; Map QIF payee/memo to GnuCash accounts")
-            (newline)
-            (qif-import:write-map memo-map)
-            (newline)
+        (display ";;; Map QIF payee/memo to GnuCash accounts")
+        (newline)
+        (qif-import:write-map memo-map)
+        (newline)
 
-            (display ";;; Map QIF security names to GnuCash commodities")
-            (newline)
-            (qif-import:write-securities security-map security-prefs)
-            (newline)
+        (display ";;; Map QIF security names to GnuCash commodities")
+        (newline)
+        (qif-import:write-securities security-map security-prefs)
+        (newline)
 
-            (display ";;; GnuCash separator used in these mappings")
-            (newline)
-            (write (gnc-get-account-separator-string))
-            (newline)))))
+        (display ";;; GnuCash separator used in these mappings")
+        (newline)
+        (write (gnc-get-account-separator-string))
+        (newline)))
+    #t)
 
+  ;; Safely save the file.
+  (gnc:backtrace-if-exception private-save))
 
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;  here's where we do all the guessing.  We really want to find the
 ;;  match in the hash table, but failing that we guess intelligently



More information about the gnucash-changes mailing list