]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
client: Add option to list snapshots from all configs
authorDavid Sterba <dsterba@suse.cz>
Wed, 24 Sep 2014 22:53:31 +0000 (00:53 +0200)
committerDavid Sterba <dsterba@suse.cz>
Thu, 2 Oct 2014 23:09:13 +0000 (01:09 +0200)
$ snapper list -a

will print the same output as 'list' but each table is preceded with
config name and subvolume. This is convenient way to see all configured
snapshots in the system, compared to listing all configs and then typing
each command separately.

client/snapper.cc
doc/snapper.xml.in
package/snapper.changes

index 4ef5eb3f35da461482e4331b1b7608ee23f7ed42..9be54576480e3a4b09c68edc3fbee6ccf68f622f 100644 (file)
@@ -141,6 +141,32 @@ help_list_configs()
 }
 
 
+list<pair<string, string> >
+enum_configs(DBus::Connection* conn)
+{
+    list<pair<string, string> > configs;
+
+    if (no_dbus)
+    {
+       list<ConfigInfo> config_infos = Snapper::getConfigs();
+       for (list<ConfigInfo>::const_iterator it = config_infos.begin(); it != config_infos.end(); ++it)
+       {
+           configs.push_back(make_pair(it->getConfigName(), it->getSubvolume()));
+       }
+    }
+    else
+    {
+       list<XConfigInfo> config_infos = command_list_xconfigs(*conn);
+       for (list<XConfigInfo>::const_iterator it = config_infos.begin(); it != config_infos.end(); ++it)
+       {
+           configs.push_back(make_pair(it->config_name, it->subvolume));
+       }
+    }
+
+    return configs;
+}
+
+
 void
 command_list_configs(DBus::Connection* conn, Snapper* snapper)
 {
@@ -382,15 +408,20 @@ help_list()
         << endl
         << _("    Options for 'list' command:") << endl
         << _("\t--type, -t <type>\t\tType of snapshots to list.") << endl
+        << _("\t--all-configs, -a\t\tList snapshots from all accessible configs.") << endl
         << endl;
 }
 
+enum ListMode { LM_ALL, LM_SINGLE, LM_PRE_POST };
+
+void list_from_one_config(DBus::Connection* conn, Snapper* snapper, string config_name, ListMode list_mode);
 
 void
 command_list(DBus::Connection* conn, Snapper* snapper)
 {
     const struct option options[] = {
        { "type",               required_argument,      0,      't' },
+       { "all-configs",        no_argument,            0,      'a' },
        { 0, 0, 0, 0 }
     };
 
@@ -401,7 +432,6 @@ command_list(DBus::Connection* conn, Snapper* snapper)
        exit(EXIT_FAILURE);
     }
 
-    enum ListMode { LM_ALL, LM_SINGLE, LM_PRE_POST };
     ListMode list_mode = LM_ALL;
 
     GetOpts::parsed_opts::const_iterator opt;
@@ -421,6 +451,29 @@ command_list(DBus::Connection* conn, Snapper* snapper)
        }
     }
 
+    list<pair<string, string> > configs;
+    if ((opt = opts.find("all-configs")) != opts.end())
+    {
+       configs = enum_configs(conn);
+    }
+    else
+    {
+       configs.push_back(make_pair(config_name, ""));
+    }
+
+    for (list<pair<string,string> >::iterator it = configs.begin(); it != configs.end(); ++it)
+    {
+       if (it != configs.begin())
+           cout << endl;
+
+       if (configs.size() > 1)
+           cout << "Config: " << it->first << ", subvolume: " << it->second << endl;
+       list_from_one_config(conn, snapper, it->first, list_mode);
+    }
+}
+
+void list_from_one_config(DBus::Connection* conn, Snapper* snapper, string config_name, ListMode list_mode)
+{
     Table table;
 
     switch (list_mode)
index 45a09168854078bc4733586492948f1058fec898..eefd1d7bf610b1e300dd3f27922eafc1546e554a 100644 (file)
                all, single and pre-post.</para>
              </listitem>
            </varlistentry>
+           <varlistentry>
+             <term><option>-a, --all-configs</option></term>
+             <listitem>
+               <para>List snapshots from all configs accessible by the user.</para>
+             </listitem>
+           </varlistentry>
          </variablelist>
        </listitem>
       </varlistentry>
index c30e0bf0354a8f4b8833e4b3684b6cb75fe995b4..48e2476a69d63debf1fc3300488f742342a62386 100644 (file)
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+Fri Oct 3 01:05:01 CEST 2014 - dsterba@suse.cz
+
+- add option --all-configs to snapper client, list snapshots from
+  all accessible configs
+
 -------------------------------------------------------------------
 Mon Sep 29 11:55:37 CEST 2014 - aschnell@suse.de