]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
extended generic plugin support 728/head
authorArvin Schnell <aschnell@suse.de>
Thu, 2 Jun 2022 11:05:55 +0000 (13:05 +0200)
committerArvin Schnell <aschnell@suse.de>
Thu, 2 Jun 2022 11:05:55 +0000 (13:05 +0200)
LIBVERSION
client/installation-helper.cc
doc/snapper.xml.in
package/snapper.changes
snapper/Btrfs.cc
snapper/Hooks.cc
snapper/Hooks.h
snapper/SnapperDefines.h
snapper/Snapshot.cc

index 5fe60723048a9d28c605f5359e50d70d3ea78bf6..dfda3e0b4f011bb0ab65e8585ae0ba122cf8f120 100644 (file)
@@ -1 +1 @@
-6.0.1
+6.1.0
index e3eed4fe25692bb4af2e0641047f6fcb22baa294..874c6c99ad5c82958f32db3e7698e34e595d02da 100644 (file)
@@ -120,7 +120,7 @@ step1(const string& device, const string& description, const string& cleanup,
 
     cout << "setting default subvolume" << endl;
 
-    snapper.getFilesystem()->setDefault(snapshot->getNum());
+    snapshot->setDefault();
 
     cout << "done" << endl;
 }
index c9d1aa3b5438c30e83017b59ee86ea97a2f4e6c8..8f567f18b6d02edaa0473f1eda0f8a2e7847b254 100644 (file)
@@ -2,13 +2,13 @@
 <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'>
index f831feeb0b49e1722f092ee26edef0b566f0e4c4..223d5a7f6cf305e923efa8ab93ae01a7e5279c2b 100644 (file)
@@ -1,3 +1,8 @@
+-------------------------------------------------------------------
+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
 
index 5dc1e2679574b7a1abd525801c01a1ac38897866..0f85b2dfdc55419b38c500122e849849366d8379 100644 (file)
@@ -1531,9 +1531,9 @@ namespace snapper
                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)
        {
index 54dec21681468e056b03f00e043e4bbec317e1e6..b4924dba937aa0a22835d58de2e0e821d7ff30cc 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * 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() });
     }
 
 
@@ -73,6 +78,7 @@ namespace snapper
     Hooks::delete_config(const string& subvolume, const Filesystem* filesystem)
     {
        grub(subvolume, filesystem, "--disable");
+       run_scripts({ "delete-config", subvolume, filesystem->fstype() });
     }
 
 
@@ -80,7 +86,7 @@ namespace snapper
     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()) });
     }
 
 
@@ -88,7 +94,7 @@ namespace snapper
     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()) });
     }
 
 
@@ -96,15 +102,17 @@ namespace snapper
     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)
     {
index a81fa31ca8b65a682fe2496978cc9094c4faea92..3b31857de3fe13e7b6db002a852d25f9dcfd1a29 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
+ * Copyright (c) 2022 SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -37,13 +38,13 @@ namespace snapper
     {
     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);
@@ -53,6 +54,8 @@ namespace snapper
        static void grub(const string& subvolume, const Filesystem* filesystem,
                         const char* option);
 
+       static void run_scripts(const vector<string>& args);
+
     };
 
 }
index 46f0c6f161f9e169daf8aa73d08eabe0dd17e3d9..cf218ab00871f289293c56e3adb961b41f25c7b1 100644 (file)
@@ -37,6 +37,8 @@
 #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"
 
index 384701a21f96b1b4c70e368d6565bce73836a135..abf17aa8c3be005986fa1dacd45bd5f8cbced441 100644 (file)
@@ -144,7 +144,7 @@ namespace snapper
     void
     Snapshot::setDefault() const
     {
-       return snapper->getFilesystem()->setDefault(num);
+       snapper->getFilesystem()->setDefault(num);
     }
 
 
@@ -792,9 +792,9 @@ namespace snapper
        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);
     }