gnucash maint: Bug 796484 - csv import: iostream error

John Ralls jralls at code.gnucash.org
Tue Jun 12 14:48:51 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/91795052 (commit)
	from  https://github.com/Gnucash/gnucash/commit/9e6760f7 (commit)



commit 9179505208768fb718b85c50b29b06bf732547f3
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Jun 12 11:43:25 2018 -0700

    Bug 796484 - csv import: iostream error
    
    Unfortunately it turns out that we can't use filestreams because
    they can't take path arguments containing Unicode on Windows.
    Replace the filestream code with g_file_get_contents(),  which
    takes care of all of that Windows compatibility noise for us.

diff --git a/gnucash/import-export/csv-imp/gnc-tokenizer.cpp b/gnucash/import-export/csv-imp/gnc-tokenizer.cpp
index 7b14a2d..f8917f7 100644
--- a/gnucash/import-export/csv-imp/gnc-tokenizer.cpp
+++ b/gnucash/import-export/csv-imp/gnc-tokenizer.cpp
@@ -15,6 +15,8 @@
 
 extern "C" {
 #include <go-glib-extras.h>
+#include <glib.h>
+#include <glib/gstdio.h>
 }
 
 std::unique_ptr<GncTokenizer> gnc_tokenizer_factory(GncImpFileFormat fmt)
@@ -43,18 +45,16 @@ GncTokenizer::load_file(const std::string& path)
         return;
 
     m_imp_file_str = path;
+    char *raw_contents;
+    size_t raw_length;
+    GError *error;
 
-    std::ifstream in;
-    in.exceptions ( std::ifstream::failbit | std::ifstream::badbit );
-    in.open (m_imp_file_str.c_str(), std::ios::in | std::ios::binary);
-
-    m_raw_contents.clear();
-    in.seekg(0, std::ios::end);
-    m_raw_contents.resize(in.tellg());
-    in.seekg(0, std::ios::beg);
-    in.read(&m_raw_contents[0], m_raw_contents.size());
-    in.close();
+    if (!g_file_get_contents(path.c_str(), &raw_contents, &raw_length, &error))
+      throw std::ifstream::failure(error->message);
 
+    m_raw_contents = raw_contents;
+    g_free(raw_contents);
+    
     // Guess encoding, user can override if needed later on.
     const char *guessed_enc = NULL;
     guessed_enc = go_guess_encoding (m_raw_contents.c_str(),



Summary of changes:
 gnucash/import-export/csv-imp/gnc-tokenizer.cpp | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)



More information about the gnucash-changes mailing list