aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bpkg/auth.cxx4
-rw-r--r--bpkg/bpkg.cxx3
-rw-r--r--bpkg/pkg-unpack.cxx2
-rw-r--r--bpkg/utility.cxx26
-rw-r--r--bpkg/utility.hxx16
5 files changed, 36 insertions, 15 deletions
diff --git a/bpkg/auth.cxx b/bpkg/auth.cxx
index 82e17ec..b60a8ee 100644
--- a/bpkg/auth.cxx
+++ b/bpkg/auth.cxx
@@ -646,10 +646,10 @@ namespace bpkg
try
{
- f = path::temp_path ("bpkg");
+ rm = tmp_file ("cert");
+ f = rm.path;
ofdstream ofs (f);
- rm = auto_rmfile (f);
ofs << *cert_pem;
ofs.close ();
}
diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx
index 4385567..79e3341 100644
--- a/bpkg/bpkg.cxx
+++ b/bpkg/bpkg.cxx
@@ -309,8 +309,7 @@ try
break;
}
- if (!tmp_dir.empty ())
- clean_tmp (true /* ignore_error */);
+ clean_tmp (true /* ignore_error */);
if (r != 0)
return r;
diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx
index 50c5137..c066f6f 100644
--- a/bpkg/pkg-unpack.cxx
+++ b/bpkg/pkg-unpack.cxx
@@ -161,7 +161,7 @@ namespace bpkg
// What should we do if tar or something after it fails? Cleaning
// up the package directory sounds like the right thing to do.
//
- auto_rm_r arm (d);
+ auto_rmdir arm (d);
cstrings args;
diff --git a/bpkg/utility.cxx b/bpkg/utility.cxx
index d87c151..f32daa0 100644
--- a/bpkg/utility.cxx
+++ b/bpkg/utility.cxx
@@ -24,7 +24,21 @@ namespace bpkg
const dir_path bpkg_dir (".bpkg");
const dir_path certs_dir (dir_path (bpkg_dir) /= "certs");
- dir_path tmp_dir;
+ static dir_path tmp_dir_;
+
+ auto_rmfile
+ tmp_file (const string& p)
+ {
+ assert (!tmp_dir_.empty ());
+ return auto_rmfile (tmp_dir_ / path::traits::temp_name (p));
+ }
+
+ auto_rmdir
+ tmp_dir (const string& p)
+ {
+ assert (!tmp_dir_.empty ());
+ return auto_rmdir (tmp_dir_ / dir_path (path::traits::temp_name (p)));
+ }
void
init_tmp (const dir_path& cfg)
@@ -42,15 +56,17 @@ namespace bpkg
mk (d); // We shouldn't need mk_p().
- tmp_dir = move (d);
+ tmp_dir_ = move (d);
}
void
clean_tmp (bool ignore_error)
{
- assert (!tmp_dir.empty ());
- rm_r (tmp_dir, true /* dir_itself */, 3, ignore_error);
- tmp_dir.clear ();
+ if (!tmp_dir_.empty ())
+ {
+ rm_r (tmp_dir_, true /* dir_itself */, 3, ignore_error);
+ tmp_dir_.clear ();
+ }
}
bool
diff --git a/bpkg/utility.hxx b/bpkg/utility.hxx
index e56e093..f4f8690 100644
--- a/bpkg/utility.hxx
+++ b/bpkg/utility.hxx
@@ -39,6 +39,11 @@ namespace bpkg
using butl::exception_guard;
using butl::make_exception_guard;
+ // <libbutl/filesystem.mxx>
+ //
+ using butl::auto_rmfile;
+ using butl::auto_rmdir;
+
// Empty string and path.
//
extern const string empty_string;
@@ -50,7 +55,7 @@ namespace bpkg
extern const dir_path bpkg_dir; // .bpkg/
extern const dir_path certs_dir; // .bpkg/certs/
- // Temporary directory.
+ // Temporary directory facility.
//
// This is normally .bpkg/tmp/ but can also be some system-wide directory
// (e.g., /tmp/bpkg-XXX/) if there is no bpkg configuration. This directory
@@ -58,7 +63,11 @@ namespace bpkg
// you don't need to call init_tmp() explicitly except for certain special
// commands (like cfg-create).
//
- extern dir_path tmp_dir;
+ auto_rmfile
+ tmp_file (const string& prefix);
+
+ auto_rmdir
+ tmp_dir (const string& prefix);
void
init_tmp (const dir_path& cfg);
@@ -100,9 +109,6 @@ namespace bpkg
uint16_t verbosity = 3,
bool ignore_error = false);
- using auto_rm = butl::auto_rmfile;
- using auto_rm_r = butl::auto_rmdir;
-
// Process.
//
// By default the process command line is printed for verbosity >= 2