aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-10 11:21:42 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-10 11:21:42 +0200
commit43c591d58e3a2c77185f2f62348dc3f049764819 (patch)
tree62c27f14b2e9d29895fa496285364557ae17cdf1
parentf3f46a1656207a1c681e7c53cc3bd2c9a28fa887 (diff)
Add support for not removing directory itself in rmdir_r()
-rw-r--r--butl/filesystem5
-rw-r--r--butl/filesystem.cxx13
2 files changed, 11 insertions, 7 deletions
diff --git a/butl/filesystem b/butl/filesystem
index 9168f19..5b1c656 100644
--- a/butl/filesystem
+++ b/butl/filesystem
@@ -71,10 +71,11 @@ namespace butl
try_rmdir_r (const dir_path&);
// As above but throws rather than returns not_exist if the directory
- // does not exist, so check before calling.
+ // does not exist, so check before calling. If the second argument is
+ // false, the the directory itself is not removed.
//
void
- rmdir_r (const dir_path&);
+ rmdir_r (const dir_path&, bool dir = true);
// Try to remove the file (or symlinks) returning not_exist if
// it does not exist. All other errors are reported by throwing
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