From: Arvin Schnell Date: Wed, 22 Sep 2021 08:37:14 +0000 (+0200) Subject: - look for most configuration files in /etc/snapper and /usr/share/snapper (bsc#1189601) X-Git-Tag: v0.9.1~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96e90e21d59b84b3c20aa50934c2e20c3cedf7de;p=thirdparty%2Fsnapper.git - look for most configuration files in /etc/snapper and /usr/share/snapper (bsc#1189601) --- diff --git a/VERSION b/VERSION index ac39a106..f374f666 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.0 +0.9.1 diff --git a/client/installation-helper.cc b/client/installation-helper.cc index 66567b4c..db0a2a24 100644 --- a/client/installation-helper.cc +++ b/client/installation-helper.cc @@ -73,7 +73,7 @@ step1(const string& device, const string& description, const string& cleanup, try { - SysconfigFile config(CONFIG_TEMPLATE_DIR "/" "default"); + SysconfigFile config(locate_file("default", ETC_CONFIG_TEMPLATE_DIR, USR_CONFIG_TEMPLATE_DIR)); config.setName(tmp_mount.getFullname() + CONFIGS_DIR "/" "root"); diff --git a/data/Makefile.am b/data/Makefile.am index 684d92b1..fa54bd4f 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -11,12 +11,14 @@ install-data-local: install -D -m 644 snapper.logrotate $(DESTDIR)/etc/logrotate.d/snapper install -d -m 755 $(DESTDIR)/etc/snapper/configs - install -D -m 644 default-config $(DESTDIR)/etc/snapper/config-templates/default - install -d -m 755 $(DESTDIR)/etc/snapper/filters - install -D -m 644 base.txt $(DESTDIR)/etc/snapper/filters/base.txt - install -D -m 644 lvm.txt $(DESTDIR)/etc/snapper/filters/lvm.txt - install -D -m 644 x11.txt $(DESTDIR)/etc/snapper/filters/x11.txt + install -d -m 755 $(DESTDIR)/usr/share/snapper/config-templates + install -D -m 644 default-config $(DESTDIR)/usr/share/snapper/config-templates/default + + install -d -m 755 $(DESTDIR)/usr/share/snapper/filters + install -D -m 644 base.txt $(DESTDIR)/usr/share/snapper/filters/base.txt + install -D -m 644 lvm.txt $(DESTDIR)/usr/share/snapper/filters/lvm.txt + install -D -m 644 x11.txt $(DESTDIR)/usr/share/snapper/filters/x11.txt install -D -m 644 org.opensuse.Snapper.conf $(DESTDIR)/usr/share/dbus-1/system.d/org.opensuse.Snapper.conf install -D -m 644 org.opensuse.Snapper.service $(DESTDIR)/usr/share/dbus-1/system-services/org.opensuse.Snapper.service @@ -32,5 +34,5 @@ if ENABLE_SYSTEMD endif if HAVE_ZYPP - install -D -m 644 zypp-plugin.conf $(DESTDIR)/etc/snapper/zypp-plugin.conf + install -D -m 644 zypp-plugin.conf $(DESTDIR)/usr/share/snapper/zypp-plugin.conf endif diff --git a/dists/debian/libsnapper.install b/dists/debian/libsnapper.install index 52e37009..a866f5fe 100644 --- a/dists/debian/libsnapper.install +++ b/dists/debian/libsnapper.install @@ -1,6 +1,6 @@ -etc/snapper/config-templates etc/snapper/configs -etc/snapper/filters etc/sysconfig/snapper +usr/share/snapper/config-templates +usr/share/snapper/filters usr/lib/libsnapper.so.* usr/share/doc/packages/snapper diff --git a/dists/debian/snapper-zypp-plugin.install b/dists/debian/snapper-zypp-plugin.install index 19877a8c..94a37e26 100644 --- a/dists/debian/snapper-zypp-plugin.install +++ b/dists/debian/snapper-zypp-plugin.install @@ -1,2 +1,2 @@ usr/lib/zypp/plugins/commit/snapper-zypp-plugin -etc/snapper/zypp-plugin.conf +usr/share/snapper/zypp-plugin.conf diff --git a/doc/snapper-zypp-plugin.conf.xml.in b/doc/snapper-zypp-plugin.conf.xml.in index d629f16e..40e0eeab 100644 --- a/doc/snapper-zypp-plugin.conf.xml.in +++ b/doc/snapper-zypp-plugin.conf.xml.in @@ -2,13 +2,13 @@ - 2013-11-22 + 2021-09-21 snapper-zypp-plugin.conf 5 - 2013-11-22 + 2021-09-21 @VERSION@ Filesystem Snapshot Management @@ -20,8 +20,10 @@ DESCRIPTION - The file /etc/snapper/zypp-plugin.conf contains - the configuation for snapper-zypp-plugin. + The file /etc/snapper/zypp-plugin.conf + or as a fallback + /usr/share/snapper/zypp-plugin.conf contains the + configuation for snapper-zypp-plugin. The file uses XML syntax. For the XML structure have a look at the provided default config. diff --git a/doc/snapper-zypp-plugin.xml.in b/doc/snapper-zypp-plugin.xml.in index 3e1fc83a..4ddba3c2 100644 --- a/doc/snapper-zypp-plugin.xml.in +++ b/doc/snapper-zypp-plugin.xml.in @@ -2,13 +2,13 @@ - 2013-11-22 + 2021-09-21 snapper-zypp-plugin 8 - 2013-11-22 + 2021-09-21 @VERSION@ Filesystem Snapshot Management @@ -34,6 +34,12 @@ Configuration file. New in version 0.1.8. + + /usr/share/snapper/zypp-plugin.conf + + Fallback configuration file. New in version 0.9.1. + + diff --git a/doc/snapper.xml.in b/doc/snapper.xml.in index 337eae0a..dd6d41b1 100644 --- a/doc/snapper.xml.in +++ b/doc/snapper.xml.in @@ -2,13 +2,13 @@ - 2020-06-15 + 2021-09-21 snapper 8 - 2020-06-15 + 2021-09-21 @VERSION@ Filesystem Snapshot Management @@ -175,11 +175,13 @@ e.g. /etc/mtab. Such files should never be reverted. To help users, snapper allows one to ignore these files. - Each line in all - files /etc/snapper/filters/*.txt specifies a - pattern. When snapper computes the difference between two snapshots it - ignores all files and directories matching any of those patterns by - using + Filters are read from the files + /etc/snapper/filters/*.txt and + /usr/share/snapper/filters/*.txt, where + for files with the same name the former location has precedence. + Each line in those files specifies a pattern. When snapper + computes the difference between two snapshots it ignores all + files and directories matching any of those patterns by using fnmatch3 with the flag FNM_LEADING_DIR. @@ -858,12 +860,24 @@ Directory containing configuration templates. + + /usr/share/snapper/config-templates + + Fallback directory containing configuration templates. + + /etc/snapper/filters/*.txt Filter files. + + /usr/share/snapper/filters/*.txt + + Fallback filter files. + + /var/log/snapper.log diff --git a/package/snapper.changes b/package/snapper.changes index 62712fff..63873464 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Tue Sep 21 13:30:29 CEST 2021 - aschnell@suse.com + +- look for most configuration files in /etc/snapper and + /usr/share/snapper (bsc#1189601) +- version 0.9.1 + ------------------------------------------------------------------- Wed Jun 16 11:50:49 CEST 2021 - aschnell@suse.com diff --git a/snapper.spec.in b/snapper.spec.in index 5ab0d7e1..c4389396 100644 --- a/snapper.spec.in +++ b/snapper.spec.in @@ -226,10 +226,11 @@ This package contains libsnapper, a library for filesystem snapshot management. %{_libdir}/libsnapper.so.* %dir %{_sysconfdir}/snapper %dir %{_sysconfdir}/snapper/configs -%dir %{_sysconfdir}/snapper/config-templates -%config(noreplace) %{_sysconfdir}/snapper/config-templates/default -%dir %{_sysconfdir}/snapper/filters -%config(noreplace) %{_sysconfdir}/snapper/filters/*.txt +%dir /usr/share/snapper +%dir /usr/share/snapper/config-templates +%config /usr/share/snapper/config-templates/default +%dir /usr/share/snapper/filters +%config /usr/share/snapper/filters/*.txt %doc %dir %{_defaultdocdir}/snapper %doc %{_defaultdocdir}/snapper/AUTHORS %doc %{_defaultdocdir}/snapper/COPYING @@ -239,6 +240,18 @@ This package contains libsnapper, a library for filesystem snapshot management. %config(noreplace) %{_sysconfdir}/sysconfig/snapper %endif +%pre -n libsnapper@LIBVERSION_MAJOR@ +# Migration from /etc/snapper to /usr/share/snapper +for i in config-templates/default filters/base.txt filters/lvm.txt filters/x11.txt ; do + test -f /etc/snapper/${i}.rpmsave && mv -v /etc/snapper/${i}.rpmsave /etc/snapper/${i}.rpmsave.old ||: +done + +%posttrans -n libsnapper@LIBVERSION_MAJOR@ +# Migration from /etc/snapper to /usr/share/snapper +for i in config-templates/default filters/base.txt filters/lvm.txt filters/x11.txt ; do + test -f /etc/snapper/${i}.rpmsave && mv -v /etc/snapper/${i}.rpmsave /etc/snapper/${i} ||: +done + %post -n libsnapper@LIBVERSION_MAJOR@ /sbin/ldconfig %if 0%{?suse_version} @@ -288,7 +301,7 @@ snapper during commits. %files -n snapper-zypp-plugin %defattr(-,root,root) -%config(noreplace) %{_sysconfdir}/snapper/zypp-plugin.conf +%config /usr/share/snapper/zypp-plugin.conf %if 0%{?suse_version} < 1210 %dir /usr/lib/zypp %dir /usr/lib/zypp/plugins @@ -298,6 +311,18 @@ snapper during commits. %doc %{_mandir}/*/snapper-zypp-plugin.8* %doc %{_mandir}/*/snapper-zypp-plugin.conf.5* +%pre -n snapper-zypp-plugin +# Migration from /etc/snapper to /usr/share/snapper +for i in zypp-plugin.conf ; do + test -f /etc/snapper/${i}.rpmsave && mv -v /etc/snapper/${i}.rpmsave /etc/snapper/${i}.rpmsave.old ||: +done + +%posttrans -n snapper-zypp-plugin +# Migration from /etc/snapper to /usr/share/snapper +for i in zypp-plugin.conf ; do + test -f /etc/snapper/${i}.rpmsave && mv -v /etc/snapper/${i}.rpmsave /etc/snapper/${i} ||: +done + %package -n pam_snapper Requires: pam Requires: snapper = %version diff --git a/snapper/AppUtil.cc b/snapper/AppUtil.cc index 1c0ff834..99565707 100644 --- a/snapper/AppUtil.cc +++ b/snapper/AppUtil.cc @@ -56,10 +56,10 @@ namespace snapper } - list + vector glob(const string& path, int flags) { - list ret; + vector ret; glob_t globbuf; if (glob(path.c_str(), flags, 0, &globbuf) == 0) @@ -176,6 +176,21 @@ namespace snapper } + string + locate_file(const string& f, const char* p1, const char* p2) + { + string f1 = string(p1) + "/" + f; + if (access(f1.c_str(), R_OK) == 0) + return f1; + + string f2 = string(p2) + "/" + f; + if (access(f2.c_str(), R_OK) == 0) + return f2; + + throw runtime_error(sformat("file '%s' not found in '%s' nor '%s'", f.c_str(), p1, p2)); + } + + unsigned pagesize() { diff --git a/snapper/AppUtil.h b/snapper/AppUtil.h index edee3255..ccde04dd 100644 --- a/snapper/AppUtil.h +++ b/snapper/AppUtil.h @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -43,14 +42,13 @@ namespace snapper { using std::string; - using std::list; using std::map; using std::vector; bool checkDir(const string& Path_Cv); - list glob(const string& path, int flags); + vector glob(const string& path, int flags); bool clonefile(int src_fd, int dest_fd); bool copyfile(int src_fd, int dest_fd); @@ -68,6 +66,12 @@ namespace snapper string basename(const string& name); + /** + * Locate the file f first in p1 and second in p2. + */ + string locate_file(const string& f, const char* p1, const char* p2); + + struct MtabData { string device; diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 52e8661e..89f7b8cc 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -1,6 +1,6 @@ /* * Copyright (c) [2011-2015] Novell, Inc. - * Copyright (c) [2016-2020] SUSE LLC + * Copyright (c) [2016-2021] SUSE LLC * * All Rights Reserved. * @@ -158,12 +158,29 @@ namespace snapper void Snapper::loadIgnorePatterns() { - const list files = glob(FILTERS_DIR "/*.txt", GLOB_NOSORT); - for (list::const_iterator it = files.begin(); it != files.end(); ++it) + const vector etc_files = glob(ETC_FILTERS_DIR "/*.txt", GLOB_NOSORT); + const vector usr_files = glob(USR_FILTERS_DIR "/*.txt", GLOB_NOSORT); + + // all files from /etc + vector files = etc_files; + + // files from /usr where no corresponding file in /etc exists + for (const string& usr_file : usr_files) + { + string b1 = basename(usr_file); + + if (none_of(etc_files.begin(), etc_files.end(), [&b1](const string& etc_file) { + string b2 = basename(etc_file); + return b1 == b2; + })) + files.push_back(usr_file); + } + + for (const string& file : files) { try { - AsciiFileReader asciifile(*it); + AsciiFileReader asciifile(file); string line; while (asciifile.getline(line)) @@ -335,7 +352,13 @@ namespace snapper } } - if (access(string(CONFIG_TEMPLATE_DIR "/" + template_name).c_str(), R_OK) != 0) + string template_file; + + try + { + template_file = locate_file(template_name, ETC_CONFIG_TEMPLATE_DIR, USR_CONFIG_TEMPLATE_DIR); + } + catch (...) { SN_THROW(CreateConfigFailedException("cannot access template config")); } @@ -374,7 +397,7 @@ namespace snapper try { - SysconfigFile config(CONFIG_TEMPLATE_DIR "/" + template_name); + SysconfigFile config(template_file); config.setName(CONFIGS_DIR "/" + config_name); diff --git a/snapper/SnapperDefines.h b/snapper/SnapperDefines.h index d21d2628..c43036c6 100644 --- a/snapper/SnapperDefines.h +++ b/snapper/SnapperDefines.h @@ -30,9 +30,12 @@ #define SYSCONFIG_FILE CONF_DIR "/snapper" #define CONFIGS_DIR "/etc/snapper/configs" -#define CONFIG_TEMPLATE_DIR "/etc/snapper/config-templates" -#define FILTERS_DIR "/etc/snapper/filters" +#define ETC_CONFIG_TEMPLATE_DIR "/etc/snapper/config-templates" +#define USR_CONFIG_TEMPLATE_DIR "/usr/share/snapper/config-templates" + +#define ETC_FILTERS_DIR "/etc/snapper/filters" +#define USR_FILTERS_DIR "/usr/share/snapper/filters" #define DEV_DIR "/dev" #define DEV_MAPPER_DIR "/dev/mapper" diff --git a/snapper/XmlFile.h b/snapper/XmlFile.h index 9f9db179..c80b7ca3 100644 --- a/snapper/XmlFile.h +++ b/snapper/XmlFile.h @@ -36,6 +36,7 @@ namespace snapper { using std::string; + using std::list; class XmlFile : private boost::noncopyable diff --git a/zypp-plugin/snapper_zypp_plugin.cc b/zypp-plugin/snapper_zypp_plugin.cc index e4b0c0af..5a8f6674 100644 --- a/zypp-plugin/snapper_zypp_plugin.cc +++ b/zypp-plugin/snapper_zypp_plugin.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019-2020] SUSE LLC + * Copyright (c) [2019-2021] SUSE LLC * * All Rights Reserved. * @@ -68,27 +68,29 @@ operator<<(ostream& os, const set& ss) } // Normally the only configuration this program needs is -// the /etc/snapper/zypp-plugin.conf file. +// the zypp-plugin.conf file in /etc/snapper or /usr/share/snapper. // But for testing we need more places to inject mocks. // This is done with SNAPPER_ZYPP_PLUGIN_* environment variables. // (Using argv is not useful since libzypp does not use it in the // plugin protocol.) -class ProgramOptions { +class ProgramOptions +{ + public: + string plugin_config; - string snapper_config; - DBusBusType bus; + string snapper_config = "root"; + DBusBusType bus = DBUS_BUS_SYSTEM; ProgramOptions() - : plugin_config("/etc/snapper/zypp-plugin.conf") - , snapper_config("root") - , bus(DBUS_BUS_SYSTEM) { const char* s; s = getenv("SNAPPER_ZYPP_PLUGIN_CONFIG"); if (s) plugin_config = s; + else + plugin_config = locate_file("zypp-plugin.conf", "/etc/snapper", "/usr/share/snapper"); s = getenv("SNAPPER_ZYPP_PLUGIN_SNAPPER_CONFIG"); if (s) @@ -98,6 +100,7 @@ public: if (s) bus = DBUS_BUS_SESSION; } + }; class SnapperZyppPlugin : public ZyppCommitPlugin {