gnucash master: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Sat Sep 16 16:41:56 EDT 2017


Updated	 via  https://github.com/Gnucash/gnucash/commit/42aa7344 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a8cccc00 (commit)
	from  https://github.com/Gnucash/gnucash/commit/681d0271 (commit)



commit 42aa734475ff358ae030c6d34e2b10a4a4d3e6d3
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Sat Sep 16 21:20:16 2017 +0200

    Travis fixes
    
    - Remove trailing semicolons. They're not needed in shell scripts
    - Don't create default XDG_DATA_HOME (<HOME>/.local/share) the code
      should work equally well if that directory doesn't exist and so
      not creating it tests another part of the code

diff --git a/util/ci/arch-testscript b/util/ci/arch-testscript
index b97021d..b993a13 100644
--- a/util/ci/arch-testscript
+++ b/util/ci/arch-testscript
@@ -9,10 +9,10 @@
 # Python is python 3, but gnucash doesn't work with python 3. There
 # doesn't seem to be a way to tell automake to use /usr/bin/python2,
 # so we'll mock this up
-mkdir autotools_bin;
-ln -s /usr/bin/python2 autotools_bin/python;
-export PATH=/autotools_bin:"$PATH";
-echo path is "$PATH";
-echo python version is "$(python --version)";
+mkdir autotools_bin
+ln -s /usr/bin/python2 autotools_bin/python
+export PATH=/autotools_bin:"$PATH"
+echo path is "$PATH"
+echo python version is "$(python --version)"
 
 ../commonbuild
diff --git a/util/ci/commonbuild b/util/ci/commonbuild
index 07d13d0..526f724 100644
--- a/util/ci/commonbuild
+++ b/util/ci/commonbuild
@@ -1,25 +1,23 @@
 #!/bin/bash -e
 
-mkdir build;
-cd build;
-export TZ="America/Los_Angeles";
-
-#mkdir -p /root/.local/share;
+mkdir build
+cd build
+export TZ="America/Los_Angeles"
 
 if [[ "$BUILDTYPE" == "cmake-make" ]]; then
     cmake ../gnucash
-    make -j 4;
-    make check || ../afterfailure;
+    make -j 4
+    make check || ../afterfailure
 elif [[ "$BUILDTYPE" == "cmake-ninja" ]]; then
     cmake ../gnucash -DWITH_PYTHON=ON -DCMAKE_BUILD_TYPE=debug -DENABLE_DEBUG=on -G Ninja
     ninja
     ninja check || ../afterfailure;
 elif [[ "$BUILDTYPE" == "autotools" ]]; then
     ../gnucash/autogen.sh;
-    ../gnucash/configure --enable-python;
+    ../gnucash/configure --enable-python
     make;
-    make check || ../afterfailure;
+    make check || ../afterfailure
 else
-    echo "Unknown buildtype: \"$BUILDTYPE\". Not building.";
+    echo "Unknown buildtype: \"$BUILDTYPE\". Not building."
 fi
 
diff --git a/util/ci/ubuntu-14.04-testscript b/util/ci/ubuntu-14.04-testscript
index a5fe7aa..1582688 100644
--- a/util/ci/ubuntu-14.04-testscript
+++ b/util/ci/ubuntu-14.04-testscript
@@ -3,6 +3,6 @@
 # -e above so that if any command has an exit code != 0, this script will
 #  exit immediately.
 
-export GTEST_ROOT=/gtest/googletest GMOCK_ROOT=/gtest/googlemock;
+export GTEST_ROOT=/gtest/googletest GMOCK_ROOT=/gtest/googlemock
 
 ../commonbuild

commit a8cccc00f31a3b657cd540843dbf590f684da2d7
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Sat Sep 16 21:17:44 2017 +0200

    Minor tweaks to the userdata_dir logic
    
    - have gnc_validate_directory throw as well in case of a missing directory
      that it shouldn't create. This allows to remove 3 other throws
    - slightly adjust the error message in case of missing directory
    - never migrate when the final directory is a temporary (sub)directory

diff --git a/libgnucash/core-utils/gnc-filepath-utils.cpp b/libgnucash/core-utils/gnc-filepath-utils.cpp
index f2316ad..2cc52e2 100644
--- a/libgnucash/core-utils/gnc-filepath-utils.cpp
+++ b/libgnucash/core-utils/gnc-filepath-utils.cpp
@@ -322,7 +322,9 @@ gnc_validate_directory (const bfs::path &dirname, bool create)
         return false;
 
     if (!bfs::exists(dirname) && (!create))
-        return false;
+        throw (bfs::filesystem_error("", dirname,
+                bst::error_code(bst::errc::no_such_file_or_directory,
+                                bst::generic_category())));
 
     /* Optionally create directories if they don't exist yet
      * Note this will do nothing if the directory and its
@@ -386,7 +388,7 @@ copy_recursive(const bfs::path& src, const bfs::path& dest)
     catch(const bfs::filesystem_error& ex)
     {
         g_warning("An error occured while trying to migrate the user configation from\n%s to\n%s"
-                  "The reported failure is\n%s",
+                  "(Error: %s)",
                   src.string().c_str(), gnc_userdata_home.string().c_str(),
                   ex.what());
         return false;
@@ -465,18 +467,14 @@ get_userdata_home(bool create)
     {
         try
         {
-            if (!gnc_validate_directory(userdata_home, create))
-                throw (bfs::filesystem_error(
-                    std::string(_("Directory doesn't exist: "))
-                    + userdata_home.string(), userdata_home,
-                    bst::error_code(bst::errc::permission_denied, bst::generic_category())));
+            gnc_validate_directory(userdata_home, create);  // May throw
             try_home_dir = false;
         }
         catch (const bfs::filesystem_error& ex)
         {
             auto path_string = userdata_home.string();
-            g_warning("%s is not a suitable base directory for the user data."
-            "Trying home directory instead.\nThe failure is\n%s",
+            g_warning("%s is not a suitable base directory for the user data. "
+            "Trying home directory instead.\n(Error: %s)",
             path_string.c_str(), ex.what());
         }
     }
@@ -487,17 +485,13 @@ get_userdata_home(bool create)
         try
         {
             /* Never attempt to create a home directory, hence the false below */
-            if (!gnc_validate_directory(userdata_home, false))
-                throw (bfs::filesystem_error(
-                    std::string(_("Directory doesn't exist: "))
-                    + userdata_home.string(), userdata_home,
-                    bst::error_code(bst::errc::permission_denied, bst::generic_category())));
+            gnc_validate_directory(userdata_home, false);  // May throw
             userdata_is_home = true;
         }
         catch (const bfs::filesystem_error& ex)
         {
             g_warning("Cannot find suitable home directory. Using tmp directory instead.\n"
-            "The failure is\n%s", ex.what());
+            "(Error: %s)", ex.what());
             userdata_home = g_get_tmp_dir();
             userdata_is_tmp = true;
         }
@@ -519,18 +513,14 @@ gnc_filepath_init(gboolean create)
         try
         {
             gnc_userdata_home_exists = bfs::exists(gnc_userdata_home);
-            if (!gnc_validate_directory(gnc_userdata_home, create))
-                throw (bfs::filesystem_error(
-                    std::string(_("Directory doesn't exist: "))
-                    + userdata_home.string(), userdata_home,
-                    bst::error_code(bst::errc::permission_denied, bst::generic_category())));
+            gnc_validate_directory(gnc_userdata_home, create); // May throw
             gnc_userdata_home_from_env = true;
         }
         catch (const bfs::filesystem_error& ex)
         {
             auto path_string = userdata_home.string();
-            g_warning("%s (from environment variable 'GNC_DATA_HOME') is not a suitable directory for the user data."
-            "Trying the default instead.\nThe failure is\n%s",
+            g_warning("%s (from environment variable 'GNC_DATA_HOME') is not a suitable directory for the user data. "
+            "Trying the default instead.\n(Error: %s)",
             path_string.c_str(), ex.what());
         }
     }
@@ -551,6 +541,7 @@ gnc_filepath_init(gboolean create)
             {
                 userdata_home = g_get_tmp_dir();
                 userdata_is_home = false;
+                userdata_is_tmp = true;
             }
         }
 
@@ -563,8 +554,12 @@ gnc_filepath_init(gboolean create)
         if (!userdata_is_home)
             gnc_userdata_home = userdata_home / PACKAGE_NAME;
         gnc_userdata_home_exists = bfs::exists(gnc_userdata_home);
-        /* This may throw and end the program! */
-        gnc_validate_directory(gnc_userdata_home, create);
+        /* This may throw and end the program!
+         * Note we always allow to create in the tmp_dir. This will
+         * skip migrating to that location in the next step but that's
+         * a good thing.
+         */
+        gnc_validate_directory(gnc_userdata_home, (create || userdata_is_tmp));
     }
 
     auto migrated = FALSE;



Summary of changes:
 libgnucash/core-utils/gnc-filepath-utils.cpp | 43 ++++++++++++----------------
 util/ci/arch-testscript                      | 10 +++----
 util/ci/commonbuild                          | 18 ++++++------
 util/ci/ubuntu-14.04-testscript              |  2 +-
 4 files changed, 33 insertions(+), 40 deletions(-)



More information about the gnucash-changes mailing list