aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-21 18:07:02 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-21 18:07:02 +0200
commit9792fc9d137b4dd702360ac0242f9a7a26e675c2 (patch)
tree8ea454a973e3ef03ffb82dd9dd41acd06b989694
parent542bb3eb22eefd6ed4161a5e02c828ac5c26f08b (diff)
Add tracer_guard to restore database tracer
-rw-r--r--bpkg/database11
-rw-r--r--bpkg/pkg-unpack.cxx4
2 files changed, 13 insertions, 2 deletions
diff --git a/bpkg/database b/bpkg/database
index c4ace56..05ffb04 100644
--- a/bpkg/database
+++ b/bpkg/database
@@ -17,6 +17,17 @@ namespace bpkg
database
open (const dir_path& configuration, tracer&, bool create = false);
+
+ struct tracer_guard
+ {
+ tracer_guard (database& db, tracer& t)
+ : db_ (db), t_ (db.tracer ()) {db.tracer (t);}
+ ~tracer_guard () {db_.tracer (*t_);}
+
+ private:
+ database& db_;
+ odb::tracer* t_;
+ };
}
#endif // BPKG_DATABASE
diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx
index 6979842..463531f 100644
--- a/bpkg/pkg-unpack.cxx
+++ b/bpkg/pkg-unpack.cxx
@@ -28,7 +28,7 @@ namespace bpkg
pkg_unpack (database& db, const dir_path& c, const dir_path& d, bool purge)
{
tracer trace ("pkg_unpack(dir)");
- db.tracer (trace); // "Tail" call, never restored.
+ tracer_guard tg (db, trace);
if (!exists (d))
fail << "package directory " << d << " does not exist";
@@ -82,7 +82,7 @@ namespace bpkg
pkg_unpack (database& db, const dir_path& c, const string& name)
{
tracer trace ("pkg_unpack(pkg)");
- db.tracer (trace); // "Tail" call, never restored.
+ tracer_guard tg (db, trace);
transaction t (db.begin ());
shared_ptr<package> p (db.find<package> (name));