diff options
-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:: |