From c156266bd8a11336c3f5d62b56bfa850a0a64d0b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 12 Dec 2018 13:16:12 -0800 Subject: [PATCH] ircd::fs: Simplify error handling. --- ircd/fs.cc | 158 ++++++++++------------------------------------------- 1 file changed, 30 insertions(+), 128 deletions(-) diff --git a/ircd/fs.cc b/ircd/fs.cc index e606a42dc..3719a87f8 100644 --- a/ircd/fs.cc +++ b/ircd/fs.cc @@ -245,9 +245,14 @@ catch(const filesystem::filesystem_error &e) size_t ircd::fs::size(const string_view &path) +try { return filesystem::file_size(fs::path(path)); } +catch(const filesystem::filesystem_error &e) +{ + throw error{e}; +} bool ircd::fs::is_reg(const string_view &path) @@ -284,6 +289,7 @@ catch(const filesystem::filesystem_error &e) std::string ircd::fs::make_path(const vector_view &list) +try { filesystem::path ret; for(const auto &s : list) @@ -291,9 +297,14 @@ ircd::fs::make_path(const vector_view &list) return ret.string(); } +catch(const filesystem::filesystem_error &e) +{ + throw error{e}; +} std::string ircd::fs::make_path(const vector_view &list) +try { filesystem::path ret; for(const auto &s : list) @@ -301,9 +312,14 @@ ircd::fs::make_path(const vector_view &list) return ret.string(); } +catch(const filesystem::filesystem_error &e) +{ + throw error{e}; +} filesystem::path ircd::fs::path(const vector_view &list) +try { filesystem::path ret; for(const auto &s : list) @@ -311,18 +327,32 @@ ircd::fs::path(const vector_view &list) return ret.string(); } +catch(const filesystem::filesystem_error &e) +{ + throw error{e}; +} filesystem::path ircd::fs::path(const string_view &s) +try { return path(std::string{s}); } +catch(const filesystem::filesystem_error &e) +{ + throw error{e}; +} filesystem::path ircd::fs::path(std::string s) +try { return filesystem::path(std::move(s)); } +catch(const filesystem::filesystem_error &e) +{ + throw error{e}; +} /////////////////////////////////////////////////////////////////////////////// // @@ -491,7 +521,6 @@ const ircd::fs::fsync_opts_default; void ircd::fs::fsync(const fd &fd, const fsync_opts &opts) -try { #ifdef IRCD_USE_AIO if(aio::context && opts.async && support::aio_fsync) @@ -500,26 +529,10 @@ try syscall(::fsync, fd); } -catch(const error &e) -{ - throw; -} -catch(const filesystem::filesystem_error &e) -{ - throw error{e}; -} -catch(const std::exception &e) -{ - throw error - { - "%s", e.what() - }; -} void ircd::fs::fdsync(const fd &fd, const fsync_opts &opts) -try { #ifdef IRCD_USE_AIO if(aio::context && opts.async && support::aio_fdsync) @@ -528,21 +541,6 @@ try syscall(::fdatasync, fd); } -catch(const error &e) -{ - throw; -} -catch(const filesystem::filesystem_error &e) -{ - throw error{e}; -} -catch(const std::exception &e) -{ - throw error - { - "%s", e.what() - }; -} /////////////////////////////////////////////////////////////////////////////// // @@ -592,7 +590,6 @@ ircd::fs::prefetch(const fd &fd, std::string ircd::fs::read(const string_view &path, const read_opts &opts) -try { const fd fd { @@ -601,21 +598,6 @@ try return read(fd, opts); } -catch(const error &e) -{ - throw; -} -catch(const filesystem::filesystem_error &e) -{ - throw error{e}; -} -catch(const std::exception &e) -{ - throw error - { - "%s", e.what() - }; -} std::string ircd::fs::read(const fd &fd, @@ -664,7 +646,6 @@ size_t ircd::fs::read(const string_view &path, const mutable_buffers &bufs, const read_opts &opts) -try { const fd fd { @@ -673,27 +654,11 @@ try return read(fd, bufs, opts); } -catch(const error &e) -{ - throw; -} -catch(const filesystem::filesystem_error &e) -{ - throw error{e}; -} -catch(const std::exception &e) -{ - throw error - { - "%s", e.what() - }; -} size_t ircd::fs::read(const fd &fd, const mutable_buffers &bufs, const read_opts &opts) -try { #ifdef IRCD_USE_AIO if(likely(aio::context)) @@ -703,21 +668,6 @@ try const auto iov(make_iov(bufs)); return size_t(syscall(::preadv, fd, iov.data(), iov.size(), opts.offset)); } -catch(const error &e) -{ - throw; -} -catch(const filesystem::filesystem_error &e) -{ - throw error{e}; -} -catch(const std::exception &e) -{ - throw error - { - "%s", e.what() - }; -} /////////////////////////////////////////////////////////////////////////////// // @@ -861,7 +811,6 @@ size_t ircd::fs::append(const fd &fd, const const_buffers &bufs, const write_opts &opts_) -try { auto opts(opts_); if(!opts.offset) @@ -869,21 +818,6 @@ try return write(fd, bufs, opts); } -catch(const error &e) -{ - throw; -} -catch(const filesystem::filesystem_error &e) -{ - throw error{e}; -} -catch(const std::exception &e) -{ - throw error - { - "%s", e.what() - }; -} ircd::const_buffer ircd::fs::write(const string_view &path, @@ -921,7 +855,6 @@ size_t ircd::fs::write(const string_view &path, const const_buffers &bufs, const write_opts &opts) -try { const fd fd { @@ -930,27 +863,11 @@ try return write(fd, bufs, opts); } -catch(const error &e) -{ - throw; -} -catch(const filesystem::filesystem_error &e) -{ - throw error{e}; -} -catch(const std::exception &e) -{ - throw error - { - "%s", e.what() - }; -} size_t ircd::fs::write(const fd &fd, const const_buffers &bufs, const write_opts &opts) -try { #ifdef IRCD_USE_AIO if(likely(aio::context)) @@ -960,21 +877,6 @@ try const auto iov(make_iov(bufs)); return size_t(syscall(::pwritev, fd, iov.data(), iov.size(), opts.offset)); } -catch(const error &e) -{ - throw; -} -catch(const filesystem::filesystem_error &e) -{ - throw error{e}; -} -catch(const std::exception &e) -{ - throw error - { - "%s", e.what() - }; -} /////////////////////////////////////////////////////////////////////////////// //