diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-08-03 15:35:22 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-08-03 15:35:22 +0200 |
commit | 936f511c53ec79d507a0993950f913ccf8b5e30d (patch) | |
tree | 17c49c449e723274d84ab25be9259c5b662cb486 | |
parent | 8a9b868f9e588db265ac7aeb30070b2cd0859c35 (diff) |
Only print mkdir if did create directory
-rw-r--r-- | build2/filesystem.txx | 6 | ||||
-rw-r--r-- | build2/rule.cxx | 77 |
2 files changed, 43 insertions, 40 deletions
diff --git a/build2/filesystem.txx b/build2/filesystem.txx index 83e3677..fe56498 100644 --- a/build2/filesystem.txx +++ b/build2/filesystem.txx @@ -37,8 +37,7 @@ namespace build2 catch (const system_error& e) { print (); - error << "unable to remove file " << f << ": " << e; - throw failed (); + fail << "unable to remove file " << f << ": " << e << endf; } if (rs == rmfile_status::success) @@ -78,8 +77,7 @@ namespace build2 catch (const system_error& e) { print (); - error << "unable to remove directory " << d << ": " << e; - throw failed (); + fail << "unable to remove directory " << d << ": " << e << endf; } switch (rs) diff --git a/build2/rule.cxx b/build2/rule.cxx index a48fef2..91a111d 100644 --- a/build2/rule.cxx +++ b/build2/rule.cxx @@ -173,6 +173,41 @@ namespace build2 } } + static bool + fsdir_mkdir (const target& t, const dir_path& d) + { + // Even with the exists() check below this can still be racy so only print + // things if we actually did create it (similar to build2::mkdir()). + // + auto print = [&t, &d] () + { + if (verb >= 2) + text << "mkdir " << d; + else if (verb) + text << "mkdir " << t; + }; + + mkdir_status ms; + + try + { + ms = try_mkdir (d); + } + catch (const system_error& e) + { + print (); + fail << "unable to create directory " << d << ": " << e; + } + + if (ms == mkdir_status::success) + { + print (); + return true; + } + + return false; + } + target_state fsdir_rule:: perform_update (action a, const target& t) { @@ -188,29 +223,13 @@ namespace build2 // const dir_path& d (t.dir); // Everything is in t.dir. - // Generally, it is probably correct to assume that in the majority - // of cases the directory will already exist. If so, then we are - // going to get better performance by first checking if it indeed - // exists. See try_mkdir() for details. + // Generally, it is probably correct to assume that in the majority of + // cases the directory will already exist. If so, then we are going to get + // better performance by first checking if it indeed exists. See + // butl::try_mkdir() for details. // - if (!exists (d)) - { - if (verb >= 2) - text << "mkdir " << d; - else if (verb) - text << "mkdir " << t; - - try - { - try_mkdir (d); - } - catch (const system_error& e) - { - fail << "unable to create directory " << d << ": " << e; - } - + if (!exists (d) && fsdir_mkdir (t, d)) ts |= target_state::changed; - } return ts; } @@ -232,21 +251,7 @@ namespace build2 const dir_path& d (t.dir); if (!exists (d)) - { - if (verb >= 2) - text << "mkdir " << d; - else if (verb) - text << "mkdir " << t; - - try - { - try_mkdir (d); - } - catch (const system_error& e) - { - fail << "unable to create directory " << d << ": " << e; - } - } + fsdir_mkdir (t, d); } target_state fsdir_rule:: |