aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-06-22 23:18:56 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-06-23 15:13:12 +0300
commit748eab79085d7c8a3b3da90316a90a892db884ae (patch)
tree8bb0b2c1e7fba762530bd0e23320cc5a667ca249
parentdbd6d3ea474a8fbc6b2a8cbfeec34dbbc58f0553 (diff)
Add ignore_error parameter to rmdir_r(), fix try_rmdir_r()
-rw-r--r--butl/filesystem6
-rw-r--r--butl/filesystem.cxx8
-rw-r--r--butl/filesystem.ixx2
3 files changed, 8 insertions, 8 deletions
diff --git a/butl/filesystem b/butl/filesystem
index 943a346..ab39f36 100644
--- a/butl/filesystem
+++ b/butl/filesystem
@@ -73,11 +73,11 @@ namespace butl
try_rmdir_r (const dir_path&, bool ignore_error = false);
// As above but throws rather than returns not_exist if the directory
- // does not exist, so check before calling. If the second argument is
- // false, the the directory itself is not removed.
+ // does not exist (unless ignore_error is true), so check before calling.
+ // If the second argument is false, then the directory itself is not removed.
//
void
- rmdir_r (const dir_path&, bool dir = true);
+ rmdir_r (const dir_path&, bool dir = true, bool ignore_error = false);
// Try to remove the file (or symlinks) returning not_exist if
// it does not exist. Unless ignore_error is true, all other
diff --git a/butl/filesystem.cxx b/butl/filesystem.cxx
index 72e1812..a2d6434 100644
--- a/butl/filesystem.cxx
+++ b/butl/filesystem.cxx
@@ -111,7 +111,7 @@ namespace butl
}
void
- rmdir_r (const dir_path& p, bool dir)
+ rmdir_r (const dir_path& p, bool dir, bool ignore_error)
{
// An nftw()-based implementation (for platforms that support it)
// might be a faster way.
@@ -121,16 +121,16 @@ namespace butl
path ep (p / de.path ()); //@@ Would be good to reuse the buffer.
if (de.ltype () == entry_type::directory)
- rmdir_r (path_cast<dir_path> (ep));
+ rmdir_r (path_cast<dir_path> (ep), true, ignore_error);
else
- try_rmfile (ep);
+ try_rmfile (ep, ignore_error);
}
if (dir)
{
rmdir_status r (try_rmdir (p));
- if (r != rmdir_status::success)
+ if (r != rmdir_status::success && !ignore_error)
throw system_error (r == rmdir_status::not_empty ? ENOTEMPTY : ENOENT,
system_category ());
}
diff --git a/butl/filesystem.ixx b/butl/filesystem.ixx
index 86f654c..c2bfa49 100644
--- a/butl/filesystem.ixx
+++ b/butl/filesystem.ixx
@@ -10,7 +10,7 @@ namespace butl
bool e (dir_exists (p)); //@@ What if it exists but is not a directory?
if (e)
- rmdir_r (p, ignore_error);
+ rmdir_r (p, true, ignore_error);
return e ? rmdir_status::success : rmdir_status::not_exist;
}