diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2022-06-03 21:53:48 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2022-06-07 13:49:14 +0300 |
commit | 00cda575c97494d1b6caf2d05ea8a1f8e848cd8a (patch) | |
tree | 19adfe4823b460367b80630c2b43ed553fc391a0 | |
parent | deecf4971fbc90b472135e30387bc76e9788061b (diff) |
Add --keep-temp common option
-rw-r--r-- | bpkg/bpkg.cxx | 17 | ||||
-rw-r--r-- | bpkg/common.cli | 7 | ||||
-rw-r--r-- | bpkg/package-skeleton.cxx | 4 | ||||
-rw-r--r-- | bpkg/pkg-checkout.cxx | 8 | ||||
-rw-r--r-- | bpkg/rep-fetch.cxx | 6 | ||||
-rw-r--r-- | bpkg/rep-remove.cxx | 4 | ||||
-rw-r--r-- | bpkg/utility.cxx | 24 | ||||
-rw-r--r-- | bpkg/utility.hxx | 4 |
8 files changed, 51 insertions, 23 deletions
diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx index e6ca4be..2a9fb6d 100644 --- a/bpkg/bpkg.cxx +++ b/bpkg/bpkg.cxx @@ -531,6 +531,8 @@ init (const common_options& co, if (tmp) init_tmp (dir_path (cfg_dir (&o))); + keep_tmp = o.keep_tmp (); + return o; } @@ -744,7 +746,20 @@ try if (build2_sched.started ()) build2_sched.shutdown (); - clean_tmp (true /* ignore_error */); + if (!keep_tmp) + { + clean_tmp (true /* ignore_error */); + } + else if (verb > 1) + { + for (const auto& d: tmp_dirs) + { + const dir_path& td (d.second); + + if (exists (td)) + info << "keeping temporary directory " << td; + } + } if (r != 0) return r; diff --git a/bpkg/common.cli b/bpkg/common.cli index cccf1d3..d62633a 100644 --- a/bpkg/common.cli +++ b/bpkg/common.cli @@ -416,6 +416,13 @@ namespace bpkg { "Don't load default options files." } + + bool --keep-tmp + { + "Don't remove the \cb{bpkg}'s temporary directory at the end of the + command execution and print its path at the verbosity level 2 or + higher. This option is primarily useful for troubleshooting." + } }; { diff --git a/bpkg/package-skeleton.cxx b/bpkg/package-skeleton.cxx index 972d064..e0d85ed 100644 --- a/bpkg/package-skeleton.cxx +++ b/bpkg/package-skeleton.cxx @@ -655,8 +655,8 @@ namespace bpkg // assert (out_root_.empty ()); - auto i (temp_dir.find (db_->config_orig)); - assert (i != temp_dir.end ()); + auto i (tmp_dirs.find (db_->config_orig)); + assert (i != tmp_dirs.end ()); // Make sure the source and out root directories, if set, are absolute // and normalized. diff --git a/bpkg/pkg-checkout.cxx b/bpkg/pkg-checkout.cxx index f2c373d..d5b4837 100644 --- a/bpkg/pkg-checkout.cxx +++ b/bpkg/pkg-checkout.cxx @@ -197,8 +197,8 @@ namespace bpkg // of it (note that if they appear on different filesystems that won't // be possible). // - auto ti (temp_dir.find (rdb.config_orig)); - assert (ti != temp_dir.end ()); + auto ti (tmp_dirs.find (rdb.config_orig)); + assert (ti != tmp_dirs.end ()); const dir_path& tdir (ti->second); // Try to reuse the cached repository (moved to the temporary directory @@ -224,7 +224,7 @@ namespace bpkg // The repository temporary directory. // - auto_rmdir rmt (tdir / sd); + auto_rmdir rmt (tdir / sd, !keep_tmp); // Move the repository to the temporary directory. // @@ -258,7 +258,7 @@ namespace bpkg // The temporary out of source directory that is required for the dist // meta-operation. // - auto_rmdir rmo (tdir / dir_path (n.string ())); + auto_rmdir rmo (tdir / dir_path (n.string ()), !keep_tmp); const dir_path& od (rmo.path); if (exists (od)) diff --git a/bpkg/rep-fetch.cxx b/bpkg/rep-fetch.cxx index e232d24..e9cacd0 100644 --- a/bpkg/rep-fetch.cxx +++ b/bpkg/rep-fetch.cxx @@ -507,12 +507,12 @@ namespace bpkg bool ev, bool lb) { - auto i (temp_dir.find (conf != nullptr ? *conf : empty_dir_path)); - assert (i != temp_dir.end ()); + auto i (tmp_dirs.find (conf != nullptr ? *conf : empty_dir_path)); + assert (i != tmp_dirs.end ()); dir_path sd (repository_state (rl)); - auto_rmdir rm (i->second / sd); + auto_rmdir rm (i->second / sd, !keep_tmp); const dir_path& td (rm.path); if (exists (td)) diff --git a/bpkg/rep-remove.cxx b/bpkg/rep-remove.cxx index 601d291..26d5725 100644 --- a/bpkg/rep-remove.cxx +++ b/bpkg/rep-remove.cxx @@ -131,8 +131,8 @@ namespace bpkg static void rmdir (const dir_path& cfg, const dir_path& d) { - auto i (temp_dir.find (cfg)); - assert (i != temp_dir.end ()); + auto i (tmp_dirs.find (cfg)); + assert (i != tmp_dirs.end ()); dir_path td (i->second / d.leaf ()); diff --git a/bpkg/utility.cxx b/bpkg/utility.cxx index 625348b..d229205 100644 --- a/bpkg/utility.cxx +++ b/bpkg/utility.cxx @@ -36,22 +36,26 @@ namespace bpkg const dir_path current_dir ("."); - map<dir_path, dir_path> temp_dir; + map<dir_path, dir_path> tmp_dirs; + + bool keep_tmp; auto_rmfile tmp_file (const dir_path& cfg, const string& p) { - auto i (temp_dir.find (cfg)); - assert (i != temp_dir.end ()); - return auto_rmfile (i->second / path::traits_type::temp_name (p)); + auto i (tmp_dirs.find (cfg)); + assert (i != tmp_dirs.end ()); + return auto_rmfile (i->second / path::traits_type::temp_name (p), + !keep_tmp); } auto_rmdir tmp_dir (const dir_path& cfg, const string& p) { - auto i (temp_dir.find (cfg)); - assert (i != temp_dir.end ()); - return auto_rmdir (i->second / dir_path (path::traits_type::temp_name (p))); + auto i (tmp_dirs.find (cfg)); + assert (i != tmp_dirs.end ()); + return auto_rmdir (i->second / dir_path (path::traits_type::temp_name (p)), + !keep_tmp); } void @@ -72,13 +76,13 @@ namespace bpkg mk (d); // We shouldn't need mk_p(). - temp_dir[cfg] = move (d); + tmp_dirs[cfg] = move (d); } void clean_tmp (bool ignore_error) { - for (const auto& d: temp_dir) + for (const auto& d: tmp_dirs) { const dir_path& td (d.second); @@ -91,7 +95,7 @@ namespace bpkg } } - temp_dir.clear (); + tmp_dirs.clear (); } path& diff --git a/bpkg/utility.hxx b/bpkg/utility.hxx index 4cbfc3c..2dcf46d 100644 --- a/bpkg/utility.hxx +++ b/bpkg/utility.hxx @@ -100,7 +100,9 @@ namespace bpkg // commands in main(), so you don't need to call init_tmp() explicitly // except for certain special commands (like cfg-create). // - extern std::map<dir_path, dir_path> temp_dir; + extern std::map<dir_path, dir_path> tmp_dirs; + + extern bool keep_tmp; // --keep-tmp auto_rmfile tmp_file (const dir_path& cfg, const string& prefix); |