]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
allow to list config for target root (FATE#317900)
authorJosef Reidinger <jreidinger@suse.cz>
Mon, 25 May 2015 11:25:37 +0000 (13:25 +0200)
committerJosef Reidinger <jreidinger@suse.cz>
Mon, 25 May 2015 11:25:37 +0000 (13:25 +0200)
.gitignore
client/snapper.cc
snapper/Snapper.cc

index 28ab8800f62fa3ecbfc074240bbebb298abbea11..c0acf20bcd6345308cd71a80f07c69043a01ae09 100644 (file)
@@ -14,3 +14,4 @@ missing
 stamp-h1
 py-compile
 test-driver
+/compile
index f7bd59a4b65e8eaf88828e2bf3783866e77c8a82..6ae90ccb627a6d25948094c86764fa89687c30ec 100644 (file)
@@ -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 <path>\tRead configuration from target root (works only without dbus).") << endl
+
         << endl;
 }
 
 
 list<pair<string, string>>
-enum_configs(DBus::Connection* conn)
+enum_configs(DBus::Connection* conn, const string& target_root = "/")
 {
     list<pair<string, string>> configs;
 
     if (no_dbus)
     {
-       list<ConfigInfo> config_infos = Snapper::getConfigs("/");
+       list<ConfigInfo> config_infos = Snapper::getConfigs(target_root);
        for (list<ConfigInfo>::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<pair<string, string> > configs = enum_configs(conn);
+    list<pair<string, string> > configs = enum_configs(conn, target_root);
 
     for (list<pair<string,string> >::iterator it = configs.begin(); it != configs.end(); ++it)
     {
index 955155d4f5a8e13af2a6332d501887bcd1520415..78f0dbc1cf207d3ad76e2d8a815ef70ac846d4df 100644 (file)
@@ -251,7 +251,7 @@ namespace snapper
 
        try
        {
-           SysconfigFile sysconfig(SYSCONFIGFILE);
+           SysconfigFile sysconfig(root_prefix + SYSCONFIGFILE);
            vector<string> config_names;
            sysconfig.getValue("SNAPPER_CONFIGS", config_names);