diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2019-02-14 22:38:51 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2019-02-15 13:28:54 +0300 |
commit | 39ce51acd1a187891d9951e8ae5460f9b6f4603c (patch) | |
tree | 174b74371962cf94aba11bd78317073778705644 | |
parent | 3c3b18efe6b9fc6f51d16c9569ca1e150adeaf76 (diff) |
Fix rmdir_r() that may throw system_error regardless of ignore_error flag value
-rw-r--r-- | libbutl/filesystem.cxx | 25 | ||||
-rw-r--r-- | libbutl/filesystem.ixx | 4 |
2 files changed, 21 insertions, 8 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 diff --git a/libbutl/filesystem.ixx b/libbutl/filesystem.ixx index 5ac5d97..c9e3997 100644 --- a/libbutl/filesystem.ixx +++ b/libbutl/filesystem.ixx @@ -29,7 +29,9 @@ namespace butl inline rmdir_status try_rmdir_r (const dir_path& p, bool ignore_error) { - bool e (dir_exists (p)); //@@ What if it exists but is not a directory? + //@@ What if it exists but is not a directory? + // + bool e (dir_exists (p, ignore_error)); if (e) rmdir_r (p, true, ignore_error); |