]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- work on dbus interface
authorArvin Schnell <aschnell@suse.de>
Thu, 3 May 2012 09:20:19 +0000 (11:20 +0200)
committerArvin Schnell <aschnell@suse.de>
Thu, 3 May 2012 09:20:19 +0000 (11:20 +0200)
client/commands.cc
client/commands.h
client/snapper.cc
client/types.cc
client/types.h
doc/dbus-protocol.txt
server/snapperd.cc

index d21d89c7a631b0c94dfeb29d6ad5ec49930f55a8..a529a23cc82013e34a70cbcd0cbfecb9b630d3aa 100644 (file)
 #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<XConfigInfo> ret;
+
+    DBus::Hihi hihi(reply);
+    hihi >> ret;
+
+    for (list<XConfigInfo>::const_iterator it = ret.begin(); it != ret.end(); ++it)
+    {
+       if (it->config_name == config_name)
+           return *it;
+    }
+
+    throw;
+}
+
+
 list<XConfigInfo>
 command_list_xconfigs(DBus::Connection& conn)
 {
@@ -202,12 +224,12 @@ command_get_xfiles(DBus::Connection& conn, const string& config_name, unsigned i
 
 vector<string>
 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);
 
index aefbb9f351ab27de139c05a4726a8aa2dcb69247..0f6a7b1e422d0c805d9726b70e2b243cef786938 100644 (file)
@@ -37,6 +37,9 @@ using std::map;
 #include "types.h"
 
 
+XConfigInfo
+command_get_xconfig(DBus::Connection& conn, const string& config_name);
+
 list<XConfigInfo>
 command_list_xconfigs(DBus::Connection& conn);
 
@@ -78,7 +81,7 @@ command_get_xfiles(DBus::Connection& conn, const string& config_name, unsigned i
 
 vector<string>
 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,
index b382ee0979e7cfb7f63cae925ece5fe08a90d81d..6a45678386d0c2afa994fc2417b5a8b8338eabbe 100644 (file)
@@ -150,6 +150,26 @@ show_userdata(const map<string, string>& 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<XFile>::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<XFile> files = command_get_xfiles(conn, config_name, nums.first, nums.second);
-
     if (getopts.numArgs() == 0)
     {
+       list<XFile> files = command_get_xfiles(conn, config_name, nums.first, nums.second);
+
        for (list<XFile>::const_iterator it1 = files.begin(); it1 != files.end(); ++it1)
        {
            vector<string> lines = command_get_xdiff(conn, config_name, nums.first, nums.second,
-                                                    it1->filename, "--unified --new-file");
+                                                    it1->name, "--unified --new-file");
            for (vector<string>::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<string> lines = tmp->getDiff("--unified --new-file");
+           vector<string> lines = command_get_xdiff(conn, config_name, nums.first, nums.second,
+                                                    name, "--unified --new-file");
            for (vector<string>::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<XUndo> 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<XUndo> 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();
index 2924b841935be50addd2e52896411d19a6563e6e..40dd25e2c9940427ed821beb7104e8c493c6d762 100644 (file)
@@ -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;
     }
index fb77442dbcac913c3dded88e8f982926eec97cf0..a6cec327332ff69dc757f6801f7d57a0223adc1d 100644 (file)
@@ -86,14 +86,14 @@ struct XSnapshots
 struct XFile
 {
     string status;
-    string filename;
+    string name;
     bool undo;
 };
 
 
 struct XUndo
 {
-    string filename;
+    string name;
     bool undo;
 };
 
index a49da75c86810a9c67db908d82e6558dfb2db2a4..dfad02a44180f3fb7d434456146085425210fe29 100644 (file)
@@ -52,3 +52,6 @@ method UndoChange config-name number1 number2
 
 method Cleanup config-name algorithm
 
+
+Filenames do not include the subvolume.
+
index 218778e8e3a3210243b370f82a6e937fa3af931a..65ad9b56d5265508f93c26b15f1ec0cc0cf0b1c5 100644 (file)
@@ -743,8 +743,10 @@ reply_to_command_set_undo(DBus::Connection& conn, DBus::Message& msg)
     for (list<Undo>::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);
+    }
 }