TF++, Miscellaneous classes and modules in C++:

◆ mkdirp()

void tfxx::fs::mkdirp ( const std::string &  path)

create a directory with all parents

C++ interface to mkdir(2)

Definition at line 44 of file mkdirp.cc.

References dirname(), tfxx::error::Exception::dont_report_on_construct(), tfxx::error::FSException::iserrno(), mkdir(), tfxx::error::FSException::report(), tfxx::error::Exception::report(), and tfxx::error::Exception::restore_report_state().

Referenced by main().

45  {
47  try {
48  tfxx::fs::mkdir(path);
49  } catch (const tfxx::error::FSException& e) {
50  if (!e.iserrno(ENOENT))
51  {
52  e.report();
53  throw(e);
54  }
55  std::string dir=tfxx::fs::dirname(path);
56  if (dir == path)
57  {
58  e.report();
59  throw(e);
60  }
61  else
62  {
63  // std::cerr << "going to create " << dir << std::endl;
64  tfxx::fs::mkdirp(dir);
65  // std::cerr << "retry to create " << path << std::endl;
66  tfxx::fs::mkdir(path);
67  }
68  } catch (tfxx::error::Exception& e) {
69  e.report();
70  throw(e);
71  }
73  } // void mkdirp(const std::string& path)
bool iserrno(const int &en) const
true, if exception reports error en
Definition: fs.h:87
std::string dirname(const std::string &path)
return path with its last non-slash component removed
Definition: dirname.cc:45
exception class for file system utilities
Definition: fs.h:72
virtual void report() const
Screen report.
Definition: exception.cc:56
static void restore_report_state()
Restore previous report state.
Definition: error.cc:98
static void dont_report_on_construct()
Issue NO screen report on construction of exception.
Definition: error.cc:91
Base class for exceptions.
Definition: error.h:78
void mkdirp(const std::string &path)
create a directory with all parents
Definition: mkdirp.cc:44
virtual void report() const
Screen report.
Definition: error.cc:108
void mkdir(const std::string &path)
create a directory
Definition: mkdir.cc:45
Here is the call graph for this function:
Here is the caller graph for this function: