Skip to content

Commit

Permalink
Merge pull request #12 from jsuchome/Code-11-SP3
Browse files Browse the repository at this point in the history
backport of fate #313041 to SP3
  • Loading branch information
jsuchome committed Sep 7, 2012
2 parents dc45ab7 + f99cfd6 commit aaaf684
Show file tree
Hide file tree
Showing 12 changed files with 562 additions and 88 deletions.
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Makefile
Makefile.am
Makefile.in
aclocal.m4
autom4te.cache
config.cache
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
configure.in
depcomp
install-sh
*.pot
libtool
ltconfig
ltmain.sh
missing
mkinstalldirs
stamp-h*
Makefile.am.common
*.ami
*.bz2
*.spec
.dep
tmp.*
*.log
*.ybc
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.17.13
2.17.14
3 changes: 3 additions & 0 deletions agent-snapper/doc/autodocs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.html
*.png
*.css
133 changes: 124 additions & 9 deletions agent-snapper/src/SnapperAgent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,40 @@ YCPList SnapperAgent::getListValue (const YCPMap &map, const YCPString &key)
return YCPList();
}

/**
* Search the map for value of given key;
* key is string and value is YCPMap
*/
YCPMap SnapperAgent::getMapValue (const YCPMap &map, const YCPString &key)
{
YCPValue val = map->value(key);
if (!val.isNull() && val->isMap())
return val->asMap();
else
return YCPMap();
}

YCPMap map2ycpmap (const map<string, string>& userdata)
{
YCPMap m;
for (map<string, string>::const_iterator it = userdata.begin(); it != userdata.end(); ++it)
{
m->add (YCPString (it->first), YCPString (it->second));
}
return m;
}

map<string, string> ycpmap2stringmap (const YCPMap &ycp_map)
{
map<string, string> m;

for (YCPMapIterator i = ycp_map->begin(); i != ycp_map->end(); i++) {
string key = i.key()->asString()->value();
m[key] = i.value()->asString()->value();
}
return m;
}


/**
* Constructor
Expand All @@ -68,6 +102,7 @@ SnapperAgent::SnapperAgent() : SCRAgent()
sh = NULL;
snapper_initialized = false;
snapper_error = "";

}

/**
Expand All @@ -77,7 +112,8 @@ SnapperAgent::~SnapperAgent()
{
if (sh)
{
deleteSnapper(sh);
delete sh;
sh = 0;
}
}

Expand Down Expand Up @@ -186,17 +222,17 @@ YCPValue SnapperAgent::Read(const YCPPath &path, const YCPValue& arg, const YCPV

s->add (YCPString ("num"), YCPInteger (it->getNum()));
s->add (YCPString ("date"), YCPInteger (it->getDate()));
s->add (YCPString ("description"), YCPString (it->getDescription()));

if (it->getType() == SINGLE || it->getType() == PRE)
if (it->getType() == PRE)
{
s->add (YCPString ("description"), YCPString (it->getDescription()));
if (it->getType() == PRE)
s->add (YCPString ("post_num"), YCPInteger (snapshots.findPost (it)->getNum ()));
s->add (YCPString ("post_num"), YCPInteger (snapshots.findPost (it)->getNum ()));
}
else if (it->getType() == POST)
{
s->add (YCPString ("pre_num"), YCPInteger (it->getPreNum()));
}
s->add (YCPString ("userdata"), YCPMap (map2ycpmap (it->getUserdata())));

y2debug ("snapshot %s", s.toString().c_str());
retlist->add (s);
Expand Down Expand Up @@ -322,11 +358,13 @@ YCPValue SnapperAgent::Execute(const YCPPath &path, const YCPValue& arg,
if (sh)
{
y2milestone ("deleting existing snapper object");
deleteSnapper(sh);
delete sh;
sh = 0;
}
string config_name = getValue (argmap, YCPString ("config"), "root");
try {
sh = createSnapper (config_name);
try
{
sh = new Snapper(config_name);
}
catch (const ConfigNotFoundException& e)
{
Expand Down Expand Up @@ -354,10 +392,87 @@ YCPValue SnapperAgent::Execute(const YCPPath &path, const YCPValue& arg,

if (path->length() == 1) {

if (PC(0) == "create") {

string description = getValue (argmap, YCPString ("description"), "");
string cleanup = getValue (argmap, YCPString ("cleanup"), "");
string type = getValue (argmap, YCPString ("type"), "single");
YCPMap userdata = getMapValue (argmap, YCPString ("userdata"));

const Snapshots& snapshots = sh->getSnapshots();
Snapshots::iterator snap;

if (type == "single") {
snap = sh->createSingleSnapshot(description);
}
else if (type == "pre") {
snap = sh->createPreSnapshot(description);
}
else if (type == "post") {
// check if pre was given!
int pre = getIntValue (argmap, YCPString ("pre"), -1);
if (pre == -1)
{
snapper_error = "pre_not_given";
return YCPBoolean (false);
}
else
{
Snapshots::const_iterator snap1 = snapshots.find (pre);
if (snap1 == snapshots.end())
{
snapper_error = "pre_not_found";
return YCPBoolean (false);
}
else
{
snap = sh->createPostSnapshot(description, snap1);
}
}
}
else {
snapper_error = "wrong_snapshot_type";
return YCPBoolean (false);
}

snap->setCleanup (cleanup);
snap->setUserdata (ycpmap2stringmap (userdata));
snap->flushInfo();
return ret;
}
else if (PC(0) == "modify") {

int num = getIntValue (argmap, YCPString ("num"), 0);

Snapshots& snapshots = sh->getSnapshots();
Snapshots::iterator snap = snapshots.find(num);
if (snap == snapshots.end())
{
y2error ("snapshot '%d' not found", num);
snapper_error = "snapshot_not_found";
return YCPBoolean (false);
}

if (!argmap->value(YCPString ("description")).isNull())
// if (argmap->hasKey(YCPString ("description")))
{
snap->setDescription (getValue (argmap, YCPString ("description"), ""));
}
if (!argmap->value(YCPString ("cleanup")).isNull())
{
snap->setCleanup (getValue (argmap, YCPString ("cleanup"), ""));
}
if (!argmap->value(YCPString ("userdata")).isNull())
{
snap->setUserdata (ycpmap2stringmap (getMapValue (argmap, YCPString ("userdata"))));
}
snap->flushInfo();
return ret;
}
/**
* Rollback the list of given files from snapshot num1 to num2 (system by default)
*/
if (PC(0) == "rollback") {
else if (PC(0) == "rollback") {

unsigned int num1 = getIntValue (argmap, YCPString ("from"), 0);
unsigned int num2 = getIntValue (argmap, YCPString ("to"), 0);
Expand Down
7 changes: 6 additions & 1 deletion agent-snapper/src/SnapperAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <scr/SCRAgent.h>

#include <snapper/Snapper.h>
#include <snapper/Factory.h>
#include <snapper/Snapshot.h>
#include <snapper/Comparison.h>
#include <snapper/File.h>
Expand Down Expand Up @@ -53,6 +52,12 @@ class SnapperAgent : public SCRAgent
*/
YCPList getListValue (const YCPMap &map, const YCPString &key);

/**
* Search the map for value of given key;
* key is string and value is YCPMap
*/
YCPMap getMapValue (const YCPMap &map, const YCPString &key);

public:
/**
* Default constructor.
Expand Down
2 changes: 0 additions & 2 deletions package/_cvsignore

This file was deleted.

7 changes: 7 additions & 0 deletions package/yast2-snapper.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Sep 5 12:50:24 CEST 2012 - jsuchome@suse.cz

- added support for creating and modifying snapshots (fate#313041)
- show and enable editing of userdata
- 2.17.14

-------------------------------------------------------------------
Mon Jan 16 10:45:11 CET 2012 - jsuchome@suse.cz

Expand Down
57 changes: 56 additions & 1 deletion src/Snapper.ycp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ------------------------------------------------------------------------------
* Copyright (c) 2006 Novell, Inc. All Rights Reserved.
* Copyright (c) 2006-2012 Novell, Inc. All Rights Reserved.
*
*
* This program is free software; you can redistribute it and/or modify it under
Expand Down Expand Up @@ -245,6 +245,61 @@ global boolean InitializeSnapper (string config) {

}

/**
* Modify existing snapshot
* Return true on success
*/
global boolean ModifySnapshot (map args) {

boolean success = (boolean) SCR::Execute (.snapper.modify, args);
if (!success)
{
map err_map = LastSnapperErrorMap ();
string type = err_map["type"]:"";
string details = _("Reason not known.");

y2warning ("modification failed with '%1'", err_map);
// error popup
Report::Error (sformat (_("Failed to modify snapshot:
%1"), details));
}
return success;
}

/**
* Create new snapshot
* Return true on success
*/
global boolean CreateSnapshot (map args) {

boolean success = (boolean) SCR::Execute (.snapper.create, args);
if (!success)
{
map err_map = LastSnapperErrorMap ();
string type = err_map["type"]:"";
string details = _("Reason not known.");

if (type == "wrong_snapshot_type")
{
details = _("Wrong snapshot type given.");
}
else if (type == "pre_not_given")
{
details = _("'Pre' snapshot was not given.");
}
else if (type == "pre_not_found")
{
details = _("Given 'Pre' snapshot was not found.");
}

y2warning ("creating failed with '%1'", err_map);
// error popup
Report::Error (sformat (_("Failed to create new snapshot:
%1"), details));
}
return success;
}

/**
* Read all snapper settings
* @return true on success
Expand Down
Loading

0 comments on commit aaaf684

Please sign in to comment.