From 01d848149c22a69a62eada5fedc2406c54d95ba8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 5 Apr 2019 09:41:18 +0200 Subject: Support for --dry-run|-n mode, perform update part --- build2/filesystem.txx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'build2/filesystem.txx') diff --git a/build2/filesystem.txx b/build2/filesystem.txx index fb224b6..919a26e 100644 --- a/build2/filesystem.txx +++ b/build2/filesystem.txx @@ -4,7 +4,7 @@ #include // is_base_of -#include // work +#include #include namespace build2 @@ -34,7 +34,9 @@ namespace build2 try { - rs = try_rmfile (f); + rs = dry_run + ? file_exists (f) ? rmfile_status::success : rmfile_status::not_exist + : try_rmfile (f); } catch (const system_error& e) { @@ -54,9 +56,6 @@ namespace build2 { using namespace butl; - bool w (work.sub (d)); // Don't try to remove working directory. - rmdir_status rs; - // We don't want to print the command if we couldn't remove the directory // because it does not exist (just like we don't print mkdir if it already // exists) or if it is not empty. This makes the below code a bit ugly. @@ -72,9 +71,13 @@ namespace build2 } }; + bool w (false); // Don't try to remove working directory. + rmdir_status rs; try { - rs = !w ? try_rmdir (d) : rmdir_status::not_empty; + rs = dry_run + ? dir_exists (d) ? rmdir_status::success : rmdir_status::not_exist + : !(w = work.sub (d)) ? try_rmdir (d) : rmdir_status::not_empty; } catch (const system_error& e) { -- cgit v1.1