Skip to content

Commit

Permalink
Merge pull request openSUSE#671 from aschnell/master
Browse files Browse the repository at this point in the history
- look for most configuration files in /etc/snapper and /usr/share/snapper
  • Loading branch information
aschnell authored Sep 22, 2021
2 parents bf6cd20 + 96e90e2 commit 1972426
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 50 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.0
0.9.1
2 changes: 1 addition & 1 deletion client/installation-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
14 changes: 8 additions & 6 deletions data/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions dists/debian/libsnapper.install
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion dists/debian/snapper-zypp-plugin.install
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
usr/lib/zypp/plugins/commit/snapper-zypp-plugin
etc/snapper/zypp-plugin.conf
usr/share/snapper/zypp-plugin.conf
10 changes: 6 additions & 4 deletions doc/snapper-zypp-plugin.conf.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -20,8 +20,10 @@

<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>
Expand Down
10 changes: 8 additions & 2 deletions doc/snapper-zypp-plugin.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -34,6 +34,12 @@
<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>

Expand Down
28 changes: 21 additions & 7 deletions doc/snapper.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -175,11 +175,13 @@
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>

Expand Down Expand Up @@ -858,12 +860,24 @@
<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>
Expand Down
7 changes: 7 additions & 0 deletions package/snapper.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Sep 21 13:30:29 CEST 2021 - [email protected]

- 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 - [email protected]

Expand Down
35 changes: 30 additions & 5 deletions snapper.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 17 additions & 2 deletions snapper/AppUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
{
Expand Down
10 changes: 7 additions & 3 deletions snapper/AppUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <sstream>
#include <locale>
#include <string>
#include <list>
#include <map>
#include <vector>
#include <stdexcept>
Expand All @@ -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<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);
Expand All @@ -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;
Expand Down
35 changes: 29 additions & 6 deletions snapper/Snapper.cc
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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"));
}
Expand Down Expand Up @@ -374,7 +397,7 @@ namespace snapper

try
{
SysconfigFile config(CONFIG_TEMPLATE_DIR "/" + template_name);
SysconfigFile config(template_file);

config.setName(CONFIGS_DIR "/" + config_name);

Expand Down
7 changes: 5 additions & 2 deletions snapper/SnapperDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 1972426

Please sign in to comment.