From: Josef Reidinger Date: Mon, 25 May 2015 11:25:37 +0000 (+0200) Subject: allow to list config for target root (FATE#317900) X-Git-Tag: v0.2.8~9^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6db5971374c220103211758fce8bbad9d21df954;p=thirdparty%2Fsnapper.git allow to list config for target root (FATE#317900) --- diff --git a/.gitignore b/.gitignore index 28ab8800..c0acf20b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ missing stamp-h1 py-compile test-driver +/compile diff --git a/client/snapper.cc b/client/snapper.cc index f7bd59a4..6ae90ccb 100644 --- a/client/snapper.cc +++ b/client/snapper.cc @@ -201,18 +201,22 @@ help_list_configs() { cout << _(" List configs:") << endl << _("\tsnapper list-configs") << endl + << endl + << _(" Options for 'list-configs' command:") << endl + << _("\t--target-root, -r \tRead configuration from target root (works only without dbus).") << endl + << endl; } list> -enum_configs(DBus::Connection* conn) +enum_configs(DBus::Connection* conn, const string& target_root = "/") { list> configs; if (no_dbus) { - list config_infos = Snapper::getConfigs("/"); + list config_infos = Snapper::getConfigs(target_root); for (list::const_iterator it = config_infos.begin(); it != config_infos.end(); ++it) { configs.push_back(make_pair(it->getConfigName(), it->getSubvolume())); @@ -234,13 +238,25 @@ enum_configs(DBus::Connection* conn) void command_list_configs(DBus::Connection* conn, Snapper* snapper) { - getopts.parse("list-configs", GetOpts::no_options); + const struct option options[] = { + { "target-root", optional_argument, 0, 'r' }, + { 0, 0, 0, 0 } + }; + GetOpts::parsed_opts opts = getopts.parse("list-configs", options); + if (getopts.hasArgs()) { cerr << _("Command 'list-configs' does not take arguments.") << endl; exit(EXIT_FAILURE); } + string target_root = "/"; + + GetOpts::parsed_opts::const_iterator opt; + + if ((opt = opts.find("target-root")) != opts.end()) + target_root = opt->second; + Table table; TableHeader header; @@ -248,7 +264,7 @@ command_list_configs(DBus::Connection* conn, Snapper* snapper) header.add(_("Subvolume")); table.setHeader(header); - list > configs = enum_configs(conn); + list > configs = enum_configs(conn, target_root); for (list >::iterator it = configs.begin(); it != configs.end(); ++it) { diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 955155d4..78f0dbc1 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -251,7 +251,7 @@ namespace snapper try { - SysconfigFile sysconfig(SYSCONFIGFILE); + SysconfigFile sysconfig(root_prefix + SYSCONFIGFILE); vector config_names; sysconfig.getValue("SNAPPER_CONFIGS", config_names);