]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- use exception macros
authorArvin Schnell <aschnell@suse.de>
Wed, 30 Mar 2016 14:09:26 +0000 (16:09 +0200)
committerArvin Schnell <aschnell@suse.de>
Wed, 30 Mar 2016 14:09:26 +0000 (16:09 +0200)
snapper/Acls.cc
snapper/AsciiFile.cc
snapper/Btrfs.cc
snapper/Compare.cc
snapper/Comparison.cc
snapper/FileUtils.cc
snapper/Filesystem.cc
snapper/Snapper.cc
snapper/Snapshot.cc
snapper/XAttributes.cc

index e81a191d71aee8b1853258b9d0fb903b7126c0fb..cfd2cc58619a5bf20deef454bd3d8233c84e45ec 100644 (file)
@@ -57,7 +57,7 @@ namespace snapper
            if (stat(path.c_str(), &buf) < 0)
            {
                y2err("stat failed errno: " << errno << " (" << stringerror(errno) << ")");
-               throw AclException();
+               SN_THROW(AclException());
            }
        }
        else
@@ -66,7 +66,7 @@ namespace snapper
            {
                y2err("fstat failed errno: " << errno << " (" << stringerror(errno) << ")");
                ::close(fd);
-               throw AclException();
+               SN_THROW(AclException());
            }
 
            acl_access = acl_get_fd(fd);
@@ -74,7 +74,7 @@ namespace snapper
            {
                y2err("acl_get_fd failed errno: " << errno << " (" << stringerror(errno) << ")");
                ::close(fd);
-               throw AclException();
+               SN_THROW(AclException());
            }
 
            ::close(fd);
@@ -91,7 +91,7 @@ namespace snapper
            if (!acl_access)
            {
                y2err("acl_get_file failed errno: " << errno << " (" << stringerror(errno) << ")");
-               throw AclException();
+               SN_THROW(AclException());
            }
        }
 
@@ -107,7 +107,7 @@ namespace snapper
                    y2err("acl_free failed errno: " << errno << " (" << stringerror(errno) << ")");
                }
 
-               throw AclException();
+               SN_THROW(AclException());
            }
        }
     }
@@ -131,7 +131,7 @@ namespace snapper
        if (acl_set_file(path.c_str(), ACL_TYPE_ACCESS, acl_access))
        {
            y2err("acl_set_file failed errno: " << errno << " (" << stringerror(errno) << ")");
-           throw AclException();
+           SN_THROW(AclException());
        }
 
        if (get_acl_types() & ACL_TYPE_DEFAULT)
@@ -139,7 +139,7 @@ namespace snapper
            if (acl_set_file(path.c_str(), ACL_TYPE_DEFAULT, acl_default))
            {
                y2err("acl_set_file failed errno: " << errno << " (" << stringerror(errno) << ")");
-               throw AclException();
+               SN_THROW(AclException());
            }
        }
     }
index f08a8d1707bf54a0d91dfe2f305fa78d06f35e81..04714ab9bffaaaad24b0ae7d49a8b2368ba367fc 100644 (file)
@@ -41,7 +41,7 @@ namespace snapper
        if (file == NULL)
        {
            y2war("file is NULL");
-           throw FileNotFoundException();
+           SN_THROW(FileNotFoundException());
        }
     }
 
@@ -52,7 +52,7 @@ namespace snapper
        if (file == NULL)
        {
            y2war("file is NULL");
-           throw FileNotFoundException();
+           SN_THROW(FileNotFoundException());
        }
     }
 
@@ -64,7 +64,7 @@ namespace snapper
        if (file == NULL)
        {
            y2war("open for '" << filename << "' failed");
-           throw FileNotFoundException();
+           SN_THROW(FileNotFoundException());
        }
     }
 
@@ -174,7 +174,7 @@ AsciiFile::save()
        Regex rx("^" "([0-9A-Z_]+)" "$");
 
        if (!rx.match(key))
-           throw InvalidKeyException();
+           SN_THROW(InvalidKeyException());
     }
 
 
index 50570c5e1ff0c1a717021e0e633e54db028206fb..de01c5775d4af4f733a3213c7da5eb2e8725a2bc 100644 (file)
@@ -95,7 +95,7 @@ namespace snapper
            catch (const runtime_error& e)
            {
                y2err("failed to parse qgroup '" << qgroup_str << "'");
-               throw InvalidConfigException();
+               SN_THROW(InvalidConfigException());
            }
        }
 
@@ -119,11 +119,11 @@ namespace snapper
            switch (e.error_number)
            {
                case EEXIST:
-                   throw CreateConfigFailedException("creating btrfs subvolume .snapshots failed "
-                                                     "since it already exists");
+                   SN_THROW(CreateConfigFailedException("creating btrfs subvolume .snapshots failed "
+                                                        "since it already exists"));
 
                default:
-                   throw CreateConfigFailedException("creating btrfs subvolume .snapshots failed");
+                   SN_THROW(CreateConfigFailedException("creating btrfs subvolume .snapshots failed"));
            }
        }
 
@@ -155,7 +155,7 @@ namespace snapper
        catch (const runtime_error& e)
        {
            y2err("delete subvolume failed, " << e.what());
-           throw DeleteConfigFailedException("deleting btrfs snapshot failed");
+           SN_THROW(DeleteConfigFailedException("deleting btrfs snapshot failed"));
        }
     }
 
@@ -214,12 +214,12 @@ namespace snapper
        struct stat stat;
        if (subvolume_dir.stat(&stat) != 0)
        {
-           throw IOErrorException("stat on subvolume directory failed");
+           SN_THROW(IOErrorException("stat on subvolume directory failed"));
        }
 
        if (!is_subvolume(stat))
        {
-           throw IOErrorException("subvolume is not a btrfs subvolume");
+           SN_THROW(IOErrorException("subvolume is not a btrfs subvolume"));
        }
 
        return subvolume_dir;
@@ -235,7 +235,7 @@ namespace snapper
        struct stat stat;
        if (infos_dir.stat(&stat) != 0)
        {
-           throw IOErrorException("stat on info directory failed");
+           SN_THROW(IOErrorException("stat on info directory failed"));
        }
 
        if (!is_subvolume(stat))
@@ -246,19 +246,19 @@ namespace snapper
        if (stat.st_uid != 0)
        {
            y2err(".snapshots must have owner root");
-           throw IOErrorException(".snapshots must have owner root");
+           SN_THROW(IOErrorException(".snapshots must have owner root"));
        }
 
        if (stat.st_gid != 0 && stat.st_mode & S_IWGRP)
        {
            y2err(".snapshots must have group root or must not be group-writable");
-           throw IOErrorException(".snapshots must have group root or must not be group-writable");
+           SN_THROW(IOErrorException(".snapshots must have group root or must not be group-writable"));
        }
 
        if (stat.st_mode & S_IWOTH)
        {
            y2err(".snapshots must not be world-writable");
-           throw IOErrorException(".snapshots must not be world-writable");
+           SN_THROW(IOErrorException(".snapshots must not be world-writable"));
        }
 
        return infos_dir;
@@ -290,7 +290,7 @@ namespace snapper
            catch (const runtime_error& e)
            {
                y2err("create snapshot failed, " << e.what());
-               throw CreateSnapshotFailedException();
+               SN_THROW(CreateSnapshotFailedException());
            }
        }
        else
@@ -305,7 +305,7 @@ namespace snapper
            catch (const runtime_error& e)
            {
                y2err("create snapshot failed, " << e.what());
-               throw CreateSnapshotFailedException();
+               SN_THROW(CreateSnapshotFailedException());
            }
        }
     }
@@ -325,7 +325,7 @@ namespace snapper
        if (!getMtabData(subvolume, found, mtab_data))
        {
            y2err("failed to find device");
-           throw CreateSnapshotFailedException();
+           SN_THROW(CreateSnapshotFailedException());
        }
 
        SDir infos_dir = openInfosDir();
@@ -342,7 +342,7 @@ namespace snapper
        catch (const runtime_error& e)
        {
            y2err("create snapshot failed, " << e.what());
-           throw CreateSnapshotFailedException();
+           SN_THROW(CreateSnapshotFailedException());
        }
     }
 
@@ -386,7 +386,7 @@ namespace snapper
        catch (const runtime_error& e)
        {
            y2err("delete snapshot failed, " << e.what());
-           throw DeleteSnapshotFailedException();
+           SN_THROW(DeleteSnapshotFailedException());
        }
     }
 
@@ -711,7 +711,7 @@ namespace snapper
        if (r < 0)
        {
            y2err("failed to initialize subvol search (" << stringerror(r) << ")");
-           throw BtrfsSendReceiveException();
+           SN_THROW(BtrfsSendReceiveException());
        }
     }
 
@@ -1234,7 +1234,7 @@ namespace snapper
        if (r1 < 0)
        {
            y2err("pipe failed errno:" << errno << " (" << stringerror(errno) << ")");
-           throw BtrfsSendReceiveException();
+           SN_THROW(BtrfsSendReceiveException());
        }
 
        struct btrfs_ioctl_send_args io_send;
@@ -1266,7 +1266,7 @@ namespace snapper
 
        if (r2 < 0 || !uf.get())
        {
-           throw BtrfsSendReceiveException();
+           SN_THROW(BtrfsSendReceiveException());
        }
 
 #else
@@ -1287,7 +1287,7 @@ namespace snapper
 
        if (r2 < 0 || !dumper_ret)
        {
-           throw BtrfsSendReceiveException();
+           SN_THROW(BtrfsSendReceiveException());
        }
 
 #endif
@@ -1300,7 +1300,7 @@ namespace snapper
        u64 flags;
        if (ioctl(dir.fd(), BTRFS_IOC_SUBVOL_GETFLAGS, &flags) < 0)
        {
-           throw IOErrorException("ioctl BTRFS_IOC_SUBVOL_GETFLAGS failed");
+           SN_THROW(IOErrorException("ioctl BTRFS_IOC_SUBVOL_GETFLAGS failed"));
        }
 
        return flags & BTRFS_SUBVOL_RDONLY;
@@ -1315,7 +1315,7 @@ namespace snapper
        if (!is_subvolume_ro(dir1) || !is_subvolume_ro(dir2))
        {
            y2err("not read-only snapshots");
-           throw BtrfsSendReceiveException();
+           SN_THROW(BtrfsSendReceiveException());
        }
 
        u64 parent_root_id = 0;
@@ -1323,7 +1323,7 @@ namespace snapper
        if (!get_root_id(name1, &parent_root_id))
        {
            y2err("could not resolve root_id for " << name1);
-           throw BtrfsSendReceiveException();
+           SN_THROW(BtrfsSendReceiveException());
        }
 
        vector<u64> clone_sources;
@@ -1401,7 +1401,7 @@ namespace snapper
        }
        catch (const runtime_error& e)
        {
-           throw IOErrorException(string("set default failed, ") + e.what());
+           SN_THROW(IOErrorException(string("set default failed, ") + e.what()));
        }
     }
 
index ce68b7f07164d9c1a9e4bf9cec1868d19f72e225..2119e04cd2125caaee3b6b235ead935120863a02 100644 (file)
@@ -158,7 +158,7 @@ namespace snapper
                    const struct stat& stat2)
     {
        if ((stat1.st_mode & S_IFMT) != (stat2.st_mode & S_IFMT))
-           throw LogicErrorException();
+           SN_THROW(LogicErrorException());
 
        switch (stat1.st_mode & S_IFMT)
        {
@@ -247,10 +247,10 @@ namespace snapper
            return DELETED;
 
        if (r1 != 0)
-           throw IOErrorException("stat failed path:" + file1.fullname());
+           SN_THROW(IOErrorException("stat failed path:" + file1.fullname()));
 
        if (r2 != 0)
-           throw IOErrorException("lstat failed path:" + file2.fullname());
+           SN_THROW(IOErrorException("lstat failed path:" + file2.fullname()));
 
        return cmpFiles(file1, stat1, file2, stat2);
     }
@@ -409,7 +409,7 @@ namespace snapper
            else
            {
                if (*first1 != *first2)
-                   throw LogicErrorException();
+                   SN_THROW(LogicErrorException());
 
                struct stat stat1;
                dir1.stat(*first1, &stat1, AT_SYMLINK_NOFOLLOW); // TODO error check
@@ -433,12 +433,14 @@ namespace snapper
        struct stat stat1;
        int r1 = dir1.stat(&stat1);
        if (r1 != 0)
-           throw IOErrorException(sformat("stat failed path:%s errno:%d", dir1.fullname().c_str(), errno));
+           SN_THROW(IOErrorException(sformat("stat failed path:%s errno:%d",
+                                             dir1.fullname().c_str(), errno)));
 
        struct stat stat2;
        int r2 = dir2.stat(&stat2);
        if (r2 != 0)
-           throw IOErrorException(sformat("stat failed path:%s errno:%d", dir2.fullname().c_str(), errno));
+           SN_THROW(IOErrorException(sformat("stat failed path:%s errno:%d",
+                                             dir2.fullname().c_str(), errno)));
 
        CmpData cmp_data;
        cmp_data.cb = cb;
index 8a2a2d7374c3f7417fa37ac03086d7a20cdddebd..5f39efe30eed94e5b3b75a7fb8c1b093e62e9adf 100644 (file)
@@ -51,7 +51,7 @@ namespace snapper
        if (snapshot1 == snapper->getSnapshots().end() ||
            snapshot2 == snapper->getSnapshots().end() ||
            snapshot1 == snapshot2)
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        y2mil("num1:" << snapshot1->getNum() << " num2:" << snapshot2->getNum());
 
@@ -152,7 +152,7 @@ namespace snapper
        y2mil("num1:" << getSnapshot1()->getNum() << " num2:" << getSnapshot2()->getNum());
 
        if (getSnapshot1()->isCurrent() || getSnapshot2()->isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        unsigned int num1 = getSnapshot1()->getNum();
        unsigned int num2 = getSnapshot2()->getNum();
@@ -210,7 +210,7 @@ namespace snapper
        y2mil("num1:" << getSnapshot1()->getNum() << " num2:" << getSnapshot2()->getNum());
 
        if (getSnapshot1()->isCurrent() || getSnapshot2()->isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        unsigned int num1 = getSnapshot1()->getNum();
        unsigned int num2 = getSnapshot2()->getNum();
@@ -227,8 +227,8 @@ namespace snapper
 
        FILE* file = fdopen(info_dir.mktemp(tmp_name), "w");
        if (!file)
-           throw IOErrorException(sformat("mkstemp failed errno:%d (%s)", errno,
-                                          stringerror(errno).c_str()));
+           SN_THROW(IOErrorException(sformat("mkstemp failed errno:%d (%s)", errno,
+                                             stringerror(errno).c_str())));
 
        for (Files::const_iterator it = files.begin(); it != files.end(); ++it)
        {
@@ -258,7 +258,7 @@ namespace snapper
     Comparison::getUndoStatistic() const
     {
        if (getSnapshot1()->isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        return files.getUndoStatistic();
     }
@@ -268,7 +268,7 @@ namespace snapper
     Comparison::getXAUndoStatistic() const
     {
         if (getSnapshot1()->isCurrent())
-            throw IllegalSnapshotException();
+            SN_THROW(IllegalSnapshotException());
 
         return files.getXAUndoStatistic();
     }
@@ -278,7 +278,7 @@ namespace snapper
     Comparison::getUndoSteps() const
     {
        if (getSnapshot1()->isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        return files.getUndoSteps();
     }
@@ -288,7 +288,7 @@ namespace snapper
     Comparison::doUndoStep(const UndoStep& undo_step)
     {
        if (getSnapshot1()->isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        return files.doUndoStep(undo_step);
     }
index ec8d8cc296fa3ac3482379c3addfdacd253095e2..19ffb57bb00b65c7b2738537b8dab8a02a50223f 100644 (file)
@@ -55,16 +55,16 @@ namespace snapper
     {
        dirfd = ::open(base_path.c_str(), O_RDONLY | O_NOATIME | O_CLOEXEC);
        if (dirfd < 0)
-           throw IOErrorException(sformat("open failed path:%s errno:%d (%s)", base_path.c_str(),
-                                          errno, stringerror(errno).c_str()));
+           SN_THROW(IOErrorException(sformat("open failed path:%s errno:%d (%s)", base_path.c_str(),
+                                             errno, stringerror(errno).c_str())));
 
        struct stat buf;
        if (fstat(dirfd, &buf) != 0)
-           throw IOErrorException(sformat("fstat failed path:%s errno:%d (%s)", base_path.c_str(),
-                                          errno, stringerror(errno).c_str()));
+           SN_THROW(IOErrorException(sformat("fstat failed path:%s errno:%d (%s)", base_path.c_str(),
+                                             errno, stringerror(errno).c_str())));
 
        if (!S_ISDIR(buf.st_mode))
-           throw IOErrorException("not a directory path:" + base_path);
+           SN_THROW(IOErrorException("not a directory path:" + base_path));
 
        setXaStatus();
     }
@@ -78,18 +78,18 @@ namespace snapper
 
        dirfd = ::openat(dir.dirfd, name.c_str(), O_RDONLY | O_NOFOLLOW | O_NOATIME | O_CLOEXEC);
        if (dirfd < 0)
-           throw IOErrorException(sformat("open failed path:%s errno:%d (%s)", dir.fullname().c_str(),
-                                          errno, stringerror(errno).c_str()));
+           SN_THROW(IOErrorException(sformat("open failed path:%s errno:%d (%s)", dir.fullname().c_str(),
+                                             errno, stringerror(errno).c_str())));
 
        struct stat buf;
        if (fstat(dirfd, &buf) != 0)
-           throw IOErrorException(sformat("fstat failed path:%s errno:%d (%s)", base_path.c_str(),
-                                          errno, stringerror(errno).c_str()));
+           SN_THROW(IOErrorException(sformat("fstat failed path:%s errno:%d (%s)", base_path.c_str(),
+                                             errno, stringerror(errno).c_str())));
 
        if (!S_ISDIR(buf.st_mode))
        {
            close(dirfd);
-           throw IOErrorException("not a directory path:" + dir.fullname(name));
+           SN_THROW(IOErrorException("not a directory path:" + dir.fullname(name)));
        }
 
        xastatus = dir.xastatus;
@@ -101,8 +101,8 @@ namespace snapper
     {
        dirfd = fcntl(dir.dirfd, F_DUPFD_CLOEXEC, 0);
        if (dirfd == -1)
-           throw IOErrorException(sformat("fcntl(F_DUPFD_CLOEXEC) failed error:%d (%s)", errno,
-                                          stringerror(errno).c_str()));
+           SN_THROW(IOErrorException(sformat("fcntl(F_DUPFD_CLOEXEC) failed error:%d (%s)", errno,
+                                             stringerror(errno).c_str())));
 
        xastatus = dir.xastatus;
     }
@@ -116,8 +116,8 @@ namespace snapper
            ::close(dirfd);
            dirfd = fcntl(dir.dirfd, F_DUPFD_CLOEXEC, 0);
            if (dirfd == -1)
-               throw IOErrorException(sformat("fcntl(F_DUPFD_CLOEXEC) failed error:%d (%s)", errno,
-                                              stringerror(errno).c_str()));
+               SN_THROW(IOErrorException(sformat("fcntl(F_DUPFD_CLOEXEC) failed error:%d (%s)", errno,
+                                                 stringerror(errno).c_str())));
 
            xastatus = dir.xastatus;
        }
@@ -176,15 +176,15 @@ namespace snapper
     {
        int fd = fcntl(dirfd, F_DUPFD_CLOEXEC, 0);
        if (fd == -1)
-           throw IOErrorException(sformat("fcntl(F_DUPFD_CLOEXEC) failed error:%d (%s)", errno,
-                                          stringerror(errno).c_str()));
+           SN_THROW(IOErrorException(sformat("fcntl(F_DUPFD_CLOEXEC) failed error:%d (%s)", errno,
+                                             stringerror(errno).c_str())));
 
        DIR* dp = fdopendir(fd);
        if (dp == NULL)
        {
            ::close(fd);
-           throw IOErrorException(sformat("fdopendir failed path:%s error:%d (%s)",
-                                          fullname().c_str(), errno, stringerror(errno).c_str()));
+           SN_THROW(IOErrorException(sformat("fdopendir failed path:%s error:%d (%s)",
+                                             fullname().c_str(), errno, stringerror(errno).c_str())));
        }
 
        vector<string> ret;
@@ -499,9 +499,9 @@ namespace snapper
            }
            else
            {
-                throw IOErrorException(sformat("Couldn't get extended attributes status for %s/%s, "
-                                              "errno:%d (%s)", base_path.c_str(), path.c_str(),
-                                              errno, stringerror(errno).c_str()));
+                SN_THROW(IOErrorException(sformat("Couldn't get extended attributes status for %s/%s, "
+                                                 "errno:%d (%s)", base_path.c_str(), path.c_str(),
+                                                 errno, stringerror(errno).c_str())));
            }
        }
        else
index 045cb83a97f177d65a7d9cd7bfd437818a674c1e..98a2bcb10f5a9de38e56fa8a3c3a8b9c67ed1921 100644 (file)
@@ -117,7 +117,8 @@ namespace snapper
        }
 
        y2err("do not know about fstype '" << fstype << "'");
-       throw InvalidConfigException();
+       SN_THROW(InvalidConfigException());
+       __builtin_unreachable();
     }
 
 
index c17e018858001a59bc1acd36b1723a29715b170d..2fa5c91ecef2a01ed5b651c24c9488546de0a368 100644 (file)
@@ -56,7 +56,7 @@ namespace snapper
          config_name(config_name), subvolume("/")
     {
        if (!getValue(KEY_SUBVOLUME, subvolume))
-           throw InvalidConfigException();
+           SN_THROW(InvalidConfigException());
     }
 
 
@@ -64,7 +64,7 @@ namespace snapper
     ConfigInfo::checkKey(const string& key) const
     {
        if (key == KEY_SUBVOLUME || key == KEY_FSTYPE)
-           throw InvalidConfigdataException();
+           SN_THROW(InvalidConfigdataException());
 
        try
        {
@@ -72,7 +72,7 @@ namespace snapper
        }
        catch (const InvalidKeyException& e)
        {
-           throw InvalidConfigdataException();
+           SN_THROW(InvalidConfigdataException());
        }
     }
 
@@ -90,7 +90,7 @@ namespace snapper
        }
        catch (const FileNotFoundException& e)
        {
-           throw ConfigNotFoundException();
+           SN_THROW(ConfigNotFoundException());
        }
 
        filesystem = Filesystem::create(*config_info, root_prefix);
@@ -193,7 +193,7 @@ namespace snapper
     Snapper::createSingleSnapshot(Snapshots::const_iterator parent, const SCD& scd)
     {
        if (parent == snapshots.end())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        return snapshots.createSingleSnapshot(parent, scd);
     }
@@ -273,7 +273,7 @@ namespace snapper
        }
        catch (const FileNotFoundException& e)
        {
-           throw ListConfigsFailedException("sysconfig-file not found");
+           SN_THROW(ListConfigsFailedException("sysconfig-file not found"));
        }
 
        return config_infos;
@@ -292,12 +292,12 @@ namespace snapper
 
        if (config_name.empty() || config_name.find_first_of(", \t") != string::npos)
        {
-           throw CreateConfigFailedException("illegal config name");
+           SN_THROW(CreateConfigFailedException("illegal config name"));
        }
 
        if (!boost::starts_with(subvolume, "/") || !checkDir(subvolume))
        {
-           throw CreateConfigFailedException("illegal subvolume");
+           SN_THROW(CreateConfigFailedException("illegal subvolume"));
        }
 
        list<ConfigInfo> configs = getConfigs(root_prefix);
@@ -305,13 +305,13 @@ namespace snapper
        {
            if (it->getSubvolume() == subvolume)
            {
-               throw CreateConfigFailedException("subvolume already covered");
+               SN_THROW(CreateConfigFailedException("subvolume already covered"));
            }
        }
 
        if (access(string(CONFIGTEMPLATEDIR "/" + template_name).c_str(), R_OK) != 0)
        {
-           throw CreateConfigFailedException("cannot access template config");
+           SN_THROW(CreateConfigFailedException("cannot access template config"));
        }
 
        unique_ptr<Filesystem> filesystem;
@@ -321,11 +321,11 @@ namespace snapper
        }
        catch (const InvalidConfigException& e)
        {
-           throw CreateConfigFailedException("invalid filesystem type");
+           SN_THROW(CreateConfigFailedException("invalid filesystem type"));
        }
        catch (const ProgramNotInstalledException& e)
        {
-           throw CreateConfigFailedException(e.what());
+           SN_THROW(CreateConfigFailedException(e.what()));
        }
 
        try
@@ -335,7 +335,7 @@ namespace snapper
            sysconfig.getValue("SNAPPER_CONFIGS", config_names);
            if (find(config_names.begin(), config_names.end(), config_name) != config_names.end())
            {
-               throw CreateConfigFailedException("config already exists");
+               SN_THROW(CreateConfigFailedException("config already exists"));
            }
 
            config_names.push_back(config_name);
@@ -343,7 +343,7 @@ namespace snapper
        }
        catch (const FileNotFoundException& e)
        {
-           throw CreateConfigFailedException("sysconfig-file not found");
+           SN_THROW(CreateConfigFailedException("sysconfig-file not found"));
        }
 
        try
@@ -357,15 +357,17 @@ namespace snapper
        }
        catch (const FileNotFoundException& e)
        {
-           throw CreateConfigFailedException("modifying config failed");
+           SN_THROW(CreateConfigFailedException("modifying config failed"));
        }
 
        try
        {
            filesystem->createConfig();
        }
-       catch (...)
+       catch (const Exception& e)
        {
+           SN_CAUGHT(e);
+
            SysconfigFile sysconfig(SYSCONFIGFILE);
            vector<string> config_names;
            sysconfig.getValue("SNAPPER_CONFIGS", config_names);
@@ -375,7 +377,7 @@ namespace snapper
 
            SystemCmd cmd(RMBIN " " + quote(CONFIGSDIR "/" + config_name));
 
-           throw;
+           SN_RETHROW(e);
        }
 
        Hooks::create_config(subvolume, filesystem.get());
@@ -416,13 +418,13 @@ namespace snapper
        }
        catch (const DeleteConfigFailedException& e)
        {
-           throw DeleteConfigFailedException("deleting snapshot failed");
+           SN_THROW(DeleteConfigFailedException("deleting snapshot failed"));
        }
 
        SystemCmd cmd1(RMBIN " " + quote(CONFIGSDIR "/" + config_name));
        if (cmd1.retcode() != 0)
        {
-           throw DeleteConfigFailedException("deleting config-file failed");
+           SN_THROW(DeleteConfigFailedException("deleting config-file failed"));
        }
 
        try
@@ -436,7 +438,7 @@ namespace snapper
        }
        catch (const FileNotFoundException& e)
        {
-           throw DeleteConfigFailedException("sysconfig-file not found");
+           SN_THROW(DeleteConfigFailedException("sysconfig-file not found"));
        }
     }
 
@@ -470,7 +472,7 @@ namespace snapper
            {
                uid_t uid;
                if (!get_user_uid(it->c_str(), uid))
-                   throw InvalidUserException();
+                   SN_THROW(InvalidUserException());
                uids.push_back(uid);
            }
        }
@@ -483,7 +485,7 @@ namespace snapper
            {
                gid_t gid;
                if (!get_group_gid(it->c_str(), gid))
-                   throw InvalidGroupException();
+                   SN_THROW(InvalidGroupException());
                gids.push_back(gid);
            }
        }
@@ -504,11 +506,11 @@ namespace snapper
     {
        acl_permset_t permset;
        if (acl_get_permset(entry, &permset) != 0)
-           throw AclException();
+           SN_THROW(AclException());
 
        if (acl_add_perm(permset, ACL_READ) != 0 || acl_delete_perm(permset, ACL_WRITE) != 0 ||
            acl_add_perm(permset, ACL_EXECUTE) != 0)
-           throw AclException();
+           SN_THROW(AclException());
     };
 
 
@@ -517,13 +519,13 @@ namespace snapper
     {
        acl_entry_t entry;
        if (acl_create_entry(acl, &entry) != 0)
-           throw AclException();
+           SN_THROW(AclException());
 
        if (acl_set_tag_type(entry, tag) != 0)
-           throw AclException();
+           SN_THROW(AclException());
 
        if (acl_set_qualifier(entry, qualifier) != 0)
-           throw AclException();
+           SN_THROW(AclException());
 
        set_acl_permissions(entry);
     };
@@ -536,11 +538,11 @@ namespace snapper
 
        acl_t orig_acl = acl_get_fd(infos_dir.fd());
        if (!orig_acl)
-           throw AclException();
+           SN_THROW(AclException());
 
        acl_t acl = acl_dup(orig_acl);
        if (!acl)
-           throw AclException();
+           SN_THROW(AclException());
 
        set<uid_t> remaining_uids = set<uid_t>(uids.begin(), uids.end());
        set<gid_t> remaining_gids = set<gid_t>(gids.begin(), gids.end());
@@ -552,7 +554,7 @@ namespace snapper
 
                acl_tag_t tag;
                if (acl_get_tag_type(entry, &tag) != 0)
-                   throw AclException();
+                   SN_THROW(AclException());
 
                switch (tag)
                {
@@ -560,7 +562,7 @@ namespace snapper
 
                        uid_t* uid = (uid_t*) acl_get_qualifier(entry);
                        if (!uid)
-                           throw AclException();
+                           SN_THROW(AclException());
 
                        if (contains(remaining_uids, *uid))
                        {
@@ -571,7 +573,7 @@ namespace snapper
                        else
                        {
                            if (acl_delete_entry(acl, entry) != 0)
-                               throw AclException();
+                               SN_THROW(AclException());
                        }
 
                    } break;
@@ -580,7 +582,7 @@ namespace snapper
 
                        gid_t* gid = (gid_t*) acl_get_qualifier(entry);
                        if (!gid)
-                           throw AclException();
+                           SN_THROW(AclException());
 
                        if (contains(remaining_gids, *gid))
                        {
@@ -591,7 +593,7 @@ namespace snapper
                        else
                        {
                            if (acl_delete_entry(acl, entry) != 0)
-                               throw AclException();
+                               SN_THROW(AclException());
                        }
 
                    } break;
@@ -612,14 +614,14 @@ namespace snapper
        }
 
        if (acl_calc_mask(&acl) != 0)
-           throw AclException();
+           SN_THROW(AclException());
 
        if (acl_cmp(orig_acl, acl) == 1)
            if (acl_set_fd(infos_dir.fd(), acl) != 0)
-               throw AclException();
+               SN_THROW(AclException());
 
        if (acl_free(acl) != 0)
-           throw AclException();
+           SN_THROW(AclException());
     }
 
 
index 4b96e8d7f8371bf21dcfec2390968c2b605c3a9e..2e597dfc37a7407b7cdf99c8146ef5cf77cd116b 100644 (file)
@@ -105,7 +105,7 @@ namespace snapper
     Snapshot::openInfoDir() const
     {
        if (isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        SDir infos_dir = snapper->openInfosDir();
        return SDir(infos_dir, decString(num));
@@ -287,10 +287,10 @@ namespace snapper
        for (map<string, string>::const_iterator it = userdata.begin(); it != userdata.end(); ++it)
        {
            if (it->first.empty() || it->first.find_first_of(",=") != string::npos)
-               throw InvalidUserdataException();
+               SN_THROW(InvalidUserdataException());
 
            if (it->second.find_first_of(",=") != string::npos)
-               throw InvalidUserdataException();
+               SN_THROW(InvalidUserdataException());
        }
     }
 
@@ -321,7 +321,7 @@ namespace snapper
     Snapshots::findPost(const_iterator pre)
     {
        if (pre == entries.end() || pre->isCurrent() || pre->getType() != PRE)
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        for (iterator it = begin(); it != end(); ++it)
        {
@@ -337,7 +337,7 @@ namespace snapper
     Snapshots::findPost(const_iterator pre) const
     {
        if (pre == entries.end() || pre->isCurrent() || pre->getType() != PRE)
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        for (const_iterator it = begin(); it != end(); ++it)
        {
@@ -353,7 +353,7 @@ namespace snapper
     Snapshots::findPre(const_iterator post)
     {
        if (post == entries.end() || post->isCurrent() || post->getType() != POST)
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        return find(post->pre_num);
     }
@@ -363,7 +363,7 @@ namespace snapper
     Snapshots::findPre(const_iterator post) const
     {
        if (post == entries.end() || post->isCurrent() || post->getType() != POST)
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        return find(post->pre_num);
     }
@@ -389,8 +389,8 @@ namespace snapper
            if (errno == EEXIST)
                continue;
 
-           throw IOErrorException(sformat("mkdir failed errno:%d (%s)", errno,
-                                          stringerror(errno).c_str()));
+           SN_THROW(IOErrorException(sformat("mkdir failed errno:%d (%s)", errno,
+                                             stringerror(errno).c_str())));
        }
 
        infos_dir.chmod(decString(num), 0755, 0);
@@ -439,9 +439,9 @@ namespace snapper
        xml.save(info_dir.mktemp(tmp_name));
 
        if (info_dir.rename(tmp_name, file_name) != 0)
-           throw IOErrorException(sformat("rename info.xml failed infoDir:%s errno:%d (%s)",
-                                          info_dir.fullname().c_str(), errno,
-                                          stringerror(errno).c_str()));
+           SN_THROW(IOErrorException(sformat("rename info.xml failed infoDir:%s errno:%d (%s)",
+                                             info_dir.fullname().c_str(), errno,
+                                             stringerror(errno).c_str())));
     }
 
 
@@ -449,7 +449,7 @@ namespace snapper
     Snapshot::mountFilesystemSnapshot(bool user_request) const
     {
        if (isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        if (!mount_checked)
        {
@@ -470,7 +470,7 @@ namespace snapper
     Snapshot::umountFilesystemSnapshot(bool user_request) const
     {
        if (isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        if (!mount_checked)
        {
@@ -503,7 +503,7 @@ namespace snapper
     Snapshot::createFilesystemSnapshot(unsigned int num_parent, bool read_only) const
     {
        if (isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        snapper->getFilesystem()->createSnapshot(num, num_parent, read_only);
     }
@@ -513,7 +513,7 @@ namespace snapper
     Snapshot::createFilesystemSnapshotOfDefault(bool read_only) const
     {
        if (isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        snapper->getFilesystem()->createSnapshotOfDefault(num, read_only);
     }
@@ -523,7 +523,7 @@ namespace snapper
     Snapshot::deleteFilesystemSnapshot() const
     {
        if (isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        snapper->getFilesystem()->umountSnapshot(num);
        snapper->getFilesystem()->deleteSnapshot(num);
@@ -595,7 +595,7 @@ namespace snapper
     {
        if (pre == entries.end() || pre->isCurrent() || pre->getType() != PRE ||
            findPost(pre) != entries.end())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        checkUserdata(scd.userdata);
 
@@ -625,9 +625,12 @@ namespace snapper
        }
        catch (const CreateSnapshotFailedException& e)
        {
+           SN_CAUGHT(e);
+
            SDir infos_dir = snapper->openInfosDir();
            infos_dir.unlink(decString(snapshot.getNum()), AT_REMOVEDIR);
-           throw;
+
+           SN_RETHROW(e);
        }
 
        try
@@ -636,10 +639,13 @@ namespace snapper
        }
        catch (const IOErrorException& e)
        {
+           SN_CAUGHT(e);
+
            snapshot.deleteFilesystemSnapshot();
            SDir infos_dir = snapper->openInfosDir();
            infos_dir.unlink(decString(snapshot.getNum()), AT_REMOVEDIR);
-           throw;
+
+           SN_RETHROW(e);
        }
 
        Hooks::create_snapshot(snapper->subvolumeDir(), snapper->getFilesystem());
@@ -659,7 +665,7 @@ namespace snapper
     Snapshots::modifySnapshot(iterator snapshot, const SMD& smd)
     {
        if (snapshot == entries.end() || snapshot->isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        checkUserdata(smd.userdata);
 
@@ -677,7 +683,7 @@ namespace snapper
     Snapshots::deleteSnapshot(iterator snapshot)
     {
        if (snapshot == entries.end() || snapshot->isCurrent())
-           throw IllegalSnapshotException();
+           SN_THROW(IllegalSnapshotException());
 
        snapshot->deleteFilesystemSnapshot();
 
index ccb8509af6fe1dcc5fbe8b39b2d3753f29ed2990..266ed2b9255295d303cc02bcfe14df453dfd777a 100644 (file)
@@ -84,7 +84,7 @@ namespace snapper
         {
             y2err("Couldn't get xattributes names-list size. link: " << path
                  << ", error: " << stringerror(errno));
-            throw XAttributesException();
+            SN_THROW(XAttributesException());
         }
 
         y2deb("XAttributes names-list size is: " << size);
@@ -99,7 +99,7 @@ namespace snapper
         {
             y2err("Couldn't get xattributes names-list. link: " << path <<
                  ", error: " << stringerror(errno));
-            throw XAttributesException();
+            SN_THROW(XAttributesException());
         }
 
        ssize_t pos = 0;
@@ -115,7 +115,7 @@ namespace snapper
             {
                 y2err("Couldn't get a xattribute value size for the xattribute name '" << name
                      << "': " << stringerror(errno));
-                throw XAttributesException();
+                SN_THROW(XAttributesException());
             }
 
             y2deb("XAttribute value size for xattribute name: '" << name << "' is " << v_size);
@@ -128,14 +128,14 @@ namespace snapper
                if (v_size < 0)
                {
                    y2err("Couldn't get xattribute value for the xattribute name '" << name << "': ");
-                   throw XAttributesException();
+                   SN_THROW(XAttributesException());
                }
            }
 
            if (!xamap.insert(make_pair(name, xa_value_t(buffer.get(), buffer.get() + v_size))).second)
            {
                y2err("Duplicite extended attribute name in source file!");
-               throw XAttributesException();
+               SN_THROW(XAttributesException());
            }
        }
 
@@ -152,7 +152,7 @@ namespace snapper
        {
            y2err("Couldn't get xattributes names-list size. link: " << file.fullname(true) <<
                  ", error: " << stringerror(errno));
-           throw XAttributesException();
+           SN_THROW(XAttributesException());
        }
 
        y2deb("XAttributes names-list size is: " << size);
@@ -167,7 +167,7 @@ namespace snapper
        {
            y2err("Couldn't get xattributes names-list. link: " << file.fullname(true) <<
                  ", error: " << stringerror(errno));
-           throw XAttributesException();
+           SN_THROW(XAttributesException());
        }
 
        ssize_t pos = 0;
@@ -182,7 +182,7 @@ namespace snapper
            {
                y2err("Couldn't get a xattribute value size for the xattribute name '" <<
                      name << "': " << stringerror(errno));
-               throw XAttributesException();
+               SN_THROW(XAttributesException());
            }
 
            y2deb("XAttribute value size for xattribute name: '" << name << "' is " << v_size);
@@ -195,14 +195,14 @@ namespace snapper
                if (v_size < 0)
                {
                    y2err("Couldn't get xattribute value for the xattribute name '" << name << "': ");
-                   throw XAttributesException();
+                   SN_THROW(XAttributesException());
                }
            }
 
            if (!xamap.insert(make_pair(name, xa_value_t(buffer.get(), buffer.get() + v_size))).second)
            {
                y2err("Duplicite extended attribute name in source file!");
-               throw XAttributesException();
+               SN_THROW(XAttributesException());
            }
        }