aboutsummaryrefslogtreecommitdiff
path: root/bpkg/utility.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2021-09-03 18:24:08 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-09-04 12:40:57 +0300
commit7bb44980ced46506c10bad333f526b7bc62ea1db (patch)
tree207a14ee727f7237e8fc2b08e47f4de8a97e0b99 /bpkg/utility.cxx
parentbd02eaa1298271ecf8365aa869e93fdcb04fdeb1 (diff)
Add support for multiple temporary directories
Diffstat (limited to 'bpkg/utility.cxx')
-rw-r--r--bpkg/utility.cxx35
1 files changed, 21 insertions, 14 deletions
diff --git a/bpkg/utility.cxx b/bpkg/utility.cxx
index b179f63..39dea81 100644
--- a/bpkg/utility.cxx
+++ b/bpkg/utility.cxx
@@ -28,20 +28,22 @@ namespace bpkg
const dir_path current_dir (".");
- dir_path temp_dir;
+ map<dir_path, dir_path> temp_dir;
auto_rmfile
- tmp_file (const string& p)
+ tmp_file (const dir_path& cfg, const string& p)
{
- assert (!temp_dir.empty ());
- return auto_rmfile (temp_dir / path::traits_type::temp_name (p));
+ auto i (temp_dir.find (cfg));
+ assert (i != temp_dir.end ());
+ return auto_rmfile (i->second / path::traits_type::temp_name (p));
}
auto_rmdir
- tmp_dir (const string& p)
+ tmp_dir (const dir_path& cfg, const string& p)
{
- assert (!temp_dir.empty ());
- return auto_rmdir (temp_dir / dir_path (path::traits_type::temp_name (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)));
}
void
@@ -62,21 +64,26 @@ namespace bpkg
mk (d); // We shouldn't need mk_p().
- temp_dir = move (d);
+ temp_dir[cfg] = move (d);
}
void
clean_tmp (bool ignore_error)
{
- if (!temp_dir.empty () && exists (temp_dir))
+ for (const auto& d: temp_dir)
{
- rm_r (temp_dir,
- true /* dir_itself */,
- 3,
- ignore_error ? rm_error_mode::ignore : rm_error_mode::fail);
+ const dir_path& td (d.second);
- temp_dir.clear ();
+ if (exists (td))
+ {
+ rm_r (td,
+ true /* dir_itself */,
+ 3,
+ ignore_error ? rm_error_mode::ignore : rm_error_mode::fail);
+ }
}
+
+ temp_dir.clear ();
}
path&