From 39ce51acd1a187891d9951e8ae5460f9b6f4603c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 14 Feb 2019 22:38:51 +0300 Subject: Fix rmdir_r() that may throw system_error regardless of ignore_error flag value --- libbutl/filesystem.cxx | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'libbutl/filesystem.cxx') 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 (move (ep)), true, ignore_error); - else - try_rmfile (ep, ignore_error); + if (de.ltype () == entry_type::directory) + rmdir_r (path_cast (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 -- cgit v1.1