aboutsummaryrefslogtreecommitdiff
path: root/libbutl/filesystem.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-02-14 22:38:51 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-02-15 13:28:54 +0300
commit39ce51acd1a187891d9951e8ae5460f9b6f4603c (patch)
tree174b74371962cf94aba11bd78317073778705644 /libbutl/filesystem.cxx
parent3c3b18efe6b9fc6f51d16c9569ca1e150adeaf76 (diff)
Fix rmdir_r() that may throw system_error regardless of ignore_error flag value
Diffstat (limited to 'libbutl/filesystem.cxx')
-rw-r--r--libbutl/filesystem.cxx25
1 files changed, 18 insertions, 7 deletions
diff --git a/libbutl/filesystem.cxx b/libbutl/filesystem.cxx
index dcdc96f..1ebe379 100644
--- a/libbutl/filesystem.cxx
+++ b/libbutl/filesystem.cxx
@@ -308,19 +308,30 @@ namespace butl
// An nftw()-based implementation (for platforms that support it)
// might be a faster way.
//
- for (const dir_entry& de: dir_iterator (p, false /* ignore_dangling */))
+ // @@ Get rid of these try/catch clauses when ignore_error flag is
+ // implemented for dir_iterator() constructor.
+ //
+ try
{
- path ep (p / de.path ()); //@@ Would be good to reuse the buffer.
+ for (const dir_entry& de: dir_iterator (p, false /* ignore_dangling */))
+ {
+ path ep (p / de.path ()); //@@ Would be good to reuse the buffer.
- if (de.ltype () == entry_type::directory)
- rmdir_r (path_cast<dir_path> (move (ep)), true, ignore_error);
- else
- try_rmfile (ep, ignore_error);
+ if (de.ltype () == entry_type::directory)
+ rmdir_r (path_cast<dir_path> (move (ep)), true, ignore_error);
+ else
+ try_rmfile (ep, ignore_error);
+ }
+ }
+ catch (const system_error&)
+ {
+ if (!ignore_error)
+ throw;
}
if (dir)
{
- rmdir_status r (try_rmdir (p));
+ rmdir_status r (try_rmdir (p, ignore_error));
if (r != rmdir_status::success && !ignore_error)
throw_generic_error (r == rmdir_status::not_empty