cout << "setting default subvolume" << endl;
- snapper.getFilesystem()->setDefault(snapshot->getNum());
+ snapshot->setDefault();
cout << "done" << endl;
}
<refentry id='snapper8' xmlns:xlink="http://www.w3.org/1999/xlink">
<refentryinfo>
- <date>2021-09-21</date>
+ <date>2022-06-02</date>
</refentryinfo>
<refmeta>
<refentrytitle>snapper</refentrytitle>
<manvolnum>8</manvolnum>
- <refmiscinfo class='date'>2021-09-21</refmiscinfo>
+ <refmiscinfo class='date'>2022-06-02</refmiscinfo>
<refmiscinfo class='version'>@VERSION@</refmiscinfo>
<refmiscinfo class='manual'>Filesystem Snapshot Management</refmiscinfo>
</refmeta>
have to be placed in <filename>/usr/lib/snapper/plugins</filename>.
The name has to start with a digit, execution order is alphabetical.</para>
<para>The first argument of a script is the action snapper executed. The
- following actions are defined:</para>
+ following actions are defined:</para>
<variablelist>
<varlistentry>
- <term><option>create-snapshot <replaceable>subvolume</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <term><option>create-config <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
+ <listitem>
+ <para>Executed when a new config gets created</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>delete-config <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
+ <listitem>
+ <para>Executed when a config gets deleted</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>create-snapshot <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
<listitem>
<para>Executed when a new snapshot gets created</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>delete-snapshot <replaceable>subvolume</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <term><option>delete-snapshot <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
<listitem>
<para>Executed when a snapshot is removed</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>modify-snapshot <replaceable>subvolume</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <term><option>modify-snapshot <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
<listitem>
<para>Executed when a snapshot gets modified</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>set-default-snapshot <replaceable>subvolume</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <term><option>set-default-snapshot <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
<listitem>
<para>Executed when the default snapshot gets changed</para>
</listitem>
</varlistentry>
</variablelist>
+ <para>More arguments may be passed in the future. Using snapper in
+ the plugins is not allowed.</para>
</refsect1>
<refsect1 id='files'>
+-------------------------------------------------------------------
+Thu Jun 02 13:01:49 CEST 2022 - lnussel@suse.com
+
+- added generic plugin supprot (gh#openSUSE/snapper#727)
+
-------------------------------------------------------------------
Tue May 03 08:46:28 CEST 2022 - aschnell@suse.com
SDir snapshot_dir = openSnapshotDir(num);
subvolid_t id = get_id(snapshot_dir.fd());
set_default_id(general_dir.fd(), id);
-
- Hooks::set_default_snapshot(subvolume, this, num);
}
+
+ Hooks::set_default_snapshot(subvolume, this, num);
}
catch (const runtime_error& e)
{
/*
* Copyright (c) [2011-2015] Novell, Inc.
+ * Copyright (c) 2022 SUSE LLC
*
* All Rights Reserved.
*
#include "config.h"
-#include <string.h>
-
-#include <boost/algorithm/string/join.hpp>
-
#include "snapper/FileUtils.h"
#include "snapper/Hooks.h"
#include "snapper/SystemCmd.h"
-#include "snapper/Log.h"
+#include "snapper/SnapperDefines.h"
namespace snapper
{
using namespace std;
+
static bool
- _plugins_filter_entries(unsigned char type, const char* name)
+ plugins_filter_entries(unsigned char type, const char* name)
{
// must start with digit
- if (*name >= '0' && *name <= '9')
- return true;
- return false;
+ return *name >= '0' && *name <= '9';
}
+
void
- Hooks::run_scripts(const list<string>& args)
+ Hooks::run_scripts(const vector<string>& args)
{
- SDir dir("/usr/lib/snapper/plugins");
+ try
+ {
+ SDir dir(PLUGINS_DIR);
- vector<string> scripts = dir.entries(_plugins_filter_entries);
+ vector<string> scripts = dir.entries(plugins_filter_entries);
std::sort(scripts.begin(), scripts.end());
for (const string& script : scripts)
{
- string cmdln = dir.fullname(script);
- for (const string& arg : args) {
- cmdln += " " + quote(arg);
- }
- SystemCmd cmd(cmdln);
+ string cmd_line = dir.fullname(script);
+ for (const string& arg : args)
+ cmd_line += " " + quote(arg);
+ SystemCmd cmd(cmd_line);
}
+ }
+ catch (const Exception& e)
+ {
+ SN_CAUGHT(e);
+ }
}
+
void
Hooks::create_config(const string& subvolume, const Filesystem* filesystem)
{
grub(subvolume, filesystem, "--enable");
+ run_scripts({ "create-config", subvolume, filesystem->fstype() });
}
Hooks::delete_config(const string& subvolume, const Filesystem* filesystem)
{
grub(subvolume, filesystem, "--disable");
+ run_scripts({ "delete-config", subvolume, filesystem->fstype() });
}
Hooks::create_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
{
grub(subvolume, filesystem, "--refresh");
- run_scripts(std::list<string>({"create-snapshot", subvolume, std::to_string(snapshot.getNum())}));
+ run_scripts({ "create-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
}
Hooks::modify_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
{
grub(subvolume, filesystem, "--refresh");
- run_scripts(std::list<string>({"modify-snapshot", subvolume, std::to_string(snapshot.getNum())}));
+ run_scripts({ "modify-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
}
Hooks::delete_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
{
grub(subvolume, filesystem, "--refresh");
- run_scripts(std::list<string>({"delete-snapshot", subvolume, std::to_string(snapshot.getNum())}));
+ run_scripts({ "delete-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
}
+
void
Hooks::set_default_snapshot(const string& subvolume, const Filesystem* filesystem, unsigned int num)
{
- run_scripts(std::list<string>({"set-default-snapshot", subvolume, std::to_string(num)}));
+ run_scripts({ "set-default-snapshot", subvolume, filesystem->fstype(), std::to_string(num) });
}
+
void
Hooks::grub(const string& subvolume, const Filesystem* filesystem, const char* option)
{
/*
* Copyright (c) [2011-2015] Novell, Inc.
+ * Copyright (c) 2022 SUSE LLC
*
* All Rights Reserved.
*
{
public:
- static void run_scripts(const list<string>& args);
static void create_config(const string& subvolume, const Filesystem* filesystem);
static void delete_config(const string& subvolume, const Filesystem* filesystem);
static void create_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot);
static void modify_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot);
static void delete_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot);
+
static void set_default_snapshot(const string& subvolume, const Filesystem* filesystem, unsigned int num);
static void rollback(const string& old_root, const string& new_root);
static void grub(const string& subvolume, const Filesystem* filesystem,
const char* option);
+ static void run_scripts(const vector<string>& args);
+
};
}
#define ETC_FILTERS_DIR "/etc/snapper/filters"
#define USR_FILTERS_DIR "/usr/share/snapper/filters"
+#define PLUGINS_DIR "/usr/lib/snapper/plugins"
+
#define DEV_DIR "/dev"
#define DEV_MAPPER_DIR "/dev/mapper"
void
Snapshot::setDefault() const
{
- return snapper->getFilesystem()->setDefault(num);
+ snapper->getFilesystem()->setDefault(num);
}
SDir infos_dir = snapper->openInfosDir();
infos_dir.unlink(decString(snapshot->getNum()), AT_REMOVEDIR);
- entries.erase(snapshot);
-
Hooks::delete_snapshot(snapper->subvolumeDir(), snapper->getFilesystem(), *snapshot);
+
+ entries.erase(snapshot);
}