From c160946897f3a625c2804010fb165aded490d887 Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Fri, 19 Mar 2021 10:53:11 +0100 Subject: [PATCH] - fixed creating root config (root prefix handling) --- LIBVERSION | 2 +- VERSION | 2 +- package/snapper.changes | 6 ++++++ snapper/AppUtil.cc | 4 +++- testsuite/Makefile.am | 2 +- testsuite/root-prefix.cc | 22 ++++++++++++++++++++++ 6 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 testsuite/root-prefix.cc diff --git a/LIBVERSION b/LIBVERSION index 91ff5727..26d99a28 100644 --- a/LIBVERSION +++ b/LIBVERSION @@ -1 +1 @@ -5.2.0 +5.2.1 diff --git a/VERSION b/VERSION index 7d87d994..ac7dffa0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.8.15 +0.8.16 diff --git a/package/snapper.changes b/package/snapper.changes index 12577957..701b9eea 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Fri Mar 19 10:30:06 CET 2021 - aschnell@suse.com + +- fixed creating root config (root prefix handling) + (gh#openSUSE/snapper#627) + ------------------------------------------------------------------- Wed Mar 10 09:53:11 CET 2021 - aschnell@suse.com diff --git a/snapper/AppUtil.cc b/snapper/AppUtil.cc index b78ff302..4fe6d472 100644 --- a/snapper/AppUtil.cc +++ b/snapper/AppUtil.cc @@ -147,7 +147,9 @@ namespace snapper string prepend_root_prefix(const string& root_prefix, const string& path) { - if (root_prefix == "/") + // TODO use std::filesystem (C++17) + + if (root_prefix == "/" || root_prefix.empty()) return path; else if (path == "/") return root_prefix; diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index cfd1002d..beb8151d 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -9,7 +9,7 @@ LDADD = ../snapper/libsnapper.la ../dbus/libdbus.la -lboost_unit_test_framework check_PROGRAMS = sysconfig-get1.test dirname1.test basename1.test \ equal-date.test dbus-escape.test cmp-lt.test humanstring.test \ table.test table-formatter.test csv-formatter.test json-formatter.test \ - getopts.test scan-datetime.test + getopts.test scan-datetime.test root-prefix.test if ENABLE_BTRFS_QUOTA check_PROGRAMS += qgroup1.test diff --git a/testsuite/root-prefix.cc b/testsuite/root-prefix.cc new file mode 100644 index 00000000..e624ac99 --- /dev/null +++ b/testsuite/root-prefix.cc @@ -0,0 +1,22 @@ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE root_prefix + +#include + +#include + +using namespace snapper; + + +BOOST_AUTO_TEST_CASE(root_prefix) +{ + BOOST_CHECK_EQUAL(prepend_root_prefix("", "/"), "/"); + BOOST_CHECK_EQUAL(prepend_root_prefix("", "/home"), "/home"); + + BOOST_CHECK_EQUAL(prepend_root_prefix("/", "/"), "/"); + BOOST_CHECK_EQUAL(prepend_root_prefix("/", "/home"), "/home"); + + BOOST_CHECK_EQUAL(prepend_root_prefix("/mnt", "/"), "/mnt"); + BOOST_CHECK_EQUAL(prepend_root_prefix("/mnt", "/home"), "/mnt/home"); +} -- 2.47.3