#include "snapper/File.h"
#include "snapper/Snapper.h"
#include "snapper/Comparison.h"
-#include "snapper/Factory.h"
#include "snapper/AppUtil.h"
#include "snapper/XmlFile.h"
#include "snapper/Enum.h"
y2mil("libsnapper version " VERSION);
y2mil("config_name:" << config_name);
- config = new SysconfigFile(CONFIGSDIR "/" + config_name);
+ try
+ {
+ config = new SysconfigFile(CONFIGSDIR "/" + config_name);
+ }
+ catch (const FileNotFoundException& e)
+ {
+ throw ConfigNotFoundException();
+ }
string val;
- if (config->getValue("SUBVOLUME", val))
- subvolume = val;
+ if (!config->getValue("SUBVOLUME", val))
+ throw InvalidConfigException();
+ subvolume = val;
y2mil("subvolume:" << subvolume);
};
+ struct ConfigNotFoundException : public std::exception
+ {
+ explicit ConfigNotFoundException() throw() {}
+ virtual const char* what() const throw() { return "config not found"; }
+ };
+
+ struct InvalidConfigException : public std::exception
+ {
+ explicit InvalidConfigException() throw() {}
+ virtual const char* what() const throw() { return "invalid config"; }
+ };
+
+
class Snapper
{
public:
}
- bool
+ void
Snapshot::createFilesystemSnapshot() const
{
SystemCmd cmd(BTRFSBIN " subvolume snapshot " + snapper->subvolumeDir() + " " + snapshotDir());
- return cmd.retcode() == 0;
+ if (cmd.retcode() != 0)
+ throw CreateSnapshotFailedException();
}
- bool
+ void
Snapshot::deleteFilesystemSnapshot() const
{
- SystemCmd cmd(BTRFSBIN " subvolume delete /" + snapshotDir());
- return cmd.retcode() == 0;
+ SystemCmd cmd(BTRFSBIN " subvolume delete " + snapshotDir());
+ if (cmd.retcode() != 0)
+ throw DeleteSnapshotFailedException();
}
enum SnapshotType { SINGLE, PRE, POST };
+ struct CreateSnapshotFailedException : public std::exception
+ {
+ explicit CreateSnapshotFailedException() throw() {}
+ virtual const char* what() const throw() { return "create snapshot failed"; }
+ };
+
+ struct DeleteSnapshotFailedException : public std::exception
+ {
+ explicit DeleteSnapshotFailedException() throw() {}
+ virtual const char* what() const throw() { return "delete snapshot failed"; }
+ };
+
+
class Snapshot
{
public:
string cleanup;
bool writeInfo() const;
- bool createFilesystemSnapshot() const;
- bool deleteFilesystemSnapshot() const;
+ void createFilesystemSnapshot() const;
+ void deleteFilesystemSnapshot() const;
};
}
else
{
- sh = createSnapper(config_name);
+ try
+ {
+ sh = createSnapper(config_name);
+ }
+ catch (const ConfigNotFoundException& e)
+ {
+ cerr << sformat(_("Config '%s' not found."), config_name.c_str()) << endl;
+ exit(EXIT_FAILURE);
+ }
+ catch (const InvalidConfigException& e)
+ {
+ cerr << sformat(_("Config '%s' is invalid."), config_name.c_str()) << endl;
+ exit(EXIT_FAILURE);
+ }
if (!quiet)
sh->setCompareCallback(&compare_callback_impl);