From 80b4ee65c55c896f12109c338ba9aa386b5719c6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 10 Jul 2015 15:33:45 +0200 Subject: Implement try_mkdir_p() --- butl/filesystem | 6 ++++++ butl/filesystem.cxx | 14 ++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'butl') diff --git a/butl/filesystem b/butl/filesystem index 4d0b7ef..63b19ff 100644 --- a/butl/filesystem +++ b/butl/filesystem @@ -56,6 +56,12 @@ namespace butl mkdir_status try_mkdir (const path&, mode_t = 0777); + // The '-p' version of the above (i.e., it creates the parent + // directories if necessary). + // + mkdir_status + try_mkdir_p (const path&, mode_t = 0777); + // Try to remove the directory returning not_exist if it does not // exist and not_empty if it is not empty. All other errors are // reported by throwing std::system_error. diff --git a/butl/filesystem.cxx b/butl/filesystem.cxx index 4cf60b2..c65d591 100644 --- a/butl/filesystem.cxx +++ b/butl/filesystem.cxx @@ -108,6 +108,20 @@ namespace butl return r; } + mkdir_status + try_mkdir_p (const path& p, mode_t m) + { + if (!p.root ()) + { + path d (p.directory ()); + + if (!dir_exists (d)) + try_mkdir_p (d, m); + } + + return try_mkdir (p, m); + } + rmdir_status try_rmdir (const path& p) { -- cgit v1.1