Hello community,
here is the log from the commit of package snapper for openSUSE:Factory
checked in at Mon Sep 26 10:20:19 CEST 2011.
--------
--- snapper/snapper.changes 2011-09-16 14:03:08.000000000 +0200
+++ /mounts/work_src_done/STABLE/snapper/snapper.changes 2011-09-23 16:30:19.000000000 +0200
@@ -1,0 +2,10 @@
+Thu Sep 22 16:28:53 CEST 2011 - aschnell@suse.de
+
+- do not log output of diff command
+
+-------------------------------------------------------------------
+Tue Sep 20 11:05:47 CEST 2011 - aschnell@suse.de
+
+- improved error handling (bnc#718914)
+
+-------------------------------------------------------------------
calling whatdependson for head-i586
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ snapper-0.0.7.tar.bz2 ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.0.7/snapper/Exception.h new/snapper-0.0.7/snapper/Exception.h
--- old/snapper-0.0.7/snapper/Exception.h 2011-09-16 10:58:51.000000000 +0200
+++ new/snapper-0.0.7/snapper/Exception.h 2011-09-20 14:40:11.000000000 +0200
@@ -30,31 +30,45 @@
namespace snapper
{
- struct FileNotFoundException : public std::exception
+ struct SnapperException : public std::exception
+ {
+ explicit SnapperException() throw() {}
+ virtual const char* what() const throw() { return "generic snapper exception"; }
+ };
+
+
+ struct FileNotFoundException : public SnapperException
{
explicit FileNotFoundException() throw() {}
virtual const char* what() const throw() { return "file not found"; }
};
- struct IllegalSnapshotException : public std::exception
+ struct IllegalSnapshotException : public SnapperException
{
explicit IllegalSnapshotException() throw() {}
virtual const char* what() const throw() { return "illegal snapshot"; }
};
- struct LogicErrorException : public std::exception
+ struct LogicErrorException : public SnapperException
{
explicit LogicErrorException() throw() {}
virtual const char* what() const throw() { return "logic error"; }
};
- struct IOErrorException : public std::exception
+ struct IOErrorException : public SnapperException
{
explicit IOErrorException() throw() {}
virtual const char* what() const throw() { return "IO error"; }
};
+ struct ProgramNotInstalledException : public SnapperException
+ {
+ explicit ProgramNotInstalledException(const char* msg) throw() : msg(msg) {}
+ virtual const char* what() const throw() { return msg; }
+ const char* msg;
+ };
+
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.0.7/snapper/File.cc new/snapper-0.0.7/snapper/File.cc
--- old/snapper-0.0.7/snapper/File.cc 2011-08-26 14:51:54.000000000 +0200
+++ new/snapper-0.0.7/snapper/File.cc 2011-09-23 16:26:57.000000000 +0200
@@ -121,8 +121,10 @@
if (getSnapper()->getCompareCallback())
getSnapper()->getCompareCallback()->start();
- comparison->getSnapshot1()->mountFilesystemSnapshot();
- comparison->getSnapshot2()->mountFilesystemSnapshot();
+ if (!comparison->getSnapshot1()->isCurrent())
+ comparison->getSnapshot1()->mountFilesystemSnapshot();
+ if (!comparison->getSnapshot2()->isCurrent())
+ comparison->getSnapshot2()->mountFilesystemSnapshot();
#if 1
cmpdirs_cb_t cb = AppendHelper(comparison, entries);
@@ -182,18 +184,16 @@
File file(comparison, name, status);
entries.push_back(file);
}
-
- sort(entries.begin(), entries.end());
-
- y2mil("read " << entries.size() << " lines");
-
- return true;
}
catch (const FileNotFoundException& e)
{
return false;
}
+ sort(entries.begin(), entries.end());
+
+ y2mil("read " << entries.size() << " lines");
+
return true;
}
@@ -410,7 +410,7 @@
File::getDiff(const string& options) const
{
SystemCmd cmd(DIFFBIN " " + options + " " + quote(getAbsolutePath(LOC_PRE)) + " " +
- quote(getAbsolutePath(LOC_POST)));
+ quote(getAbsolutePath(LOC_POST)), false);
return cmd.stdout();
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.0.7/snapper/Filesystem.cc new/snapper-0.0.7/snapper/Filesystem.cc
--- old/snapper-0.0.7/snapper/Filesystem.cc 2011-08-04 11:12:57.000000000 +0200
+++ new/snapper-0.0.7/snapper/Filesystem.cc 2011-09-20 14:40:11.000000000 +0200
@@ -49,6 +49,16 @@
}
+ Btrfs::Btrfs(const string& subvolume)
+ : Filesystem(subvolume)
+ {
+ if (access(BTRFSBIN, X_OK) != 0)
+ {
+ throw ProgramNotInstalledException(BTRFSBIN " not installed");
+ }
+ }
+
+
void
Btrfs::addConfig() const
{
@@ -118,6 +128,21 @@
}
+ Ext4::Ext4(const string& subvolume)
+ : Filesystem(subvolume)
+ {
+ if (access(CHSNAPBIN, X_OK) != 0)
+ {
+ throw ProgramNotInstalledException(CHSNAPBIN " not installed");
+ }
+
+ if (access(CHATTRBIN, X_OK) != 0)
+ {
+ throw ProgramNotInstalledException(CHATTRBIN " not installed");
+ }
+ }
+
+
void
Ext4::addConfig() const
{
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.0.7/snapper/Filesystem.h new/snapper-0.0.7/snapper/Filesystem.h
--- old/snapper-0.0.7/snapper/Filesystem.h 2011-08-26 14:51:54.000000000 +0200
+++ new/snapper-0.0.7/snapper/Filesystem.h 2011-09-20 14:40:11.000000000 +0200
@@ -71,7 +71,7 @@
{
public:
- Btrfs(const string& subvolume) : Filesystem(subvolume) {}
+ Btrfs(const string& subvolume);
virtual string name() const { return "btrfs"; }
@@ -96,7 +96,7 @@
{
public:
- Ext4(const string& subvolume) : Filesystem(subvolume) {}
+ Ext4(const string& subvolume);
virtual string name() const { return "ext4"; }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.0.7/snapper/Snapper.cc new/snapper-0.0.7/snapper/Snapper.cc
--- old/snapper-0.0.7/snapper/Snapper.cc 2011-09-15 17:30:03.000000000 +0200
+++ new/snapper-0.0.7/snapper/Snapper.cc 2011-09-23 16:26:57.000000000 +0200
@@ -179,8 +179,10 @@
y2mil("num1:" << snapshot1->getNum() << " num2:" << snapshot2->getNum());
- snapshot1->mountFilesystemSnapshot();
- snapshot2->mountFilesystemSnapshot();
+ if (!snapshot1->isCurrent())
+ snapshot1->mountFilesystemSnapshot();
+ if (!snapshot2->isCurrent())
+ snapshot2->mountFilesystemSnapshot();
bool invert = snapshot1->getNum() > snapshot2->getNum();
@@ -553,7 +555,7 @@
y2mil("config_name:" << config_name << " subvolume:" << subvolume <<
" fstype:" << fstype << " template_name:" << template_name);
- if (config_name.empty() || config_name.find_first_of(" \t") != string::npos)
+ if (config_name.empty() || config_name.find_first_of(", \t") != string::npos)
{
throw AddConfigFailedException("illegal config name");
}
@@ -563,6 +565,15 @@
throw AddConfigFailedException("illegal subvolume");
}
+ list<ConfigInfo> configs = getConfigs();
+ for (list<ConfigInfo>::const_iterator it = configs.begin(); it != configs.end(); ++it)
+ {
+ if (it->subvolume == subvolume)
+ {
+ throw AddConfigFailedException("subvolume already covered");
+ }
+ }
+
if (access(string(CONFIGTEMPLATEDIR "/" + template_name).c_str(), R_OK) != 0)
{
throw AddConfigFailedException("cannot access template config");
@@ -577,6 +588,10 @@
{
throw AddConfigFailedException("invalid filesystem type");
}
+ catch (const ProgramNotInstalledException& e)
+ {
+ throw AddConfigFailedException(e.what());
+ }
try
{
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.0.7/snapper/Snapper.h new/snapper-0.0.7/snapper/Snapper.h
--- old/snapper-0.0.7/snapper/Snapper.h 2011-09-15 17:30:03.000000000 +0200
+++ new/snapper-0.0.7/snapper/Snapper.h 2011-09-20 14:40:11.000000000 +0200
@@ -75,32 +75,32 @@
};
- struct ConfigNotFoundException : public std::exception
+ struct ConfigNotFoundException : public SnapperException
{
explicit ConfigNotFoundException() throw() {}
virtual const char* what() const throw() { return "config not found"; }
};
- struct InvalidConfigException : public std::exception
+ struct InvalidConfigException : public SnapperException
{
explicit InvalidConfigException() throw() {}
virtual const char* what() const throw() { return "invalid config"; }
};
- struct InvalidUserdataException : public std::exception
+ struct InvalidUserdataException : public SnapperException
{
explicit InvalidUserdataException() throw() {}
virtual const char* what() const throw() { return "invalid userdata"; }
};
- struct ListConfigsFailedException : public std::exception
+ struct ListConfigsFailedException : public SnapperException
{
explicit ListConfigsFailedException(const char* msg) throw() : msg(msg) {}
virtual const char* what() const throw() { return msg; }
const char* msg;
};
- struct AddConfigFailedException : public std::exception
+ struct AddConfigFailedException : public SnapperException
{
explicit AddConfigFailedException(const char* msg) throw() : msg(msg) {}
virtual const char* what() const throw() { return msg; }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.0.7/snapper/Snapshot.cc new/snapper-0.0.7/snapper/Snapshot.cc
--- old/snapper-0.0.7/snapper/Snapshot.cc 2011-09-16 12:00:41.000000000 +0200
+++ new/snapper-0.0.7/snapper/Snapshot.cc 2011-09-23 16:26:57.000000000 +0200
@@ -125,7 +125,10 @@
for (map::const_iterator it = val.begin(); it != val.end(); ++it)
{
- if (it->first.empty())
+ if (it->first.empty() || it->first.find_first_of(",=") != string::npos)
+ throw InvalidUserdataException();
+
+ if (it->second.find_first_of(",=") != string::npos)
throw InvalidUserdataException();
}
@@ -160,8 +163,8 @@
continue;
}
- unsigned int date;
- if (!getChildValue(node, "date", tmp) || (date = scan_datetime(tmp, true)) == -1)
+ time_t date;
+ if (!getChildValue(node, "date", tmp) || (date = scan_datetime(tmp, true)) == (time_t)(-1))
{
y2err("date missing or invalid. not adding snapshot " << *it1);
continue;
@@ -337,21 +340,18 @@
}
- bool
+ void
Snapshot::flushInfo()
{
if (!info_modified)
- return true;
-
- if (!writeInfo())
- return false;
+ return;
+ writeInfo();
info_modified = false;
- return true;
}
- bool
+ void
Snapshot::writeInfo() const
{
XmlFile xml;
@@ -380,9 +380,19 @@
setChildValue(userdata_node, "value", it->second);
}
- xml.save(infoDir() + "/info.xml");
+ if (!xml.save(infoDir() + "/info.xml.tmp"))
+ {
+ y2err("saving info.xml failed infoDir: " << infoDir() << " errno: << " << errno <<
+ " (" << strerror(errno) << ")");
+ throw IOErrorException();
+ }
- return true;
+ if (rename(string(infoDir() + "/info.xml.tmp").c_str(), string(infoDir() + "/info.xml").c_str()) != 0)
+ {
+ y2err("rename info.xml failed infoDir: " << infoDir() << " errno: << " << errno <<
+ " (" << strerror(errno) << ")");
+ throw IOErrorException();
+ }
}
@@ -390,7 +400,7 @@
Snapshot::mountFilesystemSnapshot() const
{
if (isCurrent())
- return;
+ throw IllegalSnapshotException();
snapper->getFilesystem()->mountSnapshot(num);
}
@@ -400,7 +410,7 @@
Snapshot::umountFilesystemSnapshot() const
{
if (isCurrent())
- return;
+ throw IllegalSnapshotException();
snapper->getFilesystem()->umountSnapshot(num);
}
@@ -434,9 +444,7 @@
snapshot.description = description;
snapshot.info_modified = true;
- snapshot.createFilesystemSnapshot();
-
- return entries.insert(entries.end(), snapshot);
+ return createHelper(snapshot);
}
@@ -447,9 +455,7 @@
snapshot.description = description;
snapshot.info_modified = true;
- snapshot.createFilesystemSnapshot();
-
- return entries.insert(entries.end(), snapshot);
+ return createHelper(snapshot);
}
@@ -463,7 +469,33 @@
snapshot.pre_num = pre->getNum();
snapshot.info_modified = true;
- snapshot.createFilesystemSnapshot();
+ return createHelper(snapshot);
+ }
+
+
+ Snapshots::iterator
+ Snapshots::createHelper(Snapshot& snapshot)
+ {
+ try
+ {
+ snapshot.createFilesystemSnapshot();
+ }
+ catch (const CreateSnapshotFailedException& e)
+ {
+ rmdir(snapshot.infoDir().c_str());
+ throw;
+ }
+
+ try
+ {
+ snapshot.flushInfo();
+ }
+ catch (const IOErrorException& e)
+ {
+ snapshot.deleteFilesystemSnapshot();
+ rmdir(snapshot.infoDir().c_str());
+ throw;
+ }
return entries.insert(entries.end(), snapshot);
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.0.7/snapper/Snapshot.h new/snapper-0.0.7/snapper/Snapshot.h
--- old/snapper-0.0.7/snapper/Snapshot.h 2011-09-16 12:01:24.000000000 +0200
+++ new/snapper-0.0.7/snapper/Snapshot.h 2011-09-20 14:40:11.000000000 +0200
@@ -29,6 +29,8 @@
#include <list>
#include <map>
+#include "snapper/Exception.h"
+
namespace snapper
{
@@ -43,32 +45,32 @@
enum SnapshotType { SINGLE, PRE, POST };
- struct CreateSnapshotFailedException : public std::exception
+ struct CreateSnapshotFailedException : public SnapperException
{
explicit CreateSnapshotFailedException() throw() {}
virtual const char* what() const throw() { return "create snapshot failed"; }
};
- struct DeleteSnapshotFailedException : public std::exception
+ struct DeleteSnapshotFailedException : public SnapperException
{
explicit DeleteSnapshotFailedException() throw() {}
virtual const char* what() const throw() { return "delete snapshot failed"; }
};
- struct IsSnapshotMountedFailedException : public std::exception
+ struct IsSnapshotMountedFailedException : public SnapperException
{
explicit IsSnapshotMountedFailedException() throw() {}
virtual const char* what() const throw() { return "is snapshot mounted failed"; }
};
- struct MountSnapshotFailedException : public std::exception
+ struct MountSnapshotFailedException : public SnapperException
{
explicit MountSnapshotFailedException() throw() {}
virtual const char* what() const throw() { return "mount snapshot failed"; }
};
- struct UmountSnapshotFailedException : public std::exception
+ struct UmountSnapshotFailedException : public SnapperException
{
explicit UmountSnapshotFailedException() throw() {}
virtual const char* what() const throw() { return "umount snapshot failed"; }
@@ -103,7 +105,7 @@
void setUserdata(const map& userdata);
map getUserdata() const { return userdata; }
- bool flushInfo();
+ void flushInfo();
string infoDir() const;
string snapshotDir() const;
@@ -133,7 +135,7 @@
bool info_modified;
- bool writeInfo() const;
+ void writeInfo() const;
void createFilesystemSnapshot() const;
void deleteFilesystemSnapshot() const;
@@ -190,6 +192,8 @@
iterator createPreSnapshot(string description);
iterator createPostSnapshot(const_iterator pre);
+ iterator createHelper(Snapshot& snapshot);
+
void deleteSnapshot(iterator snapshot);
unsigned int nextNumber();
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.0.7/snapper/SystemCmd.cc new/snapper-0.0.7/snapper/SystemCmd.cc
--- old/snapper-0.0.7/snapper/SystemCmd.cc 2011-02-28 16:48:13.000000000 +0100
+++ new/snapper-0.0.7/snapper/SystemCmd.cc 2011-09-22 16:30:38.000000000 +0200
@@ -39,8 +39,8 @@
using namespace std;
-SystemCmd::SystemCmd( const string& Command_Cv )
- : Combine_b(false)
+ SystemCmd::SystemCmd(const string& Command_Cv, bool log_output)
+ : Combine_b(false), log_output(log_output)
{
y2mil("constructor SystemCmd:\"" << Command_Cv << "\"");
init();
@@ -48,8 +48,8 @@
}
-SystemCmd::SystemCmd()
- : Combine_b(false)
+ SystemCmd::SystemCmd(bool log_output)
+ : Combine_b(false), log_output(log_output)
{
y2mil("constructor SystemCmd");
init();
@@ -292,7 +292,7 @@
if( !testmode )
checkOutput();
y2mil("system() Returns:" << Ret_i);
- if( Ret_i!=0 )
+ if (Ret_i != 0 && log_output)
logOutput();
return Ret_i;
}
@@ -560,13 +560,16 @@
void
SystemCmd::addLine(const string& Text_Cv, vector<string>& Lines_Cr)
{
- if (Lines_Cr.size() < line_limit)
+ if (log_output)
{
- y2mil("Adding Line " << Lines_Cr.size() + 1 << " \"" << Text_Cv << "\"");
- }
- else
- {
- y2deb("Adding Line " << Lines_Cr.size() + 1 << " \"" << Text_Cv << "\"");
+ if (Lines_Cr.size() < line_limit)
+ {
+ y2mil("Adding Line " << Lines_Cr.size() + 1 << " \"" << Text_Cv << "\"");
+ }
+ else
+ {
+ y2deb("Adding Line " << Lines_Cr.size() + 1 << " \"" << Text_Cv << "\"");
+ }
}
Lines_Cr.push_back(Text_Cv);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.0.7/snapper/SystemCmd.h new/snapper-0.0.7/snapper/SystemCmd.h
--- old/snapper-0.0.7/snapper/SystemCmd.h 2011-02-28 16:48:13.000000000 +0100
+++ new/snapper-0.0.7/snapper/SystemCmd.h 2011-09-22 16:30:38.000000000 +0200
@@ -44,8 +44,8 @@
enum OutputStream { IDX_STDOUT, IDX_STDERR };
- SystemCmd(const string& Command_Cv);
- SystemCmd();
+ SystemCmd(const string& Command_Cv, bool log_output = true);
+ SystemCmd(bool log_output = true);
virtual ~SystemCmd();
@@ -100,6 +100,7 @@
std::vector SelLines_aC[2];
bool NewLineSeen_ab[2];
bool Combine_b;
+ bool log_output;
bool Background_b;
string lastCmd;
int Ret_i;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.0.7/snapper/XmlFile.h new/snapper-0.0.7/snapper/XmlFile.h
--- old/snapper-0.0.7/snapper/XmlFile.h 2011-02-28 16:48:13.000000000 +0100
+++ new/snapper-0.0.7/snapper/XmlFile.h 2011-09-20 14:40:11.000000000 +0200
@@ -48,7 +48,7 @@
~XmlFile();
bool save(const string& filename)
- { return xmlSaveFormatFile(filename.c_str(), doc, 1); }
+ { return xmlSaveFormatFile(filename.c_str(), doc, 1) != -1; }
void setRootElement(xmlNode* node)
{ xmlDocSetRootElement(doc, node); }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.0.7/tools/snapper.cc new/snapper-0.0.7/tools/snapper.cc
--- old/snapper-0.0.7/tools/snapper.cc 2011-09-15 18:22:18.000000000 +0200
+++ new/snapper-0.0.7/tools/snapper.cc 2011-09-23 16:26:57.000000000 +0200
@@ -22,6 +22,8 @@
#include
#include
+#include
+#include
#include <iostream>
#include
@@ -57,6 +59,112 @@
Snapper* sh = NULL;
+Snapshots::iterator
+read_num(const string& str)
+{
+ Snapshots& snapshots = sh->getSnapshots();
+
+ istringstream s(str);
+ unsigned int num = 0;
+ s >> num;
+
+ if (s.fail() || !s.eof())
+ {
+ cerr << sformat(_("Invalid snapshot '%s'."), str.c_str()) << endl;
+ exit(EXIT_FAILURE);
+ }
+
+ Snapshots::iterator snap = snapshots.find(num);
+ if (snap == snapshots.end())
+ {
+ cerr << sformat(_("Snapshot '%u' not found."), num) << endl;
+ exit(EXIT_FAILURE);
+ }
+
+ return snap;
+}
+
+
+pair
+read_nums(const string& str)
+{
+ string::size_type pos = str.find("..");
+ if (pos == string::npos)
+ {
+ cerr << _("Invalid snapshots.") << endl;
+ exit(EXIT_FAILURE);
+ }
+
+ Snapshots::iterator snap1 = read_num(str.substr(0, pos));
+ Snapshots::iterator snap2 = read_num(str.substr(pos + 2));
+
+ if (snap1 == snap2)
+ {
+ cerr << _("Identical snapshots.") << endl;
+ exit(EXIT_FAILURE);
+ }
+
+ return pair(snap1, snap2);
+}
+
+
+map
+read_userdata(const string& s, const map& old = map())
+{
+ map userdata = old;
+
+ list<string> tmp;
+ boost::split(tmp, s, boost::is_any_of(","), boost::token_compress_on);
+ if (tmp.empty())
+ {
+ cerr << _("Invalid userdata.") << endl;
+ exit(EXIT_FAILURE);
+ }
+
+ for (list<string>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
+ {
+ string::size_type pos = it->find("=");
+ if (pos == string::npos)
+ {
+ cerr << _("Invalid userdata.") << endl;
+ exit(EXIT_FAILURE);
+ }
+
+ string key = boost::trim_copy(it->substr(0, pos));
+ string value = boost::trim_copy(it->substr(pos + 1));
+
+ if (key.empty())
+ {
+ cerr << _("Invalid userdata.") << endl;
+ exit(EXIT_FAILURE);
+ }
+
+ if (value.empty())
+ userdata.erase(key);
+ else
+ userdata[key] = value;
+ }
+
+ return userdata;
+}
+
+
+string
+show_userdata(const map& userdata)
+{
+ string s;
+
+ for (map::const_iterator it = userdata.begin(); it != userdata.end(); ++it)
+ {
+ if (!s.empty())
+ s += ", ";
+ s += it->first + "=" + it->second;
+ }
+
+ return s;
+}
+
+
void
help_list_configs()
{
@@ -169,112 +277,6 @@
}
-Snapshots::iterator
-read_num(const string& str)
-{
- Snapshots& snapshots = sh->getSnapshots();
-
- istringstream s(str);
- unsigned int num = 0;
- s >> num;
-
- if (s.fail() || !s.eof())
- {
- cerr << sformat(_("Invalid snapshot '%s'."), str.c_str()) << endl;
- exit(EXIT_FAILURE);
- }
-
- Snapshots::iterator snap = snapshots.find(num);
- if (snap == snapshots.end())
- {
- cerr << sformat(_("Snapshot '%u' not found."), num) << endl;
- exit(EXIT_FAILURE);
- }
-
- return snap;
-}
-
-
-pair
-read_nums(const string& str)
-{
- string::size_type pos = str.find("..");
- if (pos == string::npos)
- {
- cerr << _("Invalid snapshots.") << endl;
- exit(EXIT_FAILURE);
- }
-
- Snapshots::iterator snap1 = read_num(str.substr(0, pos));
- Snapshots::iterator snap2 = read_num(str.substr(pos + 2));
-
- if (snap1 == snap2)
- {
- cerr << _("Identical snapshots.") << endl;
- exit(EXIT_FAILURE);
- }
-
- return pair(snap1, snap2);
-}
-
-
-map
-read_userdata(const string& s, const map& old = map())
-{
- map userdata = old;
-
- list<string> tmp;
- boost::split(tmp, s, boost::is_any_of(","), boost::token_compress_on);
- if (tmp.empty())
- {
- cerr << _("Invalid userdata.") << endl;
- exit(EXIT_FAILURE);
- }
-
- for (list<string>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
- {
- string::size_type pos = it->find("=");
- if (pos == string::npos)
- {
- cerr << _("Invalid userdata.") << endl;
- exit(EXIT_FAILURE);
- }
-
- string key = boost::trim_copy(it->substr(0, pos));
- string value = boost::trim_copy(it->substr(pos + 1));
-
- if (key.empty())
- {
- cerr << _("Invalid userdata.") << endl;
- exit(EXIT_FAILURE);
- }
-
- if (value.empty())
- userdata.erase(key);
- else
- userdata[key] = value;
- }
-
- return userdata;
-}
-
-
-string
-show_userdata(const map& userdata)
-{
- string s;
-
- for (map::const_iterator it = userdata.begin(); it != userdata.end(); ++it)
- {
- if (!s.empty())
- s += ", ";
- s += it->first + "=" + it->second;
- }
-
- return s;
-}
-
-
void
help_list()
{
@@ -495,35 +497,43 @@
exit(EXIT_FAILURE);
}
- switch (type)
+ try
+ {
+ switch (type)
+ {
+ case SINGLE: {
+ Snapshots::iterator snap1 = sh->createSingleSnapshot(description);
+ snap1->setCleanup(cleanup);
+ snap1->setUserdata(userdata);
+ snap1->flushInfo();
+ if (print_number)
+ cout << snap1->getNum() << endl;
+ } break;
+
+ case PRE: {
+ Snapshots::iterator snap1 = sh->createPreSnapshot(description);
+ snap1->setCleanup(cleanup);
+ snap1->setUserdata(userdata);
+ snap1->flushInfo();
+ if (print_number)
+ cout << snap1->getNum() << endl;
+ } break;
+
+ case POST: {
+ Snapshots::iterator snap2 = sh->createPostSnapshot(snap1);
+ snap2->setCleanup(cleanup);
+ snap2->setUserdata(userdata);
+ snap2->flushInfo();
+ if (print_number)
+ cout << snap2->getNum() << endl;
+ sh->startBackgroundComparsion(snap1, snap2);
+ } break;
+ }
+ }
+ catch (const InvalidUserdataException& e)
{
- case SINGLE: {
- Snapshots::iterator snap1 = sh->createSingleSnapshot(description);
- snap1->setCleanup(cleanup);
- snap1->setUserdata(userdata);
- snap1->flushInfo();
- if (print_number)
- cout << snap1->getNum() << endl;
- } break;
-
- case PRE: {
- Snapshots::iterator snap1 = sh->createPreSnapshot(description);
- snap1->setCleanup(cleanup);
- snap1->setUserdata(userdata);
- snap1->flushInfo();
- if (print_number)
- cout << snap1->getNum() << endl;
- } break;
-
- case POST: {
- Snapshots::iterator snap2 = sh->createPostSnapshot(snap1);
- snap2->setCleanup(cleanup);
- snap2->setUserdata(userdata);
- snap2->flushInfo();
- if (print_number)
- cout << snap2->getNum() << endl;
- sh->startBackgroundComparsion(snap1, snap2);
- } break;
+ cerr << _("Invalid userdata.") << endl;
+ exit(EXIT_FAILURE);
}
}
@@ -560,27 +570,35 @@
exit(EXIT_FAILURE);
}
- while (getopts.hasArgs())
+ try
{
- Snapshots::iterator snapshot = read_num(getopts.popArg());
- if (snapshot->isCurrent())
+ while (getopts.hasArgs())
{
- cerr << _("Invalid snapshot.") << endl;
- exit(EXIT_FAILURE);
- }
+ Snapshots::iterator snapshot = read_num(getopts.popArg());
- GetOpts::parsed_opts::const_iterator opt;
+ GetOpts::parsed_opts::const_iterator opt;
- if ((opt = opts.find("description")) != opts.end())
- snapshot->setDescription(opt->second);
+ if ((opt = opts.find("description")) != opts.end())
+ snapshot->setDescription(opt->second);
- if ((opt = opts.find("cleanup-algorithm")) != opts.end())
- snapshot->setCleanup(opt->second);
+ if ((opt = opts.find("cleanup-algorithm")) != opts.end())
+ snapshot->setCleanup(opt->second);
- if ((opt = opts.find("userdata")) != opts.end())
- snapshot->setUserdata(read_userdata(opt->second, snapshot->getUserdata()));
+ if ((opt = opts.find("userdata")) != opts.end())
+ snapshot->setUserdata(read_userdata(opt->second, snapshot->getUserdata()));
- snapshot->flushInfo();
+ snapshot->flushInfo();
+ }
+ }
+ catch (const IllegalSnapshotException& e)
+ {
+ cerr << _("Invalid snapshot.") << endl;
+ exit(EXIT_FAILURE);
+ }
+ catch (const InvalidUserdataException& e)
+ {
+ cerr << _("Invalid userdata.") << endl;
+ exit(EXIT_FAILURE);
}
}
@@ -604,16 +622,19 @@
exit(EXIT_FAILURE);
}
- while (getopts.hasArgs())
+ try
{
- Snapshots::iterator snapshot = read_num(getopts.popArg());
- if (snapshot->isCurrent())
+ while (getopts.hasArgs())
{
- cerr << _("Invalid snapshot.") << endl;
- exit(EXIT_FAILURE);
- }
+ Snapshots::iterator snapshot = read_num(getopts.popArg());
- sh->deleteSnapshot(snapshot);
+ sh->deleteSnapshot(snapshot);
+ }
+ }
+ catch (const IllegalSnapshotException& e)
+ {
+ cerr << _("Invalid snapshot.") << endl;
+ exit(EXIT_FAILURE);
}
}
@@ -637,16 +658,19 @@
exit(EXIT_FAILURE);
}
- while (getopts.hasArgs())
+ try
{
- Snapshots::iterator snapshot = read_num(getopts.popArg());
- if (snapshot->isCurrent())
+ while (getopts.hasArgs())
{
- cerr << _("Invalid snapshot.") << endl;
- exit(EXIT_FAILURE);
- }
+ Snapshots::iterator snapshot = read_num(getopts.popArg());
- snapshot->mountFilesystemSnapshot();
+ snapshot->mountFilesystemSnapshot();
+ }
+ }
+ catch (const IllegalSnapshotException& e)
+ {
+ cerr << _("Invalid snapshot.") << endl;
+ exit(EXIT_FAILURE);
}
}
@@ -670,16 +694,19 @@
exit(EXIT_FAILURE);
}
- while (getopts.hasArgs())
+ try
{
- Snapshots::iterator snapshot = read_num(getopts.popArg());
- if (snapshot->isCurrent())
+ while (getopts.hasArgs())
{
- cerr << _("Invalid snapshot.") << endl;
- exit(EXIT_FAILURE);
- }
+ Snapshots::iterator snapshot = read_num(getopts.popArg());
- snapshot->umountFilesystemSnapshot();
+ snapshot->umountFilesystemSnapshot();
+ }
+ }
+ catch (const IllegalSnapshotException& e)
+ {
+ cerr << _("Invalid snapshot.") << endl;
+ exit(EXIT_FAILURE);
}
}
@@ -1028,6 +1055,8 @@
int
main(int argc, char** argv)
{
+ umask(0027);
+
setlocale(LC_ALL, "");
initDefaultLogger();
@@ -1136,7 +1165,17 @@
sh->setUndoCallback(&undo_callback_impl);
}
- (*cmd->second)();
+ try
+ {
+ (*cmd->second)();
+ }
+ catch (const SnapperException& e)
+ {
+ y2err("caught final exception");
+ cerr << sformat(_("Command failed (%s). See log for more information."),
+ e.what()) << endl;
+ exit(EXIT_FAILURE);
+ }
deleteSnapper(sh);
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Remember to have fun...
--
To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org
For additional commands, e-mail: opensuse-commit+help@opensuse.org