From cc13d763f8dc85d6d8d1f1a818be33ee6376fdfd Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Tue, 7 Jun 2022 11:13:51 +0200 Subject: [PATCH] extended generic plugin support for rollback --- client/cmd-rollback.cc | 2 ++ doc/snapper.xml.in | 8 +++++++- scripts/10-plugin-test.sh | 6 ++++++ snapper/Hooks.cc | 7 +++++++ snapper/Hooks.h | 1 + 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 scripts/10-plugin-test.sh diff --git a/client/cmd-rollback.cc b/client/cmd-rollback.cc index 0533075d..2bf41c34 100644 --- a/client/cmd-rollback.cc +++ b/client/cmd-rollback.cc @@ -247,6 +247,7 @@ namespace snapper Hooks::rollback(filesystem->snapshotDir(snapshot1->getNum()), filesystem->snapshotDir(snapshot2->getNum())); + Hooks::rollback(subvolume, filesystem, snapshot1->getNum(), snapshot2->getNum()); if (print_number) cout << snapshot2->getNum() << endl; @@ -291,6 +292,7 @@ namespace snapper Hooks::rollback(filesystem->snapshotDir(previous_default->getNum()), filesystem->snapshotDir(snapshot->getNum())); + Hooks::rollback(subvolume, filesystem, previous_default->getNum(), snapshot->getNum()); } break; diff --git a/doc/snapper.xml.in b/doc/snapper.xml.in index 8f567f18..5d79eccb 100644 --- a/doc/snapper.xml.in +++ b/doc/snapper.xml.in @@ -883,8 +883,14 @@ Executed when the default snapshot gets changed + + + + Executed when a rollback is done + + - More arguments may be passed in the future. Using snapper in + More actions and arguments can be added any time. Using snapper in the plugins is not allowed. diff --git a/scripts/10-plugin-test.sh b/scripts/10-plugin-test.sh new file mode 100755 index 00000000..9de0a0cb --- /dev/null +++ b/scripts/10-plugin-test.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Use only for testing. + +echo `date +"%F %T"` $* >> /tmp/snapper-plugin-test.log + diff --git a/snapper/Hooks.cc b/snapper/Hooks.cc index b4924dba..3acf160a 100644 --- a/snapper/Hooks.cc +++ b/snapper/Hooks.cc @@ -143,4 +143,11 @@ namespace snapper #endif } + + void + Hooks::rollback(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) }); + } + } diff --git a/snapper/Hooks.h b/snapper/Hooks.h index 3b31857d..97a96ef1 100644 --- a/snapper/Hooks.h +++ b/snapper/Hooks.h @@ -48,6 +48,7 @@ namespace snapper 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 rollback(const string& subvolume, const Filesystem* filesystem, unsigned int old_num, unsigned int new_num); private: