Kagome
Polkadot Runtime Engine in C++17
util.cpp
Go to the documentation of this file.
1 
7 
8 #define UNWRAP_ERROR_CODE(ec) \
9  { \
10  if (ec) { \
11  return (ec); \
12  } \
13  }
14 
17  switch (e) {
18  case E::FAILED_TO_CREATE_DIR:
19  return "Failed to create directory";
20  case E::NOT_A_DIR:
21  return "File already exists, but it's not a directory";
22  }
23  return "Unknown application::util error";
24 }
25 
27 
28  namespace fs = boost::filesystem;
29 
30  outcome::result<void> init_directory(const boost::filesystem::path &path) {
31  // init chain directory in base path
32  boost::system::error_code ec{};
33  if (not fs::exists(path, ec)) {
35  if (not fs::create_directory(path, ec)) {
37  }
39  } else {
40  if (not fs::is_directory(path, ec)) {
41  return Error::NOT_A_DIR;
42  }
44  }
45  return outcome::success();
46  }
47 
48 } // namespace kagome::application::util
#define UNWRAP_ERROR_CODE(ec)
Definition: util.cpp:8
OUTCOME_CPP_DEFINE_CATEGORY(kagome::application::util, Error, e)
Definition: util.cpp:15
outcome::result< void > init_directory(const boost::filesystem::path &path)
Definition: util.cpp:30