diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-05-26 14:55:40 +0300 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-05-27 14:38:01 +0200 |
commit | d6581aa9be74e83cc689bfdaae9aaf2e78287975 (patch) | |
tree | e741d2c6fcdb567d8c7b897d17f3f0ca2358d307 /libbuild2/build/script/runner.cxx | |
parent | e6470e37093084251b7ee60a904a78e54d13e31b (diff) |
Create build script temporary directory on demand
Diffstat (limited to 'libbuild2/build/script/runner.cxx')
-rw-r--r-- | libbuild2/build/script/runner.cxx | 122 |
1 files changed, 40 insertions, 82 deletions
diff --git a/libbuild2/build/script/runner.cxx b/libbuild2/build/script/runner.cxx index 559a6cd..315a248 100644 --- a/libbuild2/build/script/runner.cxx +++ b/libbuild2/build/script/runner.cxx @@ -3,7 +3,7 @@ #include <libbuild2/build/script/runner.hxx> -#include <libbutl/filesystem.mxx> +#include <libbutl/filesystem.mxx> // try_rmdir() #include <libbuild2/target.hxx> #include <libbuild2/script/run.hxx> @@ -17,60 +17,8 @@ namespace build2 namespace script { void default_runner:: - enter (environment& env, const location& ll) + enter (environment&, const location&) { - // Create the temporary directory for this run regardless of the - // dry-run mode, since some commands still can be executed (see run() - // for details). This also a reason for not using the build2 - // filesystem API that considers the dry-run mode. - // - // Note that the directory auto-removal is active. - // - dir_path& td (env.temp_dir.path); - - try - { - td = dir_path::temp_path ("build2-build-script"); - } - catch (const system_error& e) - { - // While there can be no fault of the script being currently - // executed let's add the location anyway to ease the - // troubleshooting. And let's stick to that principle down the road. - // - fail (ll) << "unable to obtain temporary directory for buildscript " - << "execution" << e; - } - - mkdir_status r; - - try - { - r = try_mkdir (td); - } - catch (const system_error& e) - { - fail(ll) << "unable to create temporary directory '" << td << "': " - << e << endf; - } - - // Note that the temporary directory can potentially stay after some - // abnormally terminated script run. Clean it up and reuse if that's - // the case. - // - if (r == mkdir_status::already_exists) - try - { - butl::rmdir_r (td, false /* dir */); - } - catch (const system_error& e) - { - fail (ll) << "unable to cleanup temporary directory '" << td - << "': " << e; - } - - if (verb >= 3) - text << "mkdir " << td; } void default_runner:: @@ -96,43 +44,53 @@ namespace build2 clean (env, ll); - // Note that since the temporary directory may only contain special - // files that are created and registered for cleanup by the script - // running machinery and should all be removed by the above clean() - // function call, its removal failure may not be the script fault but - // potentially a bug or a filesystem problem. Thus, we don't ignore - // the errors and report them. + // Remove the temporary directory, if created. // - env.temp_dir.cancel (); - const dir_path& td (env.temp_dir.path); - try + if (!td.empty ()) { - // Note that the temporary directory must be empty to date. + // Note that since the temporary directory may only contain special + // files that are created and registered for cleanup by the script + // running machinery and should all be removed by the above clean() + // function call, its removal failure may not be the script fault + // but potentially a bug or a filesystem problem. Thus, we don't + // ignore the errors and report them. // - rmdir_status r (try_rmdir (td)); + env.temp_dir.cancel (); - if (r != rmdir_status::success) + try { - diag_record dr (fail (ll)); - dr << "temporary directory '" << td - << (r == rmdir_status::not_exist - ? "' does not exist" - : "' is not empty"); - - if (r == rmdir_status::not_empty) - build2::script::print_dir (dr, td, ll); + // Note that the temporary directory must be empty to date. + // + rmdir_status r (try_rmdir (td)); + + if (r != rmdir_status::success) + { + // While there can be no fault of the script being currently + // executed let's add the location anyway to ease the + // troubleshooting. And let's stick to that principle down the + // road. + // + diag_record dr (fail (ll)); + dr << "temporary directory '" << td + << (r == rmdir_status::not_exist + ? "' does not exist" + : "' is not empty"); + + if (r == rmdir_status::not_empty) + build2::script::print_dir (dr, td, ll); + } + } + catch (const system_error& e) + { + fail (ll) << "unable to remove temporary directory '" << td + << "': " << e; } - } - catch (const system_error& e) - { - fail (ll) << "unable to remove temporary directory '" << td << "': " - << e; - } - if (verb >= 3) - text << "rmdir " << td; + if (verb >= 3) + text << "rmdir " << td; + } } void default_runner:: |