From: Arvin Schnell Date: Wed, 30 Mar 2016 14:09:26 +0000 (+0200) Subject: - use exception macros X-Git-Tag: v0.3.3~16^2~4 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=f33db456ec166eb04d6825c21d8d35985d0636fd;p=thirdparty%2Fsnapper.git - use exception macros --- diff --git a/snapper/Acls.cc b/snapper/Acls.cc index e81a191d..cfd2cc58 100644 --- a/snapper/Acls.cc +++ b/snapper/Acls.cc @@ -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()); } } } diff --git a/snapper/AsciiFile.cc b/snapper/AsciiFile.cc index f08a8d17..04714ab9 100644 --- a/snapper/AsciiFile.cc +++ b/snapper/AsciiFile.cc @@ -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()); } diff --git a/snapper/Btrfs.cc b/snapper/Btrfs.cc index 50570c5e..de01c577 100644 --- a/snapper/Btrfs.cc +++ b/snapper/Btrfs.cc @@ -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 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())); } } diff --git a/snapper/Compare.cc b/snapper/Compare.cc index ce68b7f0..2119e04c 100644 --- a/snapper/Compare.cc +++ b/snapper/Compare.cc @@ -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; diff --git a/snapper/Comparison.cc b/snapper/Comparison.cc index 8a2a2d73..5f39efe3 100644 --- a/snapper/Comparison.cc +++ b/snapper/Comparison.cc @@ -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); } diff --git a/snapper/FileUtils.cc b/snapper/FileUtils.cc index ec8d8cc2..19ffb57b 100644 --- a/snapper/FileUtils.cc +++ b/snapper/FileUtils.cc @@ -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 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 diff --git a/snapper/Filesystem.cc b/snapper/Filesystem.cc index 045cb83a..98a2bcb1 100644 --- a/snapper/Filesystem.cc +++ b/snapper/Filesystem.cc @@ -117,7 +117,8 @@ namespace snapper } y2err("do not know about fstype '" << fstype << "'"); - throw InvalidConfigException(); + SN_THROW(InvalidConfigException()); + __builtin_unreachable(); } diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index c17e0188..2fa5c91e 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -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 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; @@ -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 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 remaining_uids = set(uids.begin(), uids.end()); set remaining_gids = set(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()); } diff --git a/snapper/Snapshot.cc b/snapper/Snapshot.cc index 4b96e8d7..2e597dfc 100644 --- a/snapper/Snapshot.cc +++ b/snapper/Snapshot.cc @@ -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::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(); diff --git a/snapper/XAttributes.cc b/snapper/XAttributes.cc index ccb8509a..266ed2b9 100644 --- a/snapper/XAttributes.cc +++ b/snapper/XAttributes.cc @@ -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()); } }