From: Arvin Schnell Date: Thu, 3 May 2012 09:20:19 +0000 (+0200) Subject: - work on dbus interface X-Git-Tag: v0.1.3~230 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bcd912a27ed2e701abe15d1f659937ec1369af63;p=thirdparty%2Fsnapper.git - work on dbus interface --- diff --git a/client/commands.cc b/client/commands.cc index d21d89c7..a529a23c 100644 --- a/client/commands.cc +++ b/client/commands.cc @@ -33,6 +33,28 @@ #define INTERFACE "org.opensuse.snapper" +XConfigInfo +command_get_xconfig(DBus::Connection& conn, const string& config_name) +{ + DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "ListConfigs"); + + DBus::Message reply = conn.send_and_reply_and_block(call); + + list ret; + + DBus::Hihi hihi(reply); + hihi >> ret; + + for (list::const_iterator it = ret.begin(); it != ret.end(); ++it) + { + if (it->config_name == config_name) + return *it; + } + + throw; +} + + list command_list_xconfigs(DBus::Connection& conn) { @@ -202,12 +224,12 @@ command_get_xfiles(DBus::Connection& conn, const string& config_name, unsigned i vector command_get_xdiff(DBus::Connection& conn, const string& config_name, unsigned int number1, - unsigned int number2, const string& filename, const string& options) + unsigned int number2, const string& name, const string& options) { DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "GetDiff"); DBus::Hoho hoho(call); - hoho << config_name << number1 << number2 << filename << options; + hoho << config_name << number1 << number2 << name << options; DBus::Message reply = conn.send_and_reply_and_block(call); diff --git a/client/commands.h b/client/commands.h index aefbb9f3..0f6a7b1e 100644 --- a/client/commands.h +++ b/client/commands.h @@ -37,6 +37,9 @@ using std::map; #include "types.h" +XConfigInfo +command_get_xconfig(DBus::Connection& conn, const string& config_name); + list command_list_xconfigs(DBus::Connection& conn); @@ -78,7 +81,7 @@ command_get_xfiles(DBus::Connection& conn, const string& config_name, unsigned i vector command_get_xdiff(DBus::Connection& conn, const string& config_name, unsigned int number1, - unsigned int number2, const string& filename, const string& options); + unsigned int number2, const string& name, const string& options); void command_set_xundo(DBus::Connection& conn, const string& config_name, unsigned int number1, diff --git a/client/snapper.cc b/client/snapper.cc index b382ee09..6a456783 100644 --- a/client/snapper.cc +++ b/client/snapper.cc @@ -150,6 +150,26 @@ show_userdata(const map& userdata) } +string +add_subvolume(const string& subvolume, const string& name) +{ + return subvolume == "/" ? name : subvolume + name; +} + + +string +remove_subvolume(const string& subvolume, const string& name) +{ + if (!boost::starts_with(name, subvolume)) + throw; + + if (subvolume == "/") + return name; + else + return string(name, subvolume.size()); +} + + void help_list_configs() { @@ -800,8 +820,10 @@ command_status(DBus::Connection& conn) } } + XConfigInfo ci = command_get_xconfig(conn, config_name); + for (list::const_iterator it = files.begin(); it != files.end(); ++it) - fprintf(file, "%s %s\n", it->status.c_str(), it->filename.c_str()); // TODO abs filename + fprintf(file, "%s %s\n", it->status.c_str(), add_subvolume(ci.subvolume, it->name).c_str()); if (file != stdout) fclose(file); @@ -828,33 +850,30 @@ command_diff(DBus::Connection& conn) command_create_xcomparison(conn, config_name, nums.first, nums.second); - list files = command_get_xfiles(conn, config_name, nums.first, nums.second); - if (getopts.numArgs() == 0) { + list files = command_get_xfiles(conn, config_name, nums.first, nums.second); + for (list::const_iterator it1 = files.begin(); it1 != files.end(); ++it1) { vector lines = command_get_xdiff(conn, config_name, nums.first, nums.second, - it1->filename, "--unified --new-file"); + it1->name, "--unified --new-file"); for (vector::const_iterator it2 = lines.begin(); it2 != lines.end(); ++it2) cout << it2->c_str() << endl; } } else { + XConfigInfo ci = command_get_xconfig(conn, config_name); + while (getopts.numArgs() > 0) { - string name = getopts.popArg(); + string name = remove_subvolume(ci.subvolume, getopts.popArg()); - /* - Files::const_iterator tmp = files.findAbsolutePath(name); - if (tmp == files.end()) - continue; - - vector lines = tmp->getDiff("--unified --new-file"); + vector lines = command_get_xdiff(conn, config_name, nums.first, nums.second, + name, "--unified --new-file"); for (vector::const_iterator it2 = lines.begin(); it2 != lines.end(); ++it2) cout << it2->c_str() << endl; - */ } } } @@ -915,6 +934,10 @@ command_undo(DBus::Connection& conn) if (file) { + XConfigInfo ci = command_get_xconfig(conn, config_name); + + list undos; + AsciiFileReader asciifile(file); string line; @@ -935,17 +958,13 @@ command_undo(DBus::Connection& conn) name.erase(0, pos + 1); } - /* - Files::iterator it = files.findAbsolutePath(name); - if (it == files.end()) - { - cerr << sformat(_("File '%s' not found."), name.c_str()) << endl; - exit(EXIT_FAILURE); - } - - it->setUndo(true); - */ + XUndo undo; + undo.undo = true; + undo.name = remove_subvolume(ci.subvolume, name); + undos.push_back(undo); } + + command_set_xundo(conn, config_name, nums.first, nums.second, undos); } else { @@ -955,18 +974,19 @@ command_undo(DBus::Connection& conn) } else { - while (getopts.numArgs() > 0) - { - string name = getopts.popArg(); + XConfigInfo ci = command_get_xconfig(conn, config_name); - /* - Files::iterator tmp = files.findAbsolutePath(name); - if (tmp == files.end()) - continue; + list undos; - tmp->setUndo(true); - */ + while (getopts.numArgs() > 0) + { + XUndo undo; + undo.undo = true; + undo.name = remove_subvolume(ci.subvolume, getopts.popArg()); + undos.push_back(undo); } + + command_set_xundo(conn, config_name, nums.first, nums.second, undos); } } @@ -974,12 +994,11 @@ command_undo(DBus::Connection& conn) if (s.empty()) { - cout << "nothing to do" << endl; + cout << _("nothing to do") << endl; return; } - cout << "create:" << s.numCreate << " modify:" << s.numModify << " delete:" << s.numDelete - << endl; + cout << sformat(_("create:%d modify:%d delete:%d"), s.numCreate, s.numModify, s.numDelete) << endl; /* comparison.doUndo(); diff --git a/client/types.cc b/client/types.cc index 2924b841..40dd25e2 100644 --- a/client/types.cc +++ b/client/types.cc @@ -89,7 +89,7 @@ namespace DBus operator>>(Hihi& hihi, XFile& data) { hihi.open_recurse(); - hihi >> data.filename >> data.status >> data.undo; + hihi >> data.name >> data.status >> data.undo; hihi.close_recurse(); return hihi; } @@ -107,7 +107,7 @@ namespace DBus operator<<(Hoho& hoho, const XUndo& data) { hoho.open_struct(); - hoho << data.filename << data.undo; + hoho << data.name << data.undo; hoho.close_struct(); return hoho; } diff --git a/client/types.h b/client/types.h index fb77442d..a6cec327 100644 --- a/client/types.h +++ b/client/types.h @@ -86,14 +86,14 @@ struct XSnapshots struct XFile { string status; - string filename; + string name; bool undo; }; struct XUndo { - string filename; + string name; bool undo; }; diff --git a/doc/dbus-protocol.txt b/doc/dbus-protocol.txt index a49da75c..dfad02a4 100644 --- a/doc/dbus-protocol.txt +++ b/doc/dbus-protocol.txt @@ -52,3 +52,6 @@ method UndoChange config-name number1 number2 method Cleanup config-name algorithm + +Filenames do not include the subvolume. + diff --git a/server/snapperd.cc b/server/snapperd.cc index 218778e8..65ad9b56 100644 --- a/server/snapperd.cc +++ b/server/snapperd.cc @@ -743,8 +743,10 @@ reply_to_command_set_undo(DBus::Connection& conn, DBus::Message& msg) for (list::const_iterator it2 = undos.begin(); it2 != undos.end(); ++it2) { Files::iterator it3 = files.find(it2->filename); - if (it3 != files.end()) - it3->setUndo(it2->undo); + if (it3 == files.end()) + throw; + + it3->setUndo(it2->undo); } DBus::MessageMethodReturn reply(msg); @@ -989,6 +991,11 @@ dispatch(DBus::Connection& conn, DBus::Message& msg) DBus::MessageError reply(msg, "error.illegal_snapshot", DBUS_ERROR_FAILED); conn.send(reply); } + catch (...) + { + DBus::MessageError reply(msg, "error.something", DBUS_ERROR_FAILED); + conn.send(reply); + } }