]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/filesystem/src/exception.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / filesystem / src / exception.cpp
CommitLineData
92f5a8d4
TL
1// boost/filesystem/exception.hpp -----------------------------------------------------//
2
3// Copyright Beman Dawes 2003
4// Copyright Andrey Semashev 2019
5
6// Distributed under the Boost Software License, Version 1.0.
7// See http://www.boost.org/LICENSE_1_0.txt
8
9// Library home page: http://www.boost.org/libs/filesystem
10
20effc67
TL
11#include "platform_config.hpp"
12
92f5a8d4 13#include <string>
1e59de90
TL
14#include <boost/system/error_code.hpp>
15#include <boost/system/system_category.hpp>
92f5a8d4
TL
16#include <boost/filesystem/config.hpp>
17#include <boost/filesystem/path.hpp>
18#include <boost/filesystem/exception.hpp>
19
20#include "error_handling.hpp"
21
22#include <boost/config/abi_prefix.hpp> // must be the last #include
23
24namespace boost {
25namespace filesystem {
26
1e59de90
TL
27BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const char* what_arg, system::error_code ec) :
28 system::system_error(ec, what_arg)
92f5a8d4 29{
1e59de90
TL
30 try
31 {
32 m_imp_ptr.reset(new impl());
33 }
34 catch (...)
35 {
36 m_imp_ptr.reset();
37 }
38}
39
40BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(std::string const& what_arg, system::error_code ec) :
41 system::system_error(ec, what_arg)
42{
43 try
44 {
45 m_imp_ptr.reset(new impl());
46 }
47 catch (...)
48 {
49 m_imp_ptr.reset();
50 }
51}
52
53BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const char* what_arg, path const& path1_arg, system::error_code ec) :
54 system::system_error(ec, what_arg)
55{
56 try
57 {
58 m_imp_ptr.reset(new impl(path1_arg));
59 }
60 catch (...)
61 {
62 m_imp_ptr.reset();
63 }
92f5a8d4
TL
64}
65
1e59de90
TL
66BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(std::string const& what_arg, path const& path1_arg, system::error_code ec) :
67 system::system_error(ec, what_arg)
92f5a8d4 68{
1e59de90
TL
69 try
70 {
71 m_imp_ptr.reset(new impl(path1_arg));
72 }
73 catch (...)
74 {
75 m_imp_ptr.reset();
76 }
77}
78
79BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const char* what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec) :
80 system::system_error(ec, what_arg)
81{
82 try
83 {
84 m_imp_ptr.reset(new impl(path1_arg, path2_arg));
85 }
86 catch (...)
87 {
88 m_imp_ptr.reset();
89 }
92f5a8d4
TL
90}
91
1e59de90
TL
92BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(std::string const& what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec) :
93 system::system_error(ec, what_arg)
92f5a8d4 94{
1e59de90
TL
95 try
96 {
97 m_imp_ptr.reset(new impl(path1_arg, path2_arg));
98 }
99 catch (...)
100 {
101 m_imp_ptr.reset();
102 }
92f5a8d4
TL
103}
104
1e59de90
TL
105BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(filesystem_error const& that) :
106 system::system_error(static_cast< system::system_error const& >(that)),
107 m_imp_ptr(that.m_imp_ptr)
92f5a8d4
TL
108{
109}
110
1e59de90 111BOOST_FILESYSTEM_DECL filesystem_error& filesystem_error::operator=(filesystem_error const& that)
92f5a8d4 112{
1e59de90
TL
113 static_cast< system::system_error& >(*this) = static_cast< system::system_error const& >(that);
114 m_imp_ptr = that.m_imp_ptr;
115 return *this;
92f5a8d4
TL
116}
117
1e59de90 118BOOST_FILESYSTEM_DECL filesystem_error::~filesystem_error() BOOST_NOEXCEPT_OR_NOTHROW
92f5a8d4
TL
119{
120}
121
1e59de90 122BOOST_FILESYSTEM_DECL const char* filesystem_error::what() const BOOST_NOEXCEPT_OR_NOTHROW
92f5a8d4 123{
1e59de90 124 if (m_imp_ptr.get()) try
92f5a8d4 125 {
1e59de90
TL
126 if (m_imp_ptr->m_what.empty())
127 {
128 m_imp_ptr->m_what = system::system_error::what();
129 if (!m_imp_ptr->m_path1.empty())
130 {
131 m_imp_ptr->m_what += ": \"";
132 m_imp_ptr->m_what += m_imp_ptr->m_path1.string();
133 m_imp_ptr->m_what += "\"";
134 }
135 if (!m_imp_ptr->m_path2.empty())
136 {
137 m_imp_ptr->m_what += ", \"";
138 m_imp_ptr->m_what += m_imp_ptr->m_path2.string();
139 m_imp_ptr->m_what += "\"";
140 }
141 }
142
143 return m_imp_ptr->m_what.c_str();
144 }
145 catch (...)
146 {
147 m_imp_ptr->m_what.clear();
92f5a8d4
TL
148 }
149
1e59de90 150 return system::system_error::what();
92f5a8d4
TL
151}
152
1e59de90 153BOOST_FILESYSTEM_DECL path const& filesystem_error::get_empty_path() BOOST_NOEXCEPT
92f5a8d4 154{
1e59de90
TL
155 static const path empty_path;
156 return empty_path;
92f5a8d4
TL
157}
158
159// error handling helpers declared in error_handling.hpp -----------------------------------------------------//
160
161void emit_error(err_t error_num, system::error_code* ec, const char* message)
162{
1e59de90
TL
163 if (!ec)
164 BOOST_FILESYSTEM_THROW(filesystem_error(message, system::error_code(error_num, system::system_category())));
165 else
166 ec->assign(error_num, system::system_category());
92f5a8d4
TL
167}
168
1e59de90 169void emit_error(err_t error_num, path const& p, system::error_code* ec, const char* message)
92f5a8d4 170{
1e59de90
TL
171 if (!ec)
172 BOOST_FILESYSTEM_THROW(filesystem_error(message, p, system::error_code(error_num, system::system_category())));
173 else
174 ec->assign(error_num, system::system_category());
92f5a8d4
TL
175}
176
1e59de90 177void emit_error(err_t error_num, path const& p1, path const& p2, system::error_code* ec, const char* message)
92f5a8d4 178{
1e59de90
TL
179 if (!ec)
180 BOOST_FILESYSTEM_THROW(filesystem_error(message, p1, p2, system::error_code(error_num, system::system_category())));
181 else
182 ec->assign(error_num, system::system_category());
92f5a8d4
TL
183}
184
185} // namespace filesystem
186} // namespace boost
187
188#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas