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.cxx | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'build2/filesystem.cxx') diff --git a/build2/filesystem.cxx b/build2/filesystem.cxx index 5e6df5f..7242347 100644 --- a/build2/filesystem.cxx +++ b/build2/filesystem.cxx @@ -4,6 +4,7 @@ #include +#include #include using namespace std; @@ -11,15 +12,18 @@ using namespace butl; namespace build2 { - bool + void touch (const path& p, bool create, uint16_t v) { if (verb >= v) text << "touch " << p; + if (dry_run) + return; + try { - return touch_file (p, create); + touch_file (p, create); } catch (const system_error& e) { @@ -112,7 +116,11 @@ namespace build2 try { - rs = try_rmsymlink (p, d); + rs = dry_run + ? (butl::entry_exists (p) + ? rmfile_status::success + : rmfile_status::not_exist) + : try_rmsymlink (p, d); } catch (const system_error& e) { @@ -140,13 +148,16 @@ namespace build2 if (verb >= v) text << "rmdir -r " << d; - try - { - butl::rmdir_r (d, dir); - } - catch (const system_error& e) + if (!dry_run) { - fail << "unable to remove directory " << d << ": " << e; + try + { + butl::rmdir_r (d, dir); + } + catch (const system_error& e) + { + fail << "unable to remove directory " << d << ": " << e; + } } return rmdir_status::success; -- cgit v1.1