From: Arvin Schnell Date: Thu, 9 Aug 2012 13:47:22 +0000 (+0200) Subject: - work on dbus interface X-Git-Tag: v0.1.3~156 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=28d593af08bdb963e648e1b846ec336f2bbc1654;p=thirdparty%2Fsnapper.git - work on dbus interface --- diff --git a/client/snapper.cc b/client/snapper.cc index 992c3b7d..9f73f978 100644 --- a/client/snapper.cc +++ b/client/snapper.cc @@ -71,9 +71,9 @@ read_num(const string& str) pair -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 nums; + while (getopts.hasArgs()) { - unsigned int num = read_num(getopts.popArg()); + string arg = getopts.popArg(); - list 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 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); } diff --git a/client/types.cc b/client/types.cc index 02025850..fe785aff 100644 --- a/client/types.cc +++ b/client/types.cc @@ -25,6 +25,19 @@ #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 { diff --git a/client/types.h b/client/types.h index da3f7ad1..c265055a 100644 --- a/client/types.h +++ b/client/types.h @@ -77,9 +77,10 @@ struct XSnapshots typedef list::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;