From 00a601a9268d7c85be2147a2b7af9f855ea7d957 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 14 May 2018 13:06:20 +0200 Subject: Fix nested transaction issue in sync --- bdep/sync.cxx | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bdep/sync.cxx b/bdep/sync.cxx index 19afdce..651f6ad 100644 --- a/bdep/sync.cxx +++ b/bdep/sync.cxx @@ -123,11 +123,27 @@ namespace bdep { using query = bdep::query; - database db (open (d, trace)); + // Save and restore the current transaction, if any. + // + transaction* ct (nullptr); + if (transaction::has_current ()) + { + ct = &transaction::current (); + transaction::reset_current (); + } - transaction t (db.begin ()); - c = db.query_one (query::path == cfg.string ()); - t.commit (); + auto tg (make_guard ([ct] () + { + if (ct != nullptr) + transaction::current (*ct); + })); + + { + database db (open (d, trace)); + transaction t (db.begin ()); + c = db.query_one (query::path == cfg.string ()); + t.commit (); + } } // If the project is a repository of this configuration but the bdep -- cgit v1.1