]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- call generic plugins before and after the action 761/head
authorArvin Schnell <aschnell@suse.de>
Thu, 22 Dec 2022 08:05:10 +0000 (09:05 +0100)
committerArvin Schnell <aschnell@suse.de>
Fri, 23 Dec 2022 10:18:56 +0000 (11:18 +0100)
LIBVERSION
client/cmd-rollback.cc
client/installation-helper.cc
doc/snapper.xml.in
package/snapper.changes
snapper/Btrfs.cc
snapper/Hooks.cc
snapper/Hooks.h
snapper/Snapper.cc
snapper/Snapshot.cc

index dfda3e0b4f011bb0ab65e8585ae0ba122cf8f120..6abaeb2f90723ba328101fc117a1f19e93407e47 100644 (file)
@@ -1 +1 @@
-6.1.0
+6.2.0
index 2bf41c34f12acb472459217715e17f585781f5c1..f1703569bfb1cecf48c870d21691b1051260615f 100644 (file)
@@ -247,7 +247,8 @@ namespace snapper
 
                Hooks::rollback(filesystem->snapshotDir(snapshot1->getNum()),
                                filesystem->snapshotDir(snapshot2->getNum()));
-               Hooks::rollback(subvolume, filesystem, snapshot1->getNum(), snapshot2->getNum());
+               Hooks::rollback(Hooks::Stage::POST_ACTION, subvolume, filesystem, snapshot1->getNum(),
+                               snapshot2->getNum());
 
                if (print_number)
                    cout << snapshot2->getNum() << endl;
@@ -292,7 +293,8 @@ namespace snapper
 
                Hooks::rollback(filesystem->snapshotDir(previous_default->getNum()),
                                filesystem->snapshotDir(snapshot->getNum()));
-               Hooks::rollback(subvolume, filesystem, previous_default->getNum(), snapshot->getNum());
+               Hooks::rollback(Hooks::Stage::POST_ACTION, subvolume, filesystem, previous_default->getNum(),
+                               snapshot->getNum());
            }
            break;
 
index 874c6c99ad5c82958f32db3e7698e34e595d02da..248cf3506e3dee1c5f83749590f1f87f9f6a3c7f 100644 (file)
@@ -214,7 +214,7 @@ step4()
 
     cout << "running external programs" << endl;
 
-    Hooks::create_config("/", &btrfs);
+    Hooks::create_config(Hooks::Stage::POST_ACTION, "/", &btrfs);
 
     cout << "done" << endl;
 }
index 5d79eccbdccd5e0ff2f818a064feb400939ad628..fce065890aafd124fda77e42937194752f4e6e77 100644 (file)
@@ -2,13 +2,13 @@
 <refentry id='snapper8' xmlns:xlink="http://www.w3.org/1999/xlink">
 
   <refentryinfo>
-    <date>2022-06-02</date>
+    <date>2022-12-22</date>
   </refentryinfo>
 
   <refmeta>
     <refentrytitle>snapper</refentrytitle>
     <manvolnum>8</manvolnum>
-    <refmiscinfo class='date'>2022-06-02</refmiscinfo>
+    <refmiscinfo class='date'>2022-12-22</refmiscinfo>
     <refmiscinfo class='version'>@VERSION@</refmiscinfo>
     <refmiscinfo class='manual'>Filesystem Snapshot Management</refmiscinfo>
   </refmeta>
     following actions are defined:</para>
     <variablelist>
       <varlistentry>
-       <term><option>create-config <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
+       <term><option>create-config-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
        <listitem>
-         <para>Executed when a new config gets created</para>
+         <para>Executed before a new config is created</para>
        </listitem>
       </varlistentry>
       <varlistentry>
-       <term><option>delete-config <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
+       <term><option>create-config-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
        <listitem>
-         <para>Executed when a config gets deleted</para>
+         <para>Executed after a new config was created</para>
        </listitem>
       </varlistentry>
       <varlistentry>
-       <term><option>create-snapshot <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+       <term><option>delete-config-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
        <listitem>
-         <para>Executed when a new snapshot gets created</para>
+         <para>Executed before a config is deleted</para>
        </listitem>
       </varlistentry>
       <varlistentry>
-       <term><option>delete-snapshot <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+       <term><option>delete-config-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
        <listitem>
-         <para>Executed when a snapshot is removed</para>
+         <para>Executed after a config was deleted</para>
        </listitem>
       </varlistentry>
       <varlistentry>
-       <term><option>modify-snapshot <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+       <term><option>create-snapshot-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
        <listitem>
-         <para>Executed when a snapshot gets modified</para>
+         <para>Executed before a new snapshot is created</para>
        </listitem>
       </varlistentry>
       <varlistentry>
-       <term><option>set-default-snapshot <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+       <term><option>create-snapshot-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
        <listitem>
-         <para>Executed when the default snapshot gets changed</para>
+         <para>Executed after a new snapshot was created</para>
        </listitem>
       </varlistentry>
       <varlistentry>
-       <term><option>rollback <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>old-snapshot-number</replaceable> <replaceable>new-snapshot-number</replaceable></option></term>
+       <term><option>modify-snapshot-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
        <listitem>
-         <para>Executed when a rollback is done</para>
+         <para>Executed before a snapshot is modified</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term><option>modify-snapshot-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+       <listitem>
+         <para>Executed after a snapshot was modified</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term><option>delete-snapshot-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+       <listitem>
+         <para>Executed before a snapshot is removed</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term><option>delete-snapshot-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+       <listitem>
+         <para>Executed after a snapshot was removed</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term><option>set-default-snapshot-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+       <listitem>
+         <para>Executed before the default snapshot is changed</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term><option>set-default-snapshot-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+       <listitem>
+         <para>Executed after the default snapshot was changed</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term><option>rollback-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>old-snapshot-number</replaceable> <replaceable>new-snapshot-number</replaceable></option></term>
+       <listitem>
+         <para>Executed after a rollback was done</para>
        </listitem>
       </varlistentry>
     </variablelist>
index 3dde191a06fadd598c00abf14dba04ea023044c6..8f0f10dc7c2725a04acce1c658c4b10f50432005 100644 (file)
@@ -1,3 +1,8 @@
+-------------------------------------------------------------------
+Thu Dec 22 09:03:33 CET 2022 - aschnell@suse.com
+
+- call generic plugins before and after the action
+
 -------------------------------------------------------------------
 Mon Dec 05 08:13:07 CET 2022 - aschnell@suse.com
 
index 0f85b2dfdc55419b38c500122e849849366d8379..5e68fcebd9a7d181acf6124a298c0a04d68cc43b 100644 (file)
@@ -1518,6 +1518,8 @@ namespace snapper
     {
        try
        {
+           Hooks::set_default_snapshot(Hooks::Stage::PRE_ACTION, subvolume, this, num);
+
            SDir general_dir = openGeneralDir();
 
            if (num == 0)
@@ -1533,7 +1535,7 @@ namespace snapper
                set_default_id(general_dir.fd(), id);
            }
 
-           Hooks::set_default_snapshot(subvolume, this, num);
+           Hooks::set_default_snapshot(Hooks::Stage::POST_ACTION, subvolume, this, num);
        }
        catch (const runtime_error& e)
        {
index 3acf160a12980a1cff39f2b3285900a9db4da33a..d5a51eeaa3b884bf9a03c929610bec5462ba598c 100644 (file)
@@ -66,50 +66,113 @@ namespace snapper
     }
 
 
+    // Actions without -pre/-post are legacy and deprecated (2022-12-22).
+
+
     void
-    Hooks::create_config(const string& subvolume, const Filesystem* filesystem)
+    Hooks::create_config(Stage stage, const string& subvolume, const Filesystem* filesystem)
     {
-       grub(subvolume, filesystem, "--enable");
-       run_scripts({ "create-config", subvolume, filesystem->fstype() });
+       switch (stage)
+       {
+           case Stage::PRE_ACTION:
+               run_scripts({ "create-config-pre", subvolume, filesystem->fstype() });
+               break;
+
+           case Stage::POST_ACTION:
+               grub(subvolume, filesystem, "--enable");
+               run_scripts({ "create-config", subvolume, filesystem->fstype() });
+               run_scripts({ "create-config-post", subvolume, filesystem->fstype() });
+               break;
+       }
     }
 
 
     void
-    Hooks::delete_config(const string& subvolume, const Filesystem* filesystem)
+    Hooks::delete_config(Stage stage, const string& subvolume, const Filesystem* filesystem)
     {
-       grub(subvolume, filesystem, "--disable");
-       run_scripts({ "delete-config", subvolume, filesystem->fstype() });
+       switch (stage)
+       {
+           case Stage::PRE_ACTION:
+               grub(subvolume, filesystem, "--disable");
+               run_scripts({ "delete-config-pre", subvolume, filesystem->fstype() });
+               run_scripts({ "delete-config", subvolume, filesystem->fstype() });
+               break;
+
+           case Stage::POST_ACTION:
+               run_scripts({ "delete-config-post", subvolume, filesystem->fstype() });
+               break;
+       }
     }
 
 
     void
-    Hooks::create_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
+    Hooks::create_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
     {
-       grub(subvolume, filesystem, "--refresh");
-       run_scripts({ "create-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+       switch (stage)
+       {
+           case Stage::PRE_ACTION:
+               run_scripts({ "create-snapshot-pre", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+               break;
+
+           case Stage::POST_ACTION:
+               grub(subvolume, filesystem, "--refresh");
+               run_scripts({ "create-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+               run_scripts({ "create-snapshot-post", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+               break;
+       }
     }
 
 
     void
-    Hooks::modify_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
+    Hooks::modify_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
     {
-       grub(subvolume, filesystem, "--refresh");
-       run_scripts({ "modify-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+       switch (stage)
+       {
+           case Stage::PRE_ACTION:
+               run_scripts({ "modify-snapshot-pre", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+               break;
+
+           case Stage::POST_ACTION:
+               grub(subvolume, filesystem, "--refresh");
+               run_scripts({ "modify-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+               run_scripts({ "modify-snapshot-post", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+               break;
+       }
     }
 
 
     void
-    Hooks::delete_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
+    Hooks::delete_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
     {
-       grub(subvolume, filesystem, "--refresh");
-       run_scripts({ "delete-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+       switch (stage)
+       {
+           case Stage::PRE_ACTION:
+               run_scripts({ "delete-snapshot-pre", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+               break;
+
+           case Stage::POST_ACTION:
+               grub(subvolume, filesystem, "--refresh");
+               run_scripts({ "delete-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+               run_scripts({ "delete-snapshot-post", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+               break;
+       }
     }
 
 
     void
-    Hooks::set_default_snapshot(const string& subvolume, const Filesystem* filesystem, unsigned int num)
+    Hooks::set_default_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem, unsigned int num)
     {
-       run_scripts({ "set-default-snapshot", subvolume, filesystem->fstype(), std::to_string(num) });
+       switch (stage)
+       {
+           case Stage::PRE_ACTION:
+               run_scripts({ "set-default-snapshot-pre", subvolume, filesystem->fstype(), std::to_string(num) });
+               break;
+
+           case Stage::POST_ACTION:
+               run_scripts({ "set-default-snapshot", subvolume, filesystem->fstype(), std::to_string(num) });
+               run_scripts({ "set-default-snapshot-post", subvolume, filesystem->fstype(), std::to_string(num) });
+               break;
+       }
     }
 
 
@@ -145,9 +208,31 @@ namespace snapper
 
 
     void
-    Hooks::rollback(const string& subvolume, const Filesystem* filesystem, unsigned int old_num, unsigned int new_num)
+    Hooks::rollback(const string& subvolume, const Filesystem* filesystem, unsigned int old_num,
+                   unsigned int new_num)
+    {
+       rollback(Stage::POST_ACTION, subvolume, filesystem, old_num, new_num);
+    }
+
+
+    void
+    Hooks::rollback(Stage stage, const string& subvolume, const Filesystem* filesystem, unsigned int old_num,
+                   unsigned int new_num)
     {
-       run_scripts({ "rollback", subvolume, filesystem->fstype(), std::to_string(old_num), std::to_string(new_num) });
+       switch (stage)
+       {
+           case Stage::PRE_ACTION:
+               run_scripts({ "rollback-pre", subvolume, filesystem->fstype(), std::to_string(old_num),
+                       std::to_string(new_num) });
+               break;
+
+           case Stage::POST_ACTION:
+               run_scripts({ "rollback", subvolume, filesystem->fstype(), std::to_string(old_num),
+                       std::to_string(new_num) });
+               run_scripts({ "rollback-post", subvolume, filesystem->fstype(), std::to_string(old_num),
+                       std::to_string(new_num) });
+               break;
+       }
     }
 
 }
index 97a96ef17b370e3d4e73f9170187c00b142a3af2..ef0a7c3549ae700ddc24f44561db3cf581dc2377 100644 (file)
@@ -38,17 +38,27 @@ namespace snapper
     {
     public:
 
-       static void create_config(const string& subvolume, const Filesystem* filesystem);
-       static void delete_config(const string& subvolume, const Filesystem* filesystem);
+       enum class Stage { PRE_ACTION, POST_ACTION };
 
-       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 create_config(Stage stage, const string& subvolume, const Filesystem* filesystem);
+       static void delete_config(Stage stage, const string& subvolume, const Filesystem* filesystem);
 
-       static void set_default_snapshot(const string& subvolume, const Filesystem* filesystem, unsigned int num);
+       static void create_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem,
+                                   const Snapshot& snapshot);
+       static void modify_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem,
+                                   const Snapshot& snapshot);
+       static void delete_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem,
+                                   const Snapshot& snapshot);
+
+       static void set_default_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem,
+                                        unsigned int num);
 
        static void rollback(const string& old_root, const string& new_root);
-       static void rollback(const string& subvolume, const Filesystem* filesystem, unsigned int old_num, unsigned int new_num);
+
+       static void rollback(const string& subvolume, const Filesystem* filesystem, unsigned int old_num,
+                            unsigned int new_num) __attribute__((deprecated));
+       static void rollback(Stage stage, const string& subvolume, const Filesystem* filesystem, unsigned int old_num,
+                            unsigned int new_num);
 
     private:
 
index 87303500899a71faf6f2b89aee392f35f723f88d..3d8b4371d56bbea6127afff90de3bdbfa3c42f37 100644 (file)
@@ -390,6 +390,8 @@ namespace snapper
            SN_THROW(CreateConfigFailedException(e.what()));
        }
 
+       Hooks::create_config(Hooks::Stage::PRE_ACTION, subvolume, filesystem.get());
+
        try
        {
            SysconfigFile sysconfig(SYSCONFIG_FILE);
@@ -452,7 +454,7 @@ namespace snapper
            SN_RETHROW(e);
        }
 
-       Hooks::create_config(subvolume, filesystem.get());
+       Hooks::create_config(Hooks::Stage::POST_ACTION, subvolume, filesystem.get());
     }
 
 
@@ -464,7 +466,7 @@ namespace snapper
 
        unique_ptr<Snapper> snapper(new Snapper(config_name, root_prefix));
 
-       Hooks::delete_config(snapper->subvolumeDir(), snapper->getFilesystem());
+       Hooks::delete_config(Hooks::Stage::PRE_ACTION, snapper->subvolumeDir(), snapper->getFilesystem());
 
        Snapshots& snapshots = snapper->getSnapshots();
 
@@ -524,6 +526,8 @@ namespace snapper
 
            SN_THROW(DeleteConfigFailedException("modifying sysconfig-file failed"));
        }
+
+       Hooks::delete_config(Hooks::Stage::POST_ACTION, snapper->subvolumeDir(), snapper->getFilesystem());
     }
 
 
index abf17aa8c3be005986fa1dacd45bd5f8cbced441..1974bbaca6d1554ec34e44adc5f090609865b2d8 100644 (file)
@@ -701,6 +701,9 @@ namespace snapper
        // parent == end indicates the btrfs default subvolume. Unclean, but
        // adding a special snapshot like current needs too many API changes.
 
+       Hooks::create_snapshot(Hooks::Stage::PRE_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
+                              snapshot);
+
        try
        {
            if (parent != end())
@@ -733,7 +736,8 @@ namespace snapper
            SN_RETHROW(e);
        }
 
-       Hooks::create_snapshot(snapper->subvolumeDir(), snapper->getFilesystem(), snapshot);
+       Hooks::create_snapshot(Hooks::Stage::POST_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
+                              snapshot);
 
        return entries.insert(entries.end(), snapshot);
     }
@@ -747,13 +751,17 @@ namespace snapper
 
        checkUserdata(smd.userdata);
 
+       Hooks::modify_snapshot(Hooks::Stage::PRE_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
+                              *snapshot);
+
        snapshot->description = smd.description;
        snapshot->cleanup = smd.cleanup;
        snapshot->userdata = smd.userdata;
 
        snapshot->writeInfo();
 
-       Hooks::modify_snapshot(snapper->subvolumeDir(), snapper->getFilesystem(), *snapshot);
+       Hooks::modify_snapshot(Hooks::Stage::POST_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
+                              *snapshot);
     }
 
 
@@ -764,6 +772,9 @@ namespace snapper
            snapshot->isActive())
            SN_THROW(IllegalSnapshotException());
 
+       Hooks::delete_snapshot(Hooks::Stage::PRE_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
+                              *snapshot);
+
        snapshot->deleteFilesystemSnapshot();
 
        SDir info_dir = snapshot->openInfoDir();
@@ -792,7 +803,8 @@ namespace snapper
        SDir infos_dir = snapper->openInfosDir();
        infos_dir.unlink(decString(snapshot->getNum()), AT_REMOVEDIR);
 
-       Hooks::delete_snapshot(snapper->subvolumeDir(), snapper->getFilesystem(), *snapshot);
+       Hooks::delete_snapshot(Hooks::Stage::POST_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
+                              *snapshot);
 
        entries.erase(snapshot);
     }