[glom/glom-1-28] Surround all Glib::filename_from_uri() calls with try/catch.



commit f3a688d0cba5827ce75d8c17df59e887147f5067
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Feb 7 16:12:54 2016 +0100

    Surround all Glib::filename_from_uri() calls with try/catch.
    
    Because this can fail in the real world and it would be nice to know
    as soon as possible:
    https://bugzilla.gnome.org/show_bug.cgi?id=761373

 glom/libglom/connectionpool_backends/mysql_self.cc |   26 +++++++++-
 .../connectionpool_backends/postgres_self.cc       |   52 ++++++++++++++++++--
 glom/libglom/document/document.cc                  |   25 +++++++++-
 3 files changed, 95 insertions(+), 8 deletions(-)
---
diff --git a/glom/libglom/connectionpool_backends/mysql_self.cc 
b/glom/libglom/connectionpool_backends/mysql_self.cc
index c464f8d..9dd2f6d 100644
--- a/glom/libglom/connectionpool_backends/mysql_self.cc
+++ b/glom/libglom/connectionpool_backends/mysql_self.cc
@@ -146,7 +146,18 @@ Backend::InitErrors MySQLSelfHosted::initialize(const SlotProgress& slot_progres
   if(file_exists_uri(dbdir_uri))
     return INITERROR_DIRECTORY_ALREADY_EXISTS;
 
-  const std::string dbdir = Glib::filename_from_uri(dbdir_uri);
+  std::string dbdir;
+  try
+  {
+    dbdir = Glib::filename_from_uri(dbdir_uri);
+  }
+  catch(const Glib::ConvertError& ex)
+  {
+    std::cerr << G_STRFUNC << "Glib::filename_from_uri() failed: " << ex.what() << std::endl;
+
+    return INITERROR_OTHER;
+  }
+
   //std::cout << "debug: dbdir=" << dbdir << std::endl;
   g_assert(!dbdir.empty());
 
@@ -308,7 +319,18 @@ Backend::StartupErrors MySQLSelfHosted::startup(const SlotProgress& slot_progres
     return STARTUPERROR_FAILED_NO_MAIN_DIRECTORY;
   }
 
-  const std::string dbdir = Glib::filename_from_uri(dbdir_uri);
+  std::string dbdir;
+  try
+  {
+    dbdir = Glib::filename_from_uri(dbdir_uri);
+  }
+  catch(const Glib::ConvertError& ex)
+  {
+    std::cerr << G_STRFUNC << "Glib::filename_from_uri() failed: " << ex.what() << std::endl;
+
+    return STARTUPERROR_FAILED_UNKNOWN_REASON;
+  }
+
   g_assert(!dbdir.empty());
 
   const std::string dbdir_data = Glib::build_filename(dbdir, FILENAME_DATA);
diff --git a/glom/libglom/connectionpool_backends/postgres_self.cc 
b/glom/libglom/connectionpool_backends/postgres_self.cc
index bc8d7da..33be3dc 100644
--- a/glom/libglom/connectionpool_backends/postgres_self.cc
+++ b/glom/libglom/connectionpool_backends/postgres_self.cc
@@ -166,7 +166,18 @@ Backend::InitErrors PostgresSelfHosted::initialize(const SlotProgress& slot_prog
   if(file_exists_uri(dbdir_uri))
     return INITERROR_DIRECTORY_ALREADY_EXISTS;
 
-  const std::string dbdir = Glib::filename_from_uri(dbdir_uri);
+  std::string dbdir;
+  try
+  {
+    dbdir = Glib::filename_from_uri(dbdir_uri);
+  }
+  catch(const Glib::ConvertError& ex)
+  {
+    std::cerr << G_STRFUNC << "Glib::filename_from_uri() failed: " << ex.what() << std::endl;
+
+    return INITERROR_OTHER;
+  }
+
   //std::cout << "debug: dbdir=" << dbdir << std::endl;
   g_assert(!dbdir.empty());
 
@@ -356,7 +367,18 @@ Backend::StartupErrors PostgresSelfHosted::startup(const SlotProgress& slot_prog
     return STARTUPERROR_FAILED_NO_MAIN_DIRECTORY;
   }
 
-  const std::string dbdir = Glib::filename_from_uri(dbdir_uri);
+  std::string dbdir;
+  try
+  {
+    dbdir = Glib::filename_from_uri(dbdir_uri);
+  }
+  catch(const Glib::ConvertError& ex)
+  {
+    std::cerr << G_STRFUNC << "Glib::filename_from_uri() failed: " << ex.what() << std::endl;
+
+    return STARTUPERROR_FAILED_UNKNOWN_REASON;
+  }
+
   g_assert(!dbdir.empty());
 
   const std::string dbdir_data = Glib::build_filename(dbdir, FILENAME_DATA);
@@ -483,7 +505,18 @@ bool PostgresSelfHosted::cleanup(const SlotProgress& slot_progress)
     return true; //Don't try to stop it if we have not started it.
 
   const std::string dbdir_uri = m_database_directory_uri;
-  const std::string dbdir = Glib::filename_from_uri(dbdir_uri);
+  std::string dbdir;
+  try
+  {
+    dbdir = Glib::filename_from_uri(dbdir_uri);
+  }
+  catch(const Glib::ConvertError& ex)
+  {
+    std::cerr << G_STRFUNC << "Glib::filename_from_uri() failed: " << ex.what() << std::endl;
+
+    return false;
+  }
+
   g_assert(!dbdir.empty());
 
   const std::string dbdir_data = Glib::build_filename(dbdir, FILENAME_DATA);
@@ -538,8 +571,19 @@ bool PostgresSelfHosted::set_network_shared(const SlotProgress& /* slot_progress
 
   m_network_shared = network_shared;
 
+
   const std::string dbdir_uri = m_database_directory_uri;
-  const std::string dbdir = Glib::filename_from_uri(dbdir_uri);
+  std::string dbdir;
+  try
+  {
+    dbdir = Glib::filename_from_uri(dbdir_uri);
+  }
+  catch(const Glib::ConvertError& ex)
+  {
+    std::cerr << G_STRFUNC << "Glib::filename_from_uri() failed: " << ex.what() << std::endl;
+
+    return false;
+  }
 
   const std::string dbdir_uri_config = dbdir_uri + "/config";
   const char* default_conf_contents = 0;
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 1cb6dcd..c6b601e 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -4981,7 +4981,18 @@ Glib::ustring Document::save_backup_file(const Glib::ustring& uri, const SlotPro
   //Save a copy of the .glom document,
   //with the same name as the directory:
   //For instance <path>/chosendirectory/chosendirectory.glom
-  const std::string path_dir = Glib::filename_from_uri(uri);
+  std::string path_dir;
+  try
+  {
+    path_dir = Glib::filename_from_uri(uri);
+  }
+  catch(const Glib::ConvertError& ex)
+  {
+    std::cerr << G_STRFUNC << "Glib::filename_from_uri() failed: " << ex.what() << std::endl;
+
+    return Glib::ustring();
+  }
+
   const std::string basename_dir = Glib::path_get_basename(path_dir);
   const std::string& filepath_document = Glib::build_filename(path_dir, basename_dir + ".glom");
   const Glib::ustring uri_document = Glib::filename_to_uri(filepath_document);
@@ -5104,7 +5115,17 @@ Glib::ustring Document::extract_backup_file(const Glib::ustring& backup_uri, std
   backup_path.clear();
 
   // We cannot use an uri here, because we cannot untar remote files.
-  const std::string filename_tarball = Glib::filename_from_uri(backup_uri);
+  std::string filename_tarball;
+  try
+  {
+    filename_tarball = Glib::filename_from_uri(backup_uri);
+  }
+  catch(const Glib::ConvertError& ex)
+  {
+    std::cerr << G_STRFUNC << "Glib::filename_from_uri() failed: " << ex.what() << std::endl;
+
+    return Glib::ustring();
+  }
 
   struct archive* a = archive_read_new();
   ScopedArchivePtr<archive> scoped(a, &archive_read_free); //Make sure it is always released.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]