#include "snapper/AppUtil.h"
#include "snapper/AsciiFile.h"
#include "snapper/SnapperTypes.h"
+#include "snapper/Exception.h"
namespace snapper
if (file == NULL)
{
y2err("file is NULL");
- throw exception(); // TODO
+ throw FileNotFoundException();
}
}
if (file == NULL)
{
y2err("open for '" << filename << "' failed");
- throw exception(); // TODO
+ throw FileNotFoundException();
}
}
}
-bool
-AsciiFile::reload()
-{
- y2mil("loading file " << Name_C);
- clear();
-
- try
+ void
+ AsciiFile::reload()
{
+ y2mil("loading file " << Name_C);
+ clear();
+
AsciiFileReader file(Name_C);
string line;
while (file.getline(line))
Lines_C.push_back(line);
-
- return true;
}
- catch (...) // TODO
- {
- return false;
- }
-}
bool
string name() const { return Name_C; }
- bool reload();
+ void reload();
bool save();
void logContent() const;
*/
-#include <assert.h>
-
#include "snapper/Comparison.h"
#include "snapper/Snapper.h"
#include "snapper/AppUtil.h"
#include "snapper/File.h"
+#include "snapper/Exception.h"
namespace snapper
Snapshots::const_iterator snapshot2)
: snapper(snapper), snapshot1(snapshot1), snapshot2(snapshot2), files(this)
{
- assert(snapshot1 != snapper->getSnapshots().end());
- assert(snapshot2 != snapper->getSnapshots().end());
- assert(snapshot1 != snapshot2);
+ if (snapshot1 == snapper->getSnapshots().end() ||
+ snapshot2 == snapper->getSnapshots().end() ||
+ snapshot1 == snapshot2)
+ throw IllegalSnapshotException();
y2mil("num1:" << snapshot1->getNum() << " num2:" << snapshot2->getNum());
--- /dev/null
+/*
+ * Copyright (c) 2011 Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#ifndef EXCEPTION_H
+#define EXCEPTION_H
+
+
+#include <exception>
+
+
+namespace snapper
+{
+
+ struct FileNotFoundException : public std::exception
+ {
+ explicit FileNotFoundException() throw() {}
+ virtual const char* what() const throw() { return "file not found"; }
+ };
+
+
+ struct IllegalSnapshotException : public std::exception
+ {
+ explicit IllegalSnapshotException() throw() {}
+ virtual const char* what() const throw() { return "illegal snapshot"; }
+ };
+
+}
+
+
+#endif
#include "snapper/SnapperDefines.h"
#include "snapper/Compare.h"
#include "snapper/AsciiFile.h"
+#include "snapper/Exception.h"
namespace snapper
y2mil("num1:" << comparison->getSnapshot1()->getNum() << " num2:" <<
comparison->getSnapshot2()->getNum());
- assert(!comparison->getSnapshot1()->isCurrent() && !comparison->getSnapshot2()->isCurrent());
+ if (comparison->getSnapshot1()->isCurrent() || comparison->getSnapshot2()->isCurrent())
+ throw IllegalSnapshotException();
unsigned int num1 = comparison->getSnapshot1()->getNum();
unsigned int num2 = comparison->getSnapshot2()->getNum();
return true;
}
- catch (...) // TODO
+ catch (const FileNotFoundException& e)
{
return false;
}
+
+ return true;
}
{
y2mil("num1:" << comparison->getSnapshot1()->getNum() << " num2:" << comparison->getSnapshot2()->getNum());
- assert(!comparison->getSnapshot1()->isCurrent() && !comparison->getSnapshot2()->isCurrent());
+ if (comparison->getSnapshot1()->isCurrent() || comparison->getSnapshot2()->isCurrent())
+ throw IllegalSnapshotException();
unsigned int num1 = comparison->getSnapshot1()->getNum();
unsigned int num2 = comparison->getSnapshot2()->getNum();
SystemCmd.cc SystemCmd.h \
AsciiFile.cc AsciiFile.h \
Regex.cc Regex.h \
+ Exception.h \
SnapperTmpl.h \
SnapperTypes.h \
SnapperDefines.h
Factory.h \
Snapper.h \
Snapshot.h \
+ File.h \
Comparison.h \
- File.h
+ Exception.h
#include "snapper/SnapperDefines.h"
#include "snapper/File.h"
#include "snapper/AsciiFile.h"
+#include "snapper/Exception.h"
namespace snapper
y2mil("libsnapper version " VERSION);
y2mil("config_name:" << config_name);
- // TODO error checking
config = new SysconfigFile(CONFIGSDIR "/" + config_name);
string val;
while (asciifile.getline(line))
ignore_patterns.push_back(line);
}
- catch (...) // TODO
+ catch (const FileNotFoundException& e)
{
}
}
Snapshots::iterator
Snapper::createPostSnapshot(Snapshots::const_iterator pre)
{
- assert(pre != snapshots.end());
-
return snapshots.createPostSnapshot(pre);
}
void
Snapper::deleteSnapshot(Snapshots::iterator snapshot)
{
- assert(snapshot != snapshots.end());
-
snapshots.deleteSnapshot(snapshot);
}
Snapper::startBackgroundComparsion(Snapshots::const_iterator snapshot1,
Snapshots::const_iterator snapshot2)
{
- assert(snapshot1 != snapshots.end() && snapshot2 != snapshots.end());
+ if (snapshot1 == snapshots.end() || snapshot1->isCurrent())
+ throw IllegalSnapshotException();
+
+ if (snapshot2 == snapshots.end() || snapshot2->isCurrent())
+ throw IllegalSnapshotException();
y2mil("num1:" << snapshot1->getNum() << " num2:" << snapshot2->getNum());
#include "snapper/SnapperTmpl.h"
#include "snapper/SystemCmd.h"
#include "snapper/SnapperDefines.h"
+#include "snapper/Exception.h"
namespace snapper
Snapshots::iterator
Snapshots::findPost(const_iterator pre)
{
- assert(pre != end());
- assert(pre->getType() == PRE);
+ if (pre == entries.end() || pre->isCurrent() || pre->getType() != PRE)
+ throw IllegalSnapshotException();
for (iterator it = begin(); it != end(); ++it)
{
Snapshots::const_iterator
Snapshots::findPost(const_iterator pre) const
{
- assert(pre != end());
- assert(pre->getType() == PRE);
+ if (pre == entries.end() || pre->isCurrent() || pre->getType() != PRE)
+ throw IllegalSnapshotException();
for (const_iterator it = begin(); it != end(); ++it)
{
Snapshots::iterator
Snapshots::createPostSnapshot(Snapshots::const_iterator pre)
{
+ if (pre == entries.end() || pre->isCurrent() || pre->getType() != PRE)
+ throw IllegalSnapshotException();
+
Snapshot snapshot(snapper);
snapshot.type = POST;
snapshot.num = nextNumber();
void
Snapshots::deleteSnapshot(iterator snapshot)
{
- assert(!snapshot->isCurrent());
+ if (snapshot == entries.end() || snapshot->isCurrent())
+ throw IllegalSnapshotException();
snapshot->deleteFilesystemSnapshot();
#include <time.h>
-
#include <string>
#include <list>