TF++, Miscellaneous classes and modules in C++:
mkdirp.cc
Go to the documentation of this file.
1 
34 #define TF_MKDIRP_CC_VERSION \
35  "TF_MKDIRP_CC V1.0 "
36 
37 #include <tfxx/fs.h>
38 #include <errno.h>
39 
40 namespace tfxx {
41 
42  namespace fs {
43 
44  void mkdirp(const std::string& path)
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)
74 
75  } // namespace fs
76 
77 }
78 
79 /* ----- END OF mkdirp.cc ----- */
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
Namespace containing all code of library libtfxx.