]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- work on dbus interface
authorArvin Schnell <aschnell@suse.de>
Thu, 9 Aug 2012 13:47:22 +0000 (15:47 +0200)
committerArvin Schnell <aschnell@suse.de>
Thu, 9 Aug 2012 13:47:22 +0000 (15:47 +0200)
client/snapper.cc
client/types.cc
client/types.h

index 992c3b7dc204b4b935603ab6b9270e51507682cb..9f73f978feb57dad5fdcfe2b1a57184367d572f2 100644 (file)
@@ -71,9 +71,9 @@ read_num(const string& str)
 
 
 pair<unsigned int, unsigned int>
-read_nums(const string& str)
+read_nums(const string& str, const string& delim = "..")
 {
-    string::size_type pos = str.find("..");
+    string::size_type pos = str.find(delim);
     if (pos == string::npos)
     {
        cerr << _("Invalid snapshots.") << endl;
@@ -81,7 +81,7 @@ read_nums(const string& str)
     }
 
     unsigned int num1 = read_num(str.substr(0, pos));
-    unsigned int num2 = read_num(str.substr(pos + 2));
+    unsigned int num2 = read_num(str.substr(pos + delim.size()));
 
     if (num1 == num2)
     {
@@ -641,14 +641,38 @@ command_delete(DBus::Connection& conn)
        exit(EXIT_FAILURE);
     }
 
+    XSnapshots snapshots = command_list_xsnapshots(conn, config_name);
+
+    list<unsigned int> nums;
+
     while (getopts.hasArgs())
     {
-       unsigned int num = read_num(getopts.popArg());
+       string arg = getopts.popArg();
 
-       list<unsigned int> nums;
-       nums.push_back(num);
-       command_delete_xsnapshots(conn, config_name, nums);
+       if (arg.find_first_of("-") == string::npos)
+       {
+           unsigned int i = read_num(arg);
+           nums.push_back(i);
+       }
+       else
+       {
+           pair<unsigned int, unsigned int> r(read_nums(arg, "-"));
+
+           if (r.first > r.second)
+               swap(r.first, r.second);
+
+           for (unsigned int i = r.first; i <= r.second; ++i)
+           {
+               if (snapshots.find(i) != snapshots.end() &&
+                   find(nums.begin(), nums.end(), i) == nums.end())
+               {
+                   nums.push_back(i);
+               }
+           }
+       }
     }
+
+    command_delete_xsnapshots(conn, config_name, nums);
 }
 
 
index 02025850b12ff7628430d72350097a5290e5f4f5..fe785affc2ba1458b3824e7350f384ff626d1a11 100644 (file)
 #include "types.h"
 
 
+XSnapshots::const_iterator
+XSnapshots::find(unsigned int num) const
+{
+    for (const_iterator it = begin(); it != end(); ++it)
+    {
+       if (it->getNum() == num)
+           return it;
+    }
+
+    return end();
+}
+
+
 XSnapshots::const_iterator
 XSnapshots::findPre(const_iterator post) const
 {
index da3f7ad17957ae9b6ee52319959871cd8843e9f8..c265055afe1e8b186409d8e6836d37417df4ce3b 100644 (file)
@@ -77,9 +77,10 @@ struct XSnapshots
     typedef list<XSnapshot>::const_iterator const_iterator;
 
     const_iterator begin() const { return entries.begin(); }
-
     const_iterator end() const { return entries.end(); }
 
+    const_iterator find(unsigned int num) const;
+
     const_iterator findPre(const_iterator post) const;
     const_iterator findPost(const_iterator pre) const;