From: Arvin Schnell Date: Tue, 3 Mar 2015 09:23:57 +0000 (+0100) Subject: - allow to set userdata for snapshots created by helper programs X-Git-Tag: v0.2.8~15^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F156%2Fhead;p=thirdparty%2Fsnapper.git - allow to set userdata for snapshots created by helper programs --- diff --git a/client/Makefile.am b/client/Makefile.am index dabca854..aecddbde 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -23,7 +23,8 @@ libexecdir = /usr/lib/snapper libexec_PROGRAMS = installation-helper systemd-helper installation_helper_SOURCES = \ - installation-helper.cc + installation-helper.cc \ + misc.cc misc.h installation_helper_LDADD = ../snapper/libsnapper.la utils/libutils.la @@ -32,6 +33,7 @@ systemd_helper_SOURCES = \ types.cc types.h \ commands.cc commands.h \ cleanup.cc cleanup.h \ + misc.cc misc.h \ errors.cc errors.h systemd_helper_LDADD = ../snapper/libsnapper.la utils/libutils.la ../dbus/libdbus.la diff --git a/client/installation-helper.cc b/client/installation-helper.cc index 8e80976b..1bb0b462 100644 --- a/client/installation-helper.cc +++ b/client/installation-helper.cc @@ -39,13 +39,15 @@ #include "utils/GetOpts.h" +#include "misc.h" + using namespace snapper; using namespace std; void -step1(const string& device, const string& description) +step1(const string& device, const string& description, const map& userdata) { // step runs in inst-sys @@ -94,6 +96,7 @@ step1(const string& device, const string& description) SCD scd; scd.read_only = false; scd.description = description; + scd.userdata = userdata; Snapshots::iterator snapshot = snapper.createSingleSnapshot(scd); @@ -222,6 +225,7 @@ main(int argc, char** argv) { "root-prefix", required_argument, 0, 0 }, { "default-subvolume-name", required_argument, 0, 0 }, { "description", required_argument, 0, 0 }, + { "userdata", required_argument, 0, 'u' }, { 0, 0, 0, 0 } }; @@ -230,6 +234,7 @@ main(int argc, char** argv) string root_prefix = "/"; string default_subvolume_name; string description; + map userdata; GetOpts getopts; @@ -254,8 +259,11 @@ main(int argc, char** argv) if ((opt = opts.find("description")) != opts.end()) description = opt->second; + if ((opt = opts.find("userdata")) != opts.end()) + userdata = read_userdata(opt->second); + if (step == "1") - step1(device, description); + step1(device, description, userdata); else if (step == "2") step2(device, root_prefix, default_subvolume_name); else if (step == "3") diff --git a/client/systemd-helper.cc b/client/systemd-helper.cc index e7830dc3..db0a6687 100644 --- a/client/systemd-helper.cc +++ b/client/systemd-helper.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Novell, Inc. + * Copyright (c) [2014-2015] Novell, Inc. * * All Rights Reserved. * @@ -31,20 +31,19 @@ #include "commands.h" #include "cleanup.h" #include "errors.h" +#include "misc.h" using namespace snapper; using namespace std; -GetOpts getopts; - bool do_timeline = false; bool do_cleanup = false; void -timeline(DBus::Connection* conn) +timeline(DBus::Connection* conn, const map& userdata) { list config_infos = command_list_xconfigs(*conn); for (const XConfigInfo& config_info : config_infos) @@ -53,7 +52,7 @@ timeline(DBus::Connection* conn) if (pos1 != config_info.raw.end() && pos1->second == "yes") { command_create_single_xsnapshot(*conn, config_info.config_name, "timeline", - "timeline", map()); + "timeline", userdata); } } } @@ -94,25 +93,35 @@ main(int argc, char** argv) const struct option options[] = { { "timeline", no_argument, 0, 0 }, { "cleanup", no_argument, 0, 0 }, + { "userdata", required_argument, 0, 'u' }, { 0, 0, 0, 0 } }; + map userdata; + + GetOpts getopts; + getopts.init(argc, argv); GetOpts::parsed_opts opts = getopts.parse(options); + GetOpts::parsed_opts::const_iterator opt; + if (opts.find("timeline") != opts.end()) do_timeline = true; if (opts.find("cleanup") != opts.end()) do_cleanup = true; + if ((opt = opts.find("userdata")) != opts.end()) + userdata = read_userdata(opt->second); + try { DBus::Connection conn(DBUS_BUS_SYSTEM); if (do_timeline) - timeline(&conn); + timeline(&conn, userdata); if (do_cleanup) cleanup(&conn); diff --git a/package/snapper.changes b/package/snapper.changes index ef5531b9..ff7da09d 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Tue Mar 03 10:22:28 CET 2015 - aschnell@suse.de + +- allow to set userdata for snapshots created by helper programs + ------------------------------------------------------------------- Mon Mar 02 17:30:06 CET 2015 - aschnell@suse.de