]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- look for most configuration files in /etc/snapper and /usr/share/snapper (bsc#1189601) 671/head
authorArvin Schnell <aschnell@suse.de>
Wed, 22 Sep 2021 08:37:14 +0000 (10:37 +0200)
committerArvin Schnell <aschnell@suse.de>
Wed, 22 Sep 2021 08:37:14 +0000 (10:37 +0200)
16 files changed:
VERSION
client/installation-helper.cc
data/Makefile.am
dists/debian/libsnapper.install
dists/debian/snapper-zypp-plugin.install
doc/snapper-zypp-plugin.conf.xml.in
doc/snapper-zypp-plugin.xml.in
doc/snapper.xml.in
package/snapper.changes
snapper.spec.in
snapper/AppUtil.cc
snapper/AppUtil.h
snapper/Snapper.cc
snapper/SnapperDefines.h
snapper/XmlFile.h
zypp-plugin/snapper_zypp_plugin.cc

diff --git a/VERSION b/VERSION
index ac39a106c48515b621e90c028ed94c6f71bc03fa..f374f6662e9a1983e9b8a534a3295df618772ffe 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.9.0
+0.9.1
index 66567b4c707d824cb2318545079383e03c855b6d..db0a2a249d4bb1da0d4eaff587b010d43fddad43 100644 (file)
@@ -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");
 
index 684d92b1725fce945e83bf5f8f9f36eb7419b4e7..fa54bd4f5968b4f92db7266f8307d6afe058c062 100644 (file)
@@ -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
index 52e37009a542ac708fd5977746b544e9915bc4d8..a866f5fee3567ebfbfd2b2ffe0705041777a7051 100644 (file)
@@ -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
index 19877a8c53195da14b7d743a23aac82785b39944..94a37e260c58c4c40cd1731f0e9f86cdce923596 100644 (file)
@@ -1,2 +1,2 @@
 usr/lib/zypp/plugins/commit/snapper-zypp-plugin
-etc/snapper/zypp-plugin.conf
+usr/share/snapper/zypp-plugin.conf
index d629f16e3731b6634eb3fdfe1db82129b334b1cb..40e0eeabf505eed2cc860d66bfdc2bda764b9999 100644 (file)
@@ -2,13 +2,13 @@
 <refentry id='snapper-zypp-plugin.conf5'>
 
   <refentryinfo>
-    <date>2013-11-22</date>
+    <date>2021-09-21</date>
   </refentryinfo>
 
   <refmeta>
     <refentrytitle>snapper-zypp-plugin.conf</refentrytitle>
     <manvolnum>5</manvolnum>
-    <refmiscinfo class='date'>2013-11-22</refmiscinfo>
+    <refmiscinfo class='date'>2021-09-21</refmiscinfo>
     <refmiscinfo class='version'>@VERSION@</refmiscinfo>
     <refmiscinfo class='manual'>Filesystem Snapshot Management</refmiscinfo>
   </refmeta>
 
   <refsect1 id='description'>
     <title>DESCRIPTION</title>
-    <para>The file <filename>/etc/snapper/zypp-plugin.conf</filename> contains
-    the configuation for snapper-zypp-plugin.</para>
+    <para>The file <filename>/etc/snapper/zypp-plugin.conf</filename>
+    or as a fallback
+    <filename>/usr/share/snapper/zypp-plugin.conf</filename> contains the
+    configuation for snapper-zypp-plugin.</para>
 
     <para>The file uses XML syntax. For the XML structure have a look at the
     provided default config.</para>
index 3e1fc83afa46ceedcd11a81da312f1785bf0219e..4ddba3c28015b4d5e2ce8b1eb02d030701a94d99 100644 (file)
@@ -2,13 +2,13 @@
 <refentry id='snapper-zypp-plugin8'>
 
   <refentryinfo>
-    <date>2013-11-22</date>
+    <date>2021-09-21</date>
   </refentryinfo>
 
   <refmeta>
     <refentrytitle>snapper-zypp-plugin</refentrytitle>
     <manvolnum>8</manvolnum>
-    <refmiscinfo class='date'>2013-11-22</refmiscinfo>
+    <refmiscinfo class='date'>2021-09-21</refmiscinfo>
     <refmiscinfo class='version'>@VERSION@</refmiscinfo>
     <refmiscinfo class='manual'>Filesystem Snapshot Management</refmiscinfo>
   </refmeta>
          <para>Configuration file. New in version 0.1.8.</para>
        </listitem>
       </varlistentry>
+      <varlistentry>
+       <term><filename>/usr/share/snapper/zypp-plugin.conf</filename></term>
+       <listitem>
+         <para>Fallback configuration file. New in version 0.9.1.</para>
+       </listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
 
index 337eae0ad421c29f9176b528372c53198fc688a2..dd6d41b17d50eb73e8d7cbc777d67b8fd0e6e4b4 100644 (file)
@@ -2,13 +2,13 @@
 <refentry id='snapper8' xmlns:xlink="http://www.w3.org/1999/xlink">
 
   <refentryinfo>
-    <date>2020-06-15</date>
+    <date>2021-09-21</date>
   </refentryinfo>
 
   <refmeta>
     <refentrytitle>snapper</refentrytitle>
     <manvolnum>8</manvolnum>
-    <refmiscinfo class='date'>2020-06-15</refmiscinfo>
+    <refmiscinfo class='date'>2021-09-21</refmiscinfo>
     <refmiscinfo class='version'>@VERSION@</refmiscinfo>
     <refmiscinfo class='manual'>Filesystem Snapshot Management</refmiscinfo>
   </refmeta>
       e.g. <filename>/etc/mtab</filename>. Such files should never be
       reverted. To help users, snapper allows one to ignore these files.</para>
 
-      <para>Each line in all
-      files <filename>/etc/snapper/filters/*.txt</filename> specifies a
-      pattern. When snapper computes the difference between two snapshots it
-      ignores all files and directories matching any of those patterns by
-      using
+      <para>Filters are read from the files
+      <filename>/etc/snapper/filters/*.txt</filename> and
+      <filename>/usr/share/snapper/filters/*.txt</filename>, 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
       <citerefentry role="nolink"><refentrytitle>fnmatch</refentrytitle><manvolnum>3</manvolnum></citerefentry>
       with the flag FNM_LEADING_DIR.</para>
 
          <para>Directory containing configuration templates.</para>
        </listitem>
       </varlistentry>
+      <varlistentry>
+       <term><filename>/usr/share/snapper/config-templates</filename></term>
+       <listitem>
+         <para>Fallback directory containing configuration templates.</para>
+       </listitem>
+      </varlistentry>
       <varlistentry>
        <term><filename>/etc/snapper/filters/*.txt</filename></term>
        <listitem>
          <para>Filter files.</para>
        </listitem>
       </varlistentry>
+      <varlistentry>
+       <term><filename>/usr/share/snapper/filters/*.txt</filename></term>
+       <listitem>
+         <para>Fallback filter files.</para>
+       </listitem>
+      </varlistentry>
       <varlistentry>
        <term><filename>/var/log/snapper.log</filename></term>
        <listitem>
index 62712fff40c0560968958b659ebd921943f1c446..638734649c16d69026b0b805557b719fca67c7a5 100644 (file)
@@ -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
 
index 5ab0d7e1caf8d9b7803a6252f7e29591a63103a5..c438939607fd3a1bf60fd8f69d379f5c1aedab73 100644 (file)
@@ -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
index 1c0ff834c8477930800189723a52cfb0198d424a..995657074de53c17f7586e1ccf6e819980d0191d 100644 (file)
@@ -56,10 +56,10 @@ namespace snapper
     }
 
 
-    list<string>
+    vector<string>
     glob(const string& path, int flags)
     {
-       list<string> ret;
+       vector<string> 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()
     {
index edee3255842e324ab226fc5043a5317597190728..ccde04ddaeabda5b894a53f38c882b8bbf68763b 100644 (file)
@@ -33,7 +33,6 @@
 #include <sstream>
 #include <locale>
 #include <string>
-#include <list>
 #include <map>
 #include <vector>
 #include <stdexcept>
 namespace snapper
 {
     using std::string;
-    using std::list;
     using std::map;
     using std::vector;
 
 
     bool checkDir(const string& Path_Cv);
 
-    list<string> glob(const string& path, int flags);
+    vector<string> 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;
index 52e8661e7e8c615c1bd5e41a2d8af90fb445811d..89f7b8ccf321a201d2521ff638898fc8fe477a57 100644 (file)
@@ -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<string> files = glob(FILTERS_DIR "/*.txt", GLOB_NOSORT);
-       for (list<string>::const_iterator it = files.begin(); it != files.end(); ++it)
+       const vector<string> etc_files = glob(ETC_FILTERS_DIR "/*.txt", GLOB_NOSORT);
+       const vector<string> usr_files = glob(USR_FILTERS_DIR "/*.txt", GLOB_NOSORT);
+
+       // all files from /etc
+       vector<string> 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);
 
index d21d26282abe110bbee6f6c9aeb4e7bae2d06b26..c43036c6efb3828a8cfaed00c95181cd41d183bd 100644 (file)
 #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"
index 9f9db1792b1e1d36f4c4e757a0e7c22d4bbe3b54..c80b7ca39d85aee07abdc9e43397152428344bdc 100644 (file)
@@ -36,6 +36,7 @@
 namespace snapper
 {
     using std::string;
+    using std::list;
 
 
     class XmlFile : private boost::noncopyable
index e4b0c0aff472d8bc10770942a8c01324495e722f..5a8f66746b75428412cc0b00747790c5ae20cbde 100644 (file)
@@ -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<string>& 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 {