2018-08-23 12:31:36 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_FS_ERROR_H
|
|
|
|
|
|
|
|
// Forward declarations for boost
|
|
|
|
namespace boost::filesystem
|
|
|
|
{
|
|
|
|
struct filesystem_error;
|
|
|
|
}
|
|
|
|
|
2019-03-17 01:21:42 +01:00
|
|
|
namespace ircd::fs
|
2018-08-23 12:31:36 +02:00
|
|
|
{
|
2019-03-17 01:21:42 +01:00
|
|
|
struct error; // does not participate in ircd::exception hierarchy
|
|
|
|
}
|
2018-08-23 12:31:36 +02:00
|
|
|
|
2019-03-17 01:21:42 +01:00
|
|
|
namespace ircd
|
|
|
|
{
|
2018-08-23 12:31:36 +02:00
|
|
|
std::error_code make_error_code(const boost::filesystem::filesystem_error &);
|
2019-03-17 01:21:42 +01:00
|
|
|
std::system_error make_system_error(const boost::filesystem::filesystem_error &);
|
|
|
|
|
|
|
|
string_view string(const mutable_buffer &, const boost::filesystem::filesystem_error &);
|
|
|
|
std::string string(const boost::filesystem::filesystem_error &);
|
2018-08-23 12:31:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ircd::fs::error
|
2018-12-13 02:19:49 +01:00
|
|
|
:std::system_error
|
2018-08-23 12:31:36 +02:00
|
|
|
{
|
2019-03-17 01:21:42 +01:00
|
|
|
static thread_local char buf[1024];
|
2018-08-23 12:31:36 +02:00
|
|
|
|
2019-03-17 01:21:42 +01:00
|
|
|
public:
|
2018-08-23 12:31:36 +02:00
|
|
|
template<class... args>
|
2019-03-17 01:21:42 +01:00
|
|
|
error(const boost::filesystem::filesystem_error &e,
|
2018-12-24 22:34:23 +01:00
|
|
|
const string_view &fmt,
|
2018-08-23 12:31:36 +02:00
|
|
|
args&&...);
|
|
|
|
|
|
|
|
template<class... args>
|
2019-03-17 01:21:42 +01:00
|
|
|
error(const std::error_code &e,
|
2018-12-24 22:34:23 +01:00
|
|
|
const string_view &fmt,
|
2018-08-23 12:31:36 +02:00
|
|
|
args&&...);
|
|
|
|
|
2019-03-17 01:21:42 +01:00
|
|
|
error(const boost::filesystem::filesystem_error &e);
|
2018-08-23 12:31:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class... args>
|
|
|
|
ircd::fs::error::error(const boost::filesystem::filesystem_error &e,
|
2018-12-24 22:34:23 +01:00
|
|
|
const string_view &fmt,
|
2018-08-25 00:44:00 +02:00
|
|
|
args&&... a)
|
2018-08-23 12:31:36 +02:00
|
|
|
:error
|
|
|
|
{
|
|
|
|
make_error_code(e), fmt, std::forward<args>(a)...
|
|
|
|
}
|
2018-12-16 05:12:39 +01:00
|
|
|
{}
|
2018-08-23 12:31:36 +02:00
|
|
|
|
|
|
|
template<class... args>
|
|
|
|
ircd::fs::error::error(const std::error_code &e,
|
2018-12-24 22:34:23 +01:00
|
|
|
const string_view &fmt,
|
2018-08-25 00:44:00 +02:00
|
|
|
args&&... a)
|
2019-03-17 01:21:42 +01:00
|
|
|
:std::system_error{[&]
|
|
|
|
() -> std::system_error
|
2018-08-23 12:31:36 +02:00
|
|
|
{
|
2019-03-17 01:21:42 +01:00
|
|
|
fmt::sprintf{buf, fmt, std::forward<args>(a)...};
|
|
|
|
return {e, buf};
|
|
|
|
}()}
|
2018-12-16 05:12:39 +01:00
|
|
|
{}
|