aboutsummaryrefslogtreecommitdiff
path: root/build2/filesystem.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-04-05 09:41:18 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-04-08 12:51:00 +0200
commit01d848149c22a69a62eada5fedc2406c54d95ba8 (patch)
tree66a3b59619f32f7f7244200f810f4d4cc9115ca5 /build2/filesystem.cxx
parent3392226a2248b5cd93a899afb986917ce9e7ad74 (diff)
Support for --dry-run|-n mode, perform update part
Diffstat (limited to 'build2/filesystem.cxx')
-rw-r--r--build2/filesystem.cxx29
1 files changed, 20 insertions, 9 deletions
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 <build2/filesystem.hxx>
+#include <build2/context.hxx>
#include <build2/diagnostics.hxx>
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;