From 43c591d58e3a2c77185f2f62348dc3f049764819 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 Sep 2015 11:21:42 +0200 Subject: Add support for not removing directory itself in rmdir_r() --- butl/filesystem.cxx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'butl/filesystem.cxx') diff --git a/butl/filesystem.cxx b/butl/filesystem.cxx index 90e8e81..f1341ee 100644 --- a/butl/filesystem.cxx +++ b/butl/filesystem.cxx @@ -99,7 +99,7 @@ namespace butl } void - rmdir_r (const dir_path& p) + rmdir_r (const dir_path& p, bool dir) { // An nftw()-based implementation (for platforms that support it) // might be a faster way. @@ -114,11 +114,14 @@ namespace butl try_rmfile (ep); } - rmdir_status r (try_rmdir (p)); + if (dir) + { + rmdir_status r (try_rmdir (p)); - if (r != rmdir_status::success) - throw system_error (r == rmdir_status::not_empty ? ENOTEMPTY : ENOENT, - system_category ()); + if (r != rmdir_status::success) + throw system_error (r == rmdir_status::not_empty ? ENOTEMPTY : ENOENT, + system_category ()); + } } rmfile_status -- cgit v1.1