]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- work on exceptions
authorArvin Schnell <aschnell@suse.de>
Tue, 26 Apr 2011 12:22:35 +0000 (14:22 +0200)
committerArvin Schnell <aschnell@suse.de>
Tue, 26 Apr 2011 12:22:35 +0000 (14:22 +0200)
snapper/File.cc
snapper/Snapper.cc
snapper/Snapper.h
snapper/Snapshot.cc
snapper/Snapshot.h
tools/snapper.cc

index a9d2cee0d4a792d25ad5350ab9587ed3a6d9830f..5ce1628a0c01bc3b69ed97b783d25957313c965f 100644 (file)
@@ -30,7 +30,6 @@
 #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"
index 1a2f3db5786ee5040784db9fb6ddca621f621a2c..12512b4cae1e7dee360718f2153b31d7c3585459 100644 (file)
@@ -52,11 +52,19 @@ namespace snapper
        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);
 
index a152b6fb28e8c9f3f23ab0dfae2df916bd709e2b..d70e2a44786690276170255f88e7ded9762ce44d 100644 (file)
@@ -56,6 +56,19 @@ namespace snapper
     };
 
 
+    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:
index 71986292b85a336907016aaf8b5b685750393758..8512769cdd63b693130f789eef8e04b60942c340 100644 (file)
@@ -314,19 +314,21 @@ namespace snapper
     }
 
 
-    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();
     }
 
 
index 74c1a078eeba202bcb4da90574f5e9f58acc7755..82a11ee0ebc8101a89755ba4de6a723ac91a2f4e 100644 (file)
@@ -41,6 +41,19 @@ namespace snapper
     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:
@@ -87,8 +100,8 @@ namespace snapper
        string cleanup;
 
        bool writeInfo() const;
-       bool createFilesystemSnapshot() const;
-       bool deleteFilesystemSnapshot() const;
+       void createFilesystemSnapshot() const;
+       void deleteFilesystemSnapshot() const;
 
     };
 
index b83828354384c6c4c2ba1bb83d4484909caf9290..50d2101ddaacf7c30785e3e52faf74dff8f5d56a 100644 (file)
@@ -666,7 +666,20 @@ main(int argc, char** argv)
     }
     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);